File tree 1 file changed +18
-2
lines changed
1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -142,7 +142,7 @@ pub struct OTPElement {
142
142
#[ builder( default = "6" ) ]
143
143
pub digits : u64 ,
144
144
#[ serde( rename = "type" ) ]
145
- #[ builder( default ) ]
145
+ #[ builder( setter ( custom ) , default ) ]
146
146
pub type_ : OTPType ,
147
147
#[ builder( default ) ]
148
148
pub algorithm : OTPAlgorithm ,
@@ -235,6 +235,22 @@ impl OTPElementBuilder {
235
235
self
236
236
}
237
237
238
+ /// Makes the secret insertion case insensitive
239
+ pub fn type_ < VALUE : Into < OTPType > > ( & mut self , value : VALUE ) -> & mut Self {
240
+ let otp_type: OTPType = value. into ( ) ;
241
+
242
+ if otp_type == OTPType :: Motp {
243
+ // Motp codes must be lowercase
244
+ self . secret = self . secret . as_ref ( ) . map ( |s| s. to_lowercase ( ) )
245
+ } else {
246
+ // Base32 codes must be uppercase
247
+ self . secret = self . secret . as_ref ( ) . map ( |s| s. to_uppercase ( ) )
248
+ }
249
+
250
+ self . type_ = Some ( otp_type) ;
251
+ self
252
+ }
253
+
238
254
/// Check if the OTPElement is valid
239
255
fn validate ( & self ) -> Result < ( ) , ErrReport > {
240
256
if self . secret . is_none ( ) {
@@ -384,7 +400,7 @@ mod test {
384
400
#[ test]
385
401
fn valid_hex_secret ( ) {
386
402
let result = OTPElementBuilder :: default ( )
387
- . secret ( "aaaf " )
403
+ . secret ( "aAAf " )
388
404
. label ( "label" )
389
405
. issuer ( "" )
390
406
. type_ ( OTPType :: Motp )
You can’t perform that action at this time.
0 commit comments