@@ -16,12 +16,10 @@ export class TOTPService implements ITOTPService {
1616 return false ;
1717 }
1818
19- // Check for leading/trailing spaces in original input
2019 if ( secret . trim ( ) !== secret ) {
2120 return false ;
2221 }
2322
24- // Base32 validation (A-Z, 2-7)
2523 const base32Regex = / ^ [ A - Z 2 - 7 ] + = * $ / ;
2624 const normalizedSecret = secret . trim ( ) . toUpperCase ( ) ;
2725
@@ -30,7 +28,6 @@ export class TOTPService implements ITOTPService {
3028 return false ;
3129 }
3230
33- // Check for invalid padding
3431 const paddingRegex = / = + $ / ;
3532 const paddingMatch = paddingRegex . exec ( normalizedSecret ) ;
3633 if ( paddingMatch ) {
@@ -40,7 +37,6 @@ export class TOTPService implements ITOTPService {
4037 return false ;
4138 }
4239 } else if ( normalizedSecret . length % 8 !== 0 ) {
43- // If no padding, length must be a multiple of 8
4440 return false ;
4541 }
4642
@@ -58,7 +54,7 @@ export class TOTPService implements ITOTPService {
5854 return this . encrypter . encrypt ( secret . trim ( ) . toUpperCase ( ) ) ;
5955 } catch ( error ) {
6056 this . logger . error ( 'Secret encryption failed' , { error } ) ;
61- throw new TOTPError ( 'Failed to encrypt TOTP secret' ) ;
57+ throw new TOTPError ( 'Failed to encrypt secret' ) ;
6258 }
6359 }
6460
@@ -67,7 +63,7 @@ export class TOTPService implements ITOTPService {
6763 return this . encrypter . decrypt ( encryptedSecret ) ;
6864 } catch ( error ) {
6965 this . logger . error ( 'Secret decryption failed' , { error } ) ;
70- throw new TOTPError ( 'Failed to decrypt TOTP secret' ) ;
66+ throw new TOTPError ( 'Failed to decrypt secret' ) ;
7167 }
7268 }
7369
@@ -76,8 +72,8 @@ export class TOTPService implements ITOTPService {
7672 const config = configHandler . get ( 'totp' ) ;
7773 return config ?. secret ? config as TOTPConfig : null ;
7874 } catch ( error ) {
79- this . logger . error ( 'Failed to read TOTP config' , { error } ) ;
80- throw new TOTPError ( 'Failed to read TOTP configuration' ) ;
75+ this . logger . error ( 'Failed to read config' , { error } ) ;
76+ throw new TOTPError ( 'Failed to read configuration' ) ;
8177 }
8278 }
8379
@@ -90,34 +86,34 @@ export class TOTPService implements ITOTPService {
9086 } ;
9187 configHandler . set ( 'totp' , updatedConfig ) ;
9288 } catch ( error ) {
93- this . logger . error ( 'Failed to store TOTP config' , { error } ) ;
94- throw new TOTPError ( 'Failed to store TOTP configuration' ) ;
89+ this . logger . error ( 'Failed to store config' , { error } ) ;
90+ throw new TOTPError ( 'Failed to store configuration' ) ;
9591 }
9692 }
9793
9894 removeConfig ( ) : void {
9995 try {
10096 configHandler . delete ( 'totp' ) ;
10197 } catch ( error ) {
102- this . logger . error ( 'Failed to remove TOTP config' , { error } ) ;
103- throw new TOTPError ( 'Failed to remove TOTP configuration' ) ;
98+ this . logger . error ( 'Failed to remove config' , { error } ) ;
99+ throw new TOTPError ( 'Failed to remove configuration' ) ;
104100 }
105101 }
106102
107103 generateTOTP ( secret : string ) : string {
108104 try {
109105 return authenticator . generate ( secret . trim ( ) . toUpperCase ( ) ) ;
110106 } catch ( error ) {
111- this . logger . error ( 'Failed to generate TOTP code' , { error } ) ;
112- throw new TOTPError ( 'Failed to generate TOTP code' ) ;
107+ this . logger . error ( 'Failed to generate code' , { error } ) ;
108+ throw new TOTPError ( 'Failed to generate code' ) ;
113109 }
114110 }
115111
116112 verifyTOTP ( secret : string , token : string ) : boolean {
117113 try {
118114 return authenticator . check ( token , secret . trim ( ) . toUpperCase ( ) ) ;
119115 } catch ( error ) {
120- this . logger . debug ( 'TOTP verification failed' , { error } ) ;
116+ this . logger . debug ( 'Secret verification failed' , { error } ) ;
121117 return false ;
122118 }
123119 }
0 commit comments