-
Notifications
You must be signed in to change notification settings - Fork 183
Digestable signatures #12
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0ed928c
Digestable signatures: signature::digest::Signature
tarcieri 5082a51
Rename digest::Signature to 'Digestable'
tarcieri a1b59a1
Move blanket impls into 'digestable' module
tarcieri 564a42c
Have digest Signer/Verifier take digest output as an argument
tarcieri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| use crate::{ | ||
| digest::{self, Digest}, | ||
| error::Error, | ||
| signature::Signature, | ||
| signer::Signer, | ||
| verifier::Verifier, | ||
| }; | ||
|
|
||
| /// Marker trait for `Signature` types computable as `S(H(m))` where: | ||
| /// | ||
| /// - `S`: signature algorithm | ||
| /// - `H`: hash (a.k.a. digest) function | ||
| /// - `m`: message | ||
| /// | ||
| /// For signature types that implement this trait, a blanket impl of | ||
| /// `Signer` will be provided for all types that `impl digest::Signer`. | ||
| pub trait Digestable: Signature { | ||
| /// Preferred `Digest` algorithm to use when computing this signature type. | ||
| type Digest: Digest; | ||
| } | ||
|
|
||
| impl<S, T> Signer<S> for T | ||
| where | ||
| S: Digestable + Signature, | ||
| T: digest::Signer<S::Digest, S>, | ||
| { | ||
| fn sign(&self, msg: &[u8]) -> Result<S, Error> { | ||
| self.sign_digest(S::Digest::digest(msg)) | ||
| } | ||
| } | ||
|
|
||
| impl<S, T> Verifier<S> for T | ||
| where | ||
| S: Digestable + Signature, | ||
| T: digest::Verifier<S::Digest, S>, | ||
| { | ||
| fn verify(&self, msg: &[u8], signature: &S) -> Result<(), Error> { | ||
| self.verify_digest(S::Digest::digest(msg), signature) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,12 @@ | ||
| //! Support for using hash functions that impl the `Digest` trait in order | ||
| //! to hash the input message in order to compute a signature. | ||
|
|
||
| mod digestable; | ||
| mod signer; | ||
| mod verifier; | ||
|
|
||
| /// Re-export the `Digest` trait from the `digest` crate, as it's the main | ||
| /// trait this module depends on. | ||
| pub use ::digest::Digest; | ||
|
|
||
| pub use self::{signer::Signer, verifier::Verifier}; | ||
| pub use self::{digestable::Digestable, signer::Signer, verifier::Verifier}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Random thought: this pattern seems generally useful... perhaps it belongs in the
digestcrate?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.
Hm, maybe, but I think we first should see one-two similar use-cases first, before including it into
digest.BTW is it me or
Digestablefeels reverse in a sense? It's like "we can digest this signature", while it should be "this signature is calculated from message digest". How aboutDigestSignature? It still feels a bit off, but I don't have better ideas right now.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.
See 0ed928c which used
signature::digest::Signature😉