Skip to content

Commit b27c878

Browse files
committed
Handle short secret error for Yandex code
1 parent 721df64 commit b27c878

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/otp/algorithms/yandex_otp_maker.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ where
7070
Err(e) => return Err(OtpError::SecretEncoding(e.kind, e.position)),
7171
};
7272

73+
if decoded_secret.len() < SECRET_LENGHT {
74+
return Err(OtpError::ShortSecret);
75+
}
76+
7377
let parsed_secret = &decoded_secret.as_slice()[0..SECRET_LENGHT];
7478

7579
let mut pin_with_secret: Vec<u8> = Vec::with_capacity(pin.as_bytes().len() + SECRET_LENGHT);

src/otp/otp_error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::fmt::{Display, Formatter};
55
pub enum OtpError {
66
SecretEncoding(DecodeKind, usize), // Secret encoding error, of given kind at give position
77
MissingPin, // Missing Pin for Yandex / MOTP Codes
8+
ShortSecret, // Short secret for Yandex codes
89
MissingCounter, // Missing counter for HOTP codes
910
InvalidOffset, // Invalid offset
1011
InvalidDigest, // Invalid digest
@@ -20,6 +21,7 @@ impl Display for OtpError {
2021
OtpError::MissingCounter => f.write_str("Missing counter value"),
2122
OtpError::InvalidDigest => f.write_str("Invalid digest"),
2223
OtpError::InvalidOffset => f.write_str("Invalid offset"),
24+
OtpError::ShortSecret => f.write_str("Secret length less than 16 bytes"),
2325
}
2426
}
2527
}

0 commit comments

Comments
 (0)