-
Notifications
You must be signed in to change notification settings - Fork 5
Update RustCrypto crates #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,8 +37,13 @@ | |
|
||
#![doc(html_root_url = "https://docs.rs/totp-lite/1.0.3")] | ||
|
||
use digest::{BlockInput, FixedOutputDirty, Reset, Update}; | ||
use hmac::{Hmac, Mac, NewMac}; | ||
use digest::{ | ||
block_buffer::Eager, | ||
core_api::{BlockSizeUser, BufferKindUser, CoreProxy, FixedOutputCore, UpdateCore}, | ||
generic_array::typenum::{IsLess, Le, NonZero, U256}, | ||
FixedOutput, HashMarker, Update, | ||
}; | ||
use hmac::{Hmac, Mac}; | ||
pub use sha1::Sha1; | ||
pub use sha2::{Sha256, Sha512}; | ||
|
||
|
@@ -68,7 +73,15 @@ pub const DEFAULT_DIGITS: u32 = 8; | |
/// ``` | ||
pub fn totp<H>(secret: &[u8], time: u64) -> String | ||
where | ||
H: Update + BlockInput + Reset + FixedOutputDirty + Clone + Default, | ||
H: Update + FixedOutput + CoreProxy, | ||
H::Core: HashMarker | ||
+ UpdateCore | ||
+ FixedOutputCore | ||
+ BufferKindUser<BufferKind = Eager> | ||
+ Default | ||
+ Clone, | ||
<H::Core as BlockSizeUser>::BlockSize: IsLess<U256>, | ||
Le<<H::Core as BlockSizeUser>::BlockSize, U256>: NonZero, | ||
{ | ||
totp_custom::<H>(DEFAULT_STEP, DEFAULT_DIGITS, secret, time) | ||
} | ||
|
@@ -91,11 +104,19 @@ where | |
/// ``` | ||
pub fn totp_custom<H>(step: u64, digits: u32, secret: &[u8], time: u64) -> String | ||
where | ||
H: Update + BlockInput + Reset + FixedOutputDirty + Clone + Default, | ||
H: Update + FixedOutput + CoreProxy, | ||
H::Core: HashMarker | ||
+ UpdateCore | ||
+ FixedOutputCore | ||
+ BufferKindUser<BufferKind = Eager> | ||
+ Default | ||
+ Clone, | ||
<H::Core as BlockSizeUser>::BlockSize: IsLess<U256>, | ||
Le<<H::Core as BlockSizeUser>::BlockSize, U256>: NonZero, | ||
{ | ||
// Hash the secret and the time together. | ||
let mut mac: Hmac<H> = Hmac::new_from_slice(secret).unwrap(); | ||
mac.update(&to_bytes(time / step)); | ||
let mut mac = <Hmac<H> as Mac>::new_from_slice(secret).unwrap(); | ||
<Hmac<H> as Update>::update(&mut mac, &to_bytes(time / step)); | ||
Comment on lines
+118
to
+119
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is still a method, but both the |
||
let hash: &[u8] = &mac.finalize().into_bytes(); | ||
|
||
// Magic from the RFC. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain these new constraints?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mainly copy-pasted them from
Hmac
https://docs.rs/hmac/latest/src/hmac/optim.rs.html#20-36There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks I'll review these.