-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit contains the first breaking changes to the `signature` crate made since its initial 1.0 stabilization. Planning for these changes occurred in #237. The following changes have been made: - The `Signature` trait has been renamed to `SignatureEncoding`. The `Signature` bound on `*Signer` and `*Verifier` traits has been removed, meaning there are no longer any mandatory trait bounds on the signature parameters at all. - The `AsRef<[u8]>` bound formerly found on the `Signature` crate has been replaced with an associated `Repr` type, inspired by the `group::GroupEncoding` trait. This means signature types no longer need to retain a serialized form, and can parse the bag-of-bytes representation to something more convenient, which is useful for e.g. batch verification. - The `std` feature is no longer enabled by default, which matches the other RustCrypto/traits crates. - The `derive-preview` and `hazmat-preview` features have been stabilized. - The former `Keypair` trait has been renamed to `KeypairRef`, and the signature generic parameter removed. A new `Keypair` trait has been added which returns an owned instance of the associated `VerifyingKey`, and a blanket impl of `Keypair` for `KeypairRef` has been added. This addresses the issues described in #1124.
- Loading branch information
Showing
18 changed files
with
195 additions
and
240 deletions.
There are no files selected for viewing
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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 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 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 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,38 @@ | ||
//! Encoding support. | ||
use crate::{Error, Result}; | ||
|
||
#[cfg(feature = "alloc")] | ||
use alloc::{boxed::Box, vec::Vec}; | ||
|
||
/// Support for decoding/encoding signatures as bytes. | ||
pub trait SignatureEncoding: | ||
Clone + Sized + for<'a> TryFrom<&'a [u8], Error = Error> + Into<Self::Repr> | ||
{ | ||
/// Byte representation of a signature. | ||
type Repr: 'static + AsRef<[u8]> + AsMut<[u8]> + Clone + Default + Send + Sync; | ||
|
||
/// Decode signature from its byte representation. | ||
fn from_bytes(bytes: &Self::Repr) -> Result<Self> { | ||
Self::try_from(bytes.as_ref()) | ||
} | ||
|
||
/// Encode signature as its byte representation. | ||
fn to_bytes(&self) -> Self::Repr { | ||
self.clone().into() | ||
} | ||
|
||
/// Encode signature as a byte vector. | ||
#[cfg(feature = "alloc")] | ||
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] | ||
fn to_vec(&self) -> Vec<u8> { | ||
self.to_bytes().as_ref().to_vec() | ||
} | ||
|
||
/// Encode the signature as a boxed byte slice. | ||
#[cfg(feature = "alloc")] | ||
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] | ||
fn to_boxed_slice(&self) -> Box<[u8]> { | ||
self.to_vec().into_boxed_slice() | ||
} | ||
} |
This file contains 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 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
Oops, something went wrong.