add `ThirtyTwoByteHash` hash trait which can be implemented for easier conversion of things to `Message`s
This commit is contained in:
parent
1f4a4c11a3
commit
e5a02bd9a0
15
src/lib.rs
15
src/lib.rs
|
@ -205,6 +205,14 @@ fn from_str(s: &str) -> Result<Signature, Error> {
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
||||||
pub struct RecoverableSignature(ffi::RecoverableSignature);
|
pub struct RecoverableSignature(ffi::RecoverableSignature);
|
||||||
|
|
||||||
|
/// Trait describing something that promises to be a 32-byte random number; in particular,
|
||||||
|
/// it has negligible probability of being zero or overflowing the group order. Such objects
|
||||||
|
/// may be converted to `Message`s without any error paths.
|
||||||
|
pub trait ThirtyTwoByteHash {
|
||||||
|
/// Converts the object into a 32-byte array
|
||||||
|
fn into_32(self) -> [u8; 32];
|
||||||
|
}
|
||||||
|
|
||||||
impl RecoveryId {
|
impl RecoveryId {
|
||||||
#[inline]
|
#[inline]
|
||||||
/// Allows library users to create valid recovery IDs from i32.
|
/// Allows library users to create valid recovery IDs from i32.
|
||||||
|
@ -519,6 +527,13 @@ impl Message {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T: ThirtyTwoByteHash> From<T> for Message {
|
||||||
|
/// Converts a 32-byte hash directly to a message without error paths
|
||||||
|
fn from(t: T) -> Message {
|
||||||
|
Message(t.into_32())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// An ECDSA error
|
/// An ECDSA error
|
||||||
#[derive(Copy, PartialEq, Eq, Clone, Debug)]
|
#[derive(Copy, PartialEq, Eq, Clone, Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
|
|
Loading…
Reference in New Issue