Skip to content

Commit 71d3933

Browse files
committed
fix: handle integer underflow on code format
1 parent b167d02 commit 71d3933

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/otp/otp_element.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,11 @@ impl OTPElement {
226226
.checked_pow(self.digits as u32)
227227
.ok_or(OtpError::InvalidDigits)?;
228228
let s = (value as u64 % exponential).to_string();
229-
Ok("0".repeat(self.digits as usize - s.chars().count()) + s.as_str())
229+
Ok("0".repeat(
230+
(self.digits as usize)
231+
.checked_sub(s.chars().count())
232+
.unwrap_or(0),
233+
) + s.as_str())
230234
}
231235
}
232236

0 commit comments

Comments
 (0)