Skip to content

Commit ef759fe

Browse files
committed
add in a base OTPResult class with initializers and as_string/as_u32 methods
1 parent 1eec5c1 commit ef759fe

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,4 @@
8080
pub mod hotp;
8181
pub mod totp;
8282
pub mod util;
83+
pub mod otp_result;

src/otp_result.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use std::time::{SystemTime, UNIX_EPOCH};
2+
3+
struct OTPResult {
4+
digits: u32,
5+
code: u32,
6+
}
7+
8+
impl OTPResult {
9+
pub fn new(digits: u32, code: u32 ) -> Self {
10+
OTPResult { digits, code }
11+
}
12+
}
13+
14+
impl OTPResult {
15+
pub fn get_digits(&self) -> u32 { self.digits }
16+
}
17+
18+
impl OTPResult {
19+
pub fn as_string(&self) -> String {
20+
format!("{:01$}", self.code as usize, self.digits as usize)
21+
}
22+
23+
pub fn as_u32(&self) -> u32 {
24+
self.code
25+
}
26+
}

0 commit comments

Comments
 (0)