@@ -9,6 +9,7 @@ use ratatui::{
99 text:: Text ,
1010 widgets:: { Block , Borders , Clear } ,
1111} ;
12+ use tui_input:: Input ;
1213
1314use crate :: event:: Event ;
1415
@@ -30,6 +31,22 @@ fn pad_string(input: &str, length: usize) -> String {
3031 }
3132}
3233
34+ #[ derive( Debug , Clone , Default ) ]
35+ struct UserInputField {
36+ field : Input ,
37+ error : Option < String > ,
38+ }
39+
40+ impl UserInputField {
41+ fn is_empty ( & self ) -> bool {
42+ self . field . value ( ) . is_empty ( )
43+ }
44+
45+ fn value ( & self ) -> & str {
46+ self . field . value ( )
47+ }
48+ }
49+
3350#[ derive( Debug , PartialEq ) ]
3451enum FocusedSection {
3552 EapChoice ,
@@ -87,11 +104,11 @@ impl WPAEntreprise {
87104 v. next ( ) ;
88105 }
89106 Eap :: TTLS ( v) => {
90- v. focused_input = ttls:: FocusedInput :: CaCert ;
107+ v. focused_input = ttls:: FocusedInput :: Identity ;
91108 v. next ( ) ;
92109 }
93110 Eap :: PEAP ( v) => {
94- v. focused_input = peap:: FocusedInput :: CaCert ;
111+ v. focused_input = peap:: FocusedInput :: Identity ;
95112 v. next ( ) ;
96113 }
97114 Eap :: PWD ( v) => {
@@ -128,15 +145,31 @@ impl WPAEntreprise {
128145 }
129146 } ,
130147 Eap :: TTLS ( v) => match v. focused_input {
131- ttls:: FocusedInput :: CaCert => {
148+ ttls:: FocusedInput :: Identity => {
132149 v. focused_input = ttls:: FocusedInput :: ServerDomainMask ;
133150 v. next ( ) ;
134151 }
135152 ttls:: FocusedInput :: ServerDomainMask => {
136- v. focused_input = ttls:: FocusedInput :: Identity ;
153+ v. focused_input = ttls:: FocusedInput :: CaCert ;
137154 v. next ( ) ;
138155 }
139- ttls:: FocusedInput :: Identity => {
156+ ttls:: FocusedInput :: CaCert => {
157+ v. focused_input = ttls:: FocusedInput :: ClientCert ;
158+ v. next ( ) ;
159+ }
160+ ttls:: FocusedInput :: ClientCert => {
161+ v. focused_input = ttls:: FocusedInput :: ClientKey ;
162+ v. next ( ) ;
163+ }
164+ ttls:: FocusedInput :: ClientKey => {
165+ v. focused_input = ttls:: FocusedInput :: KeyPassphrase ;
166+ v. next ( ) ;
167+ }
168+ ttls:: FocusedInput :: KeyPassphrase => {
169+ v. focused_input = ttls:: FocusedInput :: Phase2Method ;
170+ v. next ( ) ;
171+ }
172+ ttls:: FocusedInput :: Phase2Method => {
140173 v. focused_input = ttls:: FocusedInput :: Phase2Identity ;
141174 v. next ( ) ;
142175 }
@@ -151,15 +184,31 @@ impl WPAEntreprise {
151184 }
152185 } ,
153186 Eap :: PEAP ( v) => match v. focused_input {
154- peap:: FocusedInput :: CaCert => {
187+ peap:: FocusedInput :: Identity => {
155188 v. focused_input = peap:: FocusedInput :: ServerDomainMask ;
156189 v. next ( ) ;
157190 }
158191 peap:: FocusedInput :: ServerDomainMask => {
159- v. focused_input = peap:: FocusedInput :: Identity ;
192+ v. focused_input = peap:: FocusedInput :: CaCert ;
160193 v. next ( ) ;
161194 }
162- peap:: FocusedInput :: Identity => {
195+ peap:: FocusedInput :: CaCert => {
196+ v. focused_input = peap:: FocusedInput :: ClientCert ;
197+ v. next ( ) ;
198+ }
199+ peap:: FocusedInput :: ClientCert => {
200+ v. focused_input = peap:: FocusedInput :: ClientKey ;
201+ v. next ( ) ;
202+ }
203+ peap:: FocusedInput :: ClientKey => {
204+ v. focused_input = peap:: FocusedInput :: KeyPassphrase ;
205+ v. next ( ) ;
206+ }
207+ peap:: FocusedInput :: KeyPassphrase => {
208+ v. focused_input = peap:: FocusedInput :: Phase2Method ;
209+ v. next ( ) ;
210+ }
211+ peap:: FocusedInput :: Phase2Method => {
163212 v. focused_input = peap:: FocusedInput :: Phase2Identity ;
164213 v. next ( ) ;
165214 }
@@ -228,20 +277,36 @@ impl WPAEntreprise {
228277 }
229278 } ,
230279 Eap :: TTLS ( v) => match v. focused_input {
231- ttls:: FocusedInput :: CaCert => {
280+ ttls:: FocusedInput :: Identity => {
232281 self . focused_section = FocusedSection :: EapChoice ;
233282 v. previous ( ) ;
234283 }
235284 ttls:: FocusedInput :: ServerDomainMask => {
236- v. focused_input = ttls:: FocusedInput :: CaCert ;
285+ v. focused_input = ttls:: FocusedInput :: Identity ;
237286 v. previous ( ) ;
238287 }
239- ttls:: FocusedInput :: Identity => {
288+ ttls:: FocusedInput :: CaCert => {
240289 v. focused_input = ttls:: FocusedInput :: ServerDomainMask ;
241290 v. previous ( ) ;
242291 }
292+ ttls:: FocusedInput :: ClientCert => {
293+ v. focused_input = ttls:: FocusedInput :: CaCert ;
294+ v. previous ( ) ;
295+ }
296+ ttls:: FocusedInput :: ClientKey => {
297+ v. focused_input = ttls:: FocusedInput :: ClientCert ;
298+ v. previous ( ) ;
299+ }
300+ ttls:: FocusedInput :: KeyPassphrase => {
301+ v. focused_input = ttls:: FocusedInput :: ClientKey ;
302+ v. previous ( ) ;
303+ }
304+ ttls:: FocusedInput :: Phase2Method => {
305+ v. focused_input = ttls:: FocusedInput :: KeyPassphrase ;
306+ v. previous ( ) ;
307+ }
243308 ttls:: FocusedInput :: Phase2Identity => {
244- v. focused_input = ttls:: FocusedInput :: Identity ;
309+ v. focused_input = ttls:: FocusedInput :: Phase2Method ;
245310 v. previous ( ) ;
246311 }
247312 ttls:: FocusedInput :: Phase2Password => {
@@ -250,20 +315,36 @@ impl WPAEntreprise {
250315 }
251316 } ,
252317 Eap :: PEAP ( v) => match v. focused_input {
253- peap:: FocusedInput :: CaCert => {
318+ peap:: FocusedInput :: Identity => {
254319 self . focused_section = FocusedSection :: EapChoice ;
255320 v. previous ( ) ;
256321 }
257322 peap:: FocusedInput :: ServerDomainMask => {
258- v. focused_input = peap:: FocusedInput :: CaCert ;
323+ v. focused_input = peap:: FocusedInput :: Identity ;
259324 v. previous ( ) ;
260325 }
261- peap:: FocusedInput :: Identity => {
326+ peap:: FocusedInput :: CaCert => {
262327 v. focused_input = peap:: FocusedInput :: ServerDomainMask ;
263328 v. previous ( ) ;
264329 }
330+ peap:: FocusedInput :: ClientCert => {
331+ v. focused_input = peap:: FocusedInput :: CaCert ;
332+ v. previous ( ) ;
333+ }
334+ peap:: FocusedInput :: ClientKey => {
335+ v. focused_input = peap:: FocusedInput :: ClientCert ;
336+ v. previous ( ) ;
337+ }
338+ peap:: FocusedInput :: KeyPassphrase => {
339+ v. focused_input = peap:: FocusedInput :: ClientKey ;
340+ v. previous ( ) ;
341+ }
342+ peap:: FocusedInput :: Phase2Method => {
343+ v. focused_input = peap:: FocusedInput :: KeyPassphrase ;
344+ v. previous ( ) ;
345+ }
265346 peap:: FocusedInput :: Phase2Identity => {
266- v. focused_input = peap:: FocusedInput :: Identity ;
347+ v. focused_input = peap:: FocusedInput :: Phase2Method ;
267348 v. previous ( ) ;
268349 }
269350 peap:: FocusedInput :: Phase2Password => {
@@ -376,7 +457,7 @@ impl WPAEntreprise {
376457 . direction ( Direction :: Vertical )
377458 . constraints ( [
378459 Constraint :: Fill ( 1 ) ,
379- Constraint :: Length ( 21 ) ,
460+ Constraint :: Length ( 30 ) ,
380461 Constraint :: Fill ( 1 ) ,
381462 ] )
382463 . flex ( ratatui:: layout:: Flex :: SpaceBetween )
@@ -402,8 +483,8 @@ impl WPAEntreprise {
402483 Constraint :: Length ( 1 ) , // Title
403484 Constraint :: Length ( 2 ) ,
404485 Constraint :: Length ( 1 ) , // Eap choice
405- Constraint :: Length ( 1 ) ,
406- Constraint :: Length ( 10 ) , // Form
486+ Constraint :: Length ( 2 ) ,
487+ Constraint :: Length ( 30 ) , // Form
407488 Constraint :: Length ( 2 ) ,
408489 Constraint :: Length ( 1 ) , // Submit
409490 Constraint :: Length ( 2 ) ,
0 commit comments