-
Notifications
You must be signed in to change notification settings - Fork 238
add adapters for digest trait #678
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
base: master
Are you sure you want to change the base?
Conversation
@@ -13,11 +13,13 @@ categories = [ | |||
] | |||
|
|||
[features] | |||
default = ["digest"] |
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.
should be fine to enable by default since digest is also no_std
without the default features
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'd prefer to make it optional to not bloat up people's dependency trees and also because the 0.10 vs 0.11 thing
fn update(&mut self, data: &[u8]) { | ||
match self.inner.write_all(data) { | ||
Ok(()) => {} | ||
Err(_) => unreachable!(), |
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.
it's better to do Err(e) => match e{}
so the compiler checks for you that it's actually unreachable.
Interesting timing, we were discussing it yesterday in Matrix https://matrix.to/#/!BHcierreUuwCMxVqOf:matrix.org/$e8f4Ojv7DjdxQcGhRarquhTGY88GPgchLVjG93ZPjxE?via=matrix.org&via=catircservices.org&via=mozilla.org IMO it's a bit niche. For example, the Also the rust-crypto ecosystem isn't known for its stability. Latest |
thanks for taking a look. i find these traits far superior to those in long story short, i am currently working on a JSON Web Token library, which often needs to write data after encoding it & authenticating it. it ends up being intuitive to chain APIs that implement e.g. writing HS256 signed data encoded as base64url becomes incredibly simple (can be done directly to a TCP stream)
output:
as for the digest crate not providing an adapter, i think there are 2 reasons:
|
there is an existing trait digest::Update used in very popular crates like sha2
this trait is essentially equivalent to
ErrorType<Error=Infallible> + Write
this PR adds new adapters between the two traits with an optional dependency on digest
example usage: