pub struct Signature<C>where
C: PrimeCurve,{ /* private fields */ }
Expand description
ECDSA signature (fixed-size). Generic over elliptic curve types.
Serialized as fixed-sized big endian scalar values with no added framing:
r
: field element size for the given curve, big-endians
: field element size for the given curve, big-endian
Both r
and s
MUST be non-zero.
For example, in a curve with a 256-bit modulus like NIST P-256 or
secp256k1, r
and s
will both be 32-bytes and serialized as big endian,
resulting in a signature with a total of 64-bytes.
ASN.1 DER-encoded signatures also supported via the
Signature::from_der
and Signature::to_der
methods.
serde
support
When the serde
feature of this crate is enabled, it provides support for
serializing and deserializing ECDSA signatures using the Serialize
and
Deserialize
traits.
The serialization uses a hexadecimal encoding when used with “human readable” text formats, and a binary encoding otherwise.
Implementations§
source§impl<C> Signature<C>where
C: PrimeCurve,
<<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output: ArrayLength<u8>,
impl<C> Signature<C>where C: PrimeCurve, <<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output: ArrayLength<u8>,
sourcepub fn from_bytes(
bytes: &GenericArray<u8, <<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output>
) -> Result<Signature<C>, Error>
pub fn from_bytes( bytes: &GenericArray<u8, <<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output> ) -> Result<Signature<C>, Error>
Parse a signature from fixed-width bytes, i.e. 2 * the size of
[FieldBytes
] for a particular curve.
Returns
Ok(signature)
if ther
ands
components are both in the valid range1..n
when serialized as concatenated big endian integers.Err(err)
if ther
and/ors
component of the signature is out-of-range when interpreted as a big endian integer.
sourcepub fn from_slice(slice: &[u8]) -> Result<Signature<C>, Error>
pub fn from_slice(slice: &[u8]) -> Result<Signature<C>, Error>
Parse a signature from a byte slice.
sourcepub fn from_der(bytes: &[u8]) -> Result<Signature<C>, Error>where
<<<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output as Add<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B1>>>::Output: ArrayLength<u8>,
<<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output: Add<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B1>> + ArrayLength<u8>,
Available on crate feature der
only.
pub fn from_der(bytes: &[u8]) -> Result<Signature<C>, Error>where <<<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output as Add<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B1>>>::Output: ArrayLength<u8>, <<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output: Add<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B1>> + ArrayLength<u8>,
der
only.Parse a signature from ASN.1 DER.
sourcepub fn from_scalars(
r: impl Into<GenericArray<u8, <C as Curve>::FieldBytesSize>>,
s: impl Into<GenericArray<u8, <C as Curve>::FieldBytesSize>>
) -> Result<Signature<C>, Error>
pub fn from_scalars( r: impl Into<GenericArray<u8, <C as Curve>::FieldBytesSize>>, s: impl Into<GenericArray<u8, <C as Curve>::FieldBytesSize>> ) -> Result<Signature<C>, Error>
Create a Signature
from the serialized r
and s
scalar values
which comprise the signature.
Returns
Ok(signature)
if ther
ands
components are both in the valid range1..n
when serialized as concatenated big endian integers.Err(err)
if ther
and/ors
component of the signature is out-of-range when interpreted as a big endian integer.
sourcepub fn split_bytes(
&self
) -> (GenericArray<u8, <C as Curve>::FieldBytesSize>, GenericArray<u8, <C as Curve>::FieldBytesSize>)
pub fn split_bytes( &self ) -> (GenericArray<u8, <C as Curve>::FieldBytesSize>, GenericArray<u8, <C as Curve>::FieldBytesSize>)
Split the signature into its r
and s
components, represented as bytes.
sourcepub fn to_bytes(
&self
) -> GenericArray<u8, <<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output>
pub fn to_bytes( &self ) -> GenericArray<u8, <<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output>
Serialize this signature as bytes.
sourcepub fn to_der(&self) -> Signature<C>where
<<<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output as Add<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B1>>>::Output: ArrayLength<u8>,
<<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output: Add<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B1>> + ArrayLength<u8>,
Available on crate feature der
only.
pub fn to_der(&self) -> Signature<C>where <<<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output as Add<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B1>>>::Output: ArrayLength<u8>, <<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output: Add<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B1>> + ArrayLength<u8>,
der
only.Serialize this signature as ASN.1 DER.
source§impl<C> Signature<C>where
C: PrimeCurve + CurveArithmetic,
<<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output: ArrayLength<u8>,
impl<C> Signature<C>where C: PrimeCurve + CurveArithmetic, <<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output: ArrayLength<u8>,
sourcepub fn r(&self) -> NonZeroScalar<C>
Available on crate feature arithmetic
only.
pub fn r(&self) -> NonZeroScalar<C>
arithmetic
only.Get the r
component of this signature
sourcepub fn s(&self) -> NonZeroScalar<C>
Available on crate feature arithmetic
only.
pub fn s(&self) -> NonZeroScalar<C>
arithmetic
only.Get the s
component of this signature
sourcepub fn split_scalars(&self) -> (NonZeroScalar<C>, NonZeroScalar<C>)
Available on crate feature arithmetic
only.
pub fn split_scalars(&self) -> (NonZeroScalar<C>, NonZeroScalar<C>)
arithmetic
only.Split the signature into its r
and s
scalars.
sourcepub fn normalize_s(&self) -> Option<Signature<C>>
Available on crate feature arithmetic
only.
pub fn normalize_s(&self) -> Option<Signature<C>>
arithmetic
only.Normalize signature into “low S” form as described in BIP 0062: Dealing with Malleability.
Trait Implementations§
source§impl<C> AssociatedAlgorithmIdentifier for Signature<C>where
C: PrimeCurve,
Signature<C>: AssociatedOid,
Available on crate feature pkcs8
only.
impl<C> AssociatedAlgorithmIdentifier for Signature<C>where C: PrimeCurve, Signature<C>: AssociatedOid,
pkcs8
only.ECDSA AlgorithmIdentifier
which identifies the digest used by default
with the Signer
and Verifier
traits.
source§const ALGORITHM_IDENTIFIER: AlgorithmIdentifier<AnyRef<'static>> = AlgorithmIdentifierRef{ oid: Self::OID, parameters: None,}
const ALGORITHM_IDENTIFIER: AlgorithmIdentifier<AnyRef<'static>> = AlgorithmIdentifierRef{ oid: Self::OID, parameters: None,}
AlgorithmIdentifier
for this structure.source§impl<C> AssociatedOid for Signature<C>where
C: DigestPrimitive,
<C as DigestPrimitive>::Digest: AssociatedOid,
Available on crate features digest
and hazmat
only.
impl<C> AssociatedOid for Signature<C>where C: DigestPrimitive, <C as DigestPrimitive>::Digest: AssociatedOid,
digest
and hazmat
only.ECDSA [ObjectIdentifier
] which identifies the digest used by default
with the Signer
and Verifier
traits.
To support non-default digest algorithms, use the SignatureWithOid
type instead.
source§impl<C> Debug for Signature<C>where
C: PrimeCurve,
<<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output: ArrayLength<u8>,
impl<C> Debug for Signature<C>where C: PrimeCurve, <<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output: ArrayLength<u8>,
source§impl<D> DigestSigner<D, Signature<NistP256>> for Signer<NistP256>where
D: Digest<OutputSize = U32> + Default,
impl<D> DigestSigner<D, Signature<NistP256>> for Signer<NistP256>where D: Digest<OutputSize = U32> + Default,
source§impl<D> DigestSigner<D, Signature<NistP384>> for Signer<NistP384>where
D: Digest<OutputSize = U32> + Default,
impl<D> DigestSigner<D, Signature<NistP384>> for Signer<NistP384>where D: Digest<OutputSize = U32> + Default,
source§impl<D> DigestSigner<D, Signature<Secp256k1>> for Signer<Secp256k1>where
D: Digest<OutputSize = U32> + Default,
Available on crate feature secp256k1
only.
impl<D> DigestSigner<D, Signature<Secp256k1>> for Signer<Secp256k1>where D: Digest<OutputSize = U32> + Default,
secp256k1
only.source§impl<C> Display for Signature<C>where
C: PrimeCurve,
<<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output: ArrayLength<u8>,
impl<C> Display for Signature<C>where C: PrimeCurve, <<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output: ArrayLength<u8>,
source§impl<C> From<Signature<C>> for Signature<C>where
C: PrimeCurve,
<<<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output as Add<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B1>>>::Output: ArrayLength<u8>,
<<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output: Add<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B1>> + ArrayLength<u8>,
impl<C> From<Signature<C>> for Signature<C>where C: PrimeCurve, <<<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output as Add<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B1>>>::Output: ArrayLength<u8>, <<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output: Add<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B1>> + ArrayLength<u8>,
source§impl<C> From<SignatureWithOid<C>> for Signature<C>where
C: PrimeCurve,
Available on crate feature digest
only.
impl<C> From<SignatureWithOid<C>> for Signature<C>where C: PrimeCurve,
digest
only.source§fn from(sig: SignatureWithOid<C>) -> Signature<C>
fn from(sig: SignatureWithOid<C>) -> Signature<C>
source§impl<C> FromStr for Signature<C>where
C: PrimeCurve + CurveArithmetic,
<<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output: ArrayLength<u8>,
Available on crate feature arithmetic
only.
impl<C> FromStr for Signature<C>where C: PrimeCurve + CurveArithmetic, <<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output: ArrayLength<u8>,
arithmetic
only.source§impl<C> LowerHex for Signature<C>where
C: PrimeCurve,
<<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output: ArrayLength<u8>,
impl<C> LowerHex for Signature<C>where C: PrimeCurve, <<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output: ArrayLength<u8>,
source§impl<C> PartialEq<Signature<C>> for Signature<C>where
C: PartialEq<C> + PrimeCurve,
impl<C> PartialEq<Signature<C>> for Signature<C>where C: PartialEq<C> + PrimeCurve,
source§impl<C> PrehashSignature for Signature<C>where
C: DigestPrimitive,
<<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output: ArrayLength<u8>,
Available on crate feature digest
only.
impl<C> PrehashSignature for Signature<C>where C: DigestPrimitive, <<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output: ArrayLength<u8>,
digest
only.§type Digest = <C as DigestPrimitive>::Digest
type Digest = <C as DigestPrimitive>::Digest
Digest
algorithm to use when computing this signature type.source§impl PrehashSigner<Signature<Secp256k1>> for Signer<Secp256k1>
Available on crate feature secp256k1
only.
impl PrehashSigner<Signature<Secp256k1>> for Signer<Secp256k1>
secp256k1
only.source§impl<C> SignatureEncoding for Signature<C>where
C: PrimeCurve,
<<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output: ArrayLength<u8>,
impl<C> SignatureEncoding for Signature<C>where C: PrimeCurve, <<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output: ArrayLength<u8>,
§type Repr = GenericArray<u8, <<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output>
type Repr = GenericArray<u8, <<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output>
source§fn to_vec(&self) -> Vec<u8, Global>
fn to_vec(&self) -> Vec<u8, Global>
alloc
only.source§fn encoded_len(&self) -> usize
fn encoded_len(&self) -> usize
source§impl<C> TryFrom<&[u8]> for Signature<C>where
C: PrimeCurve,
<<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output: ArrayLength<u8>,
impl<C> TryFrom<&[u8]> for Signature<C>where C: PrimeCurve, <<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output: ArrayLength<u8>,
source§impl<C> TryFrom<Signature<C>> for Signature<C>where
C: PrimeCurve,
<<<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output as Add<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B1>>>::Output: ArrayLength<u8>,
<<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output: Add<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B1>> + ArrayLength<u8>,
impl<C> TryFrom<Signature<C>> for Signature<C>where C: PrimeCurve, <<<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output as Add<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B1>>>::Output: ArrayLength<u8>, <<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output: Add<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B1>> + ArrayLength<u8>,
source§impl<C> UpperHex for Signature<C>where
C: PrimeCurve,
<<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output: ArrayLength<u8>,
impl<C> UpperHex for Signature<C>where C: PrimeCurve, <<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output: ArrayLength<u8>,
impl<C> Copy for Signature<C>where C: PrimeCurve, <<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output: ArrayLength<u8>, <<<C as Curve>::FieldBytesSize as Add<<C as Curve>::FieldBytesSize>>::Output as ArrayLength<u8>>::ArrayType: Copy,
impl<C> Eq for Signature<C>where C: Eq + PrimeCurve,
impl<C> StructuralEq for Signature<C>where C: PrimeCurve,
impl<C> StructuralPartialEq for Signature<C>where C: PrimeCurve,
Auto Trait Implementations§
impl<C> RefUnwindSafe for Signature<C>where <C as Curve>::Uint: RefUnwindSafe,
impl<C> Send for Signature<C>
impl<C> Sync for Signature<C>
impl<C> Unpin for Signature<C>where <C as Curve>::Uint: Unpin,
impl<C> UnwindSafe for Signature<C>where <C as Curve>::Uint: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> DynAssociatedAlgorithmIdentifier for Twhere
T: AssociatedAlgorithmIdentifier,
impl<T> DynAssociatedAlgorithmIdentifier for Twhere T: AssociatedAlgorithmIdentifier,
§fn algorithm_identifier(&self) -> Result<AlgorithmIdentifier<Any>, Error>
fn algorithm_identifier(&self) -> Result<AlgorithmIdentifier<Any>, Error>
AlgorithmIdentifier
for this structure.