Struct ring_compat::signature::ecdsa::Signature
source · pub struct Signature<C>where
C: PrimeCurve,{ /* private fields */ }
signature
only.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>::Output: ArrayLength<u8>,
impl<C> Signature<C>where C: PrimeCurve, <<C as Curve>::FieldBytesSize as Add>::Output: ArrayLength<u8>,
sourcepub fn from_bytes(
bytes: &GenericArray<u8, <<C as Curve>::FieldBytesSize as Add>::Output>
) -> Result<Signature<C>, Error>
pub fn from_bytes( bytes: &GenericArray<u8, <<C as Curve>::FieldBytesSize as Add>::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>::Output as Add<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B1>>>::Output: ArrayLength<u8>,
<<C as Curve>::FieldBytesSize as Add>::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>::Output as Add<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B1>>>::Output: ArrayLength<u8>, <<C as Curve>::FieldBytesSize as Add>::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>::Output>
pub fn to_bytes( &self ) -> GenericArray<u8, <<C as Curve>::FieldBytesSize as Add>::Output>
Serialize this signature as bytes.
sourcepub fn to_der(&self) -> Signature<C>where
<<<C as Curve>::FieldBytesSize as Add>::Output as Add<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B1>>>::Output: ArrayLength<u8>,
<<C as Curve>::FieldBytesSize as Add>::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>::Output as Add<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B1>>>::Output: ArrayLength<u8>, <<C as Curve>::FieldBytesSize as Add>::Output: Add<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B1>> + ArrayLength<u8>,
der
only.Serialize this signature as ASN.1 DER.
Trait Implementations§
source§impl<C> Debug for Signature<C>where
C: PrimeCurve,
<<C as Curve>::FieldBytesSize as Add>::Output: ArrayLength<u8>,
impl<C> Debug for Signature<C>where C: PrimeCurve, <<C as Curve>::FieldBytesSize as Add>::Output: ArrayLength<u8>,
source§impl<C> Display for Signature<C>where
C: PrimeCurve,
<<C as Curve>::FieldBytesSize as Add>::Output: ArrayLength<u8>,
impl<C> Display for Signature<C>where C: PrimeCurve, <<C as Curve>::FieldBytesSize as Add>::Output: ArrayLength<u8>,
source§impl<C> From<Signature<C>> for GenericArray<u8, <<C as Curve>::FieldBytesSize as Add>::Output>where
C: PrimeCurve,
<<C as Curve>::FieldBytesSize as Add>::Output: ArrayLength<u8>,
impl<C> From<Signature<C>> for GenericArray<u8, <<C as Curve>::FieldBytesSize as Add>::Output>where C: PrimeCurve, <<C as Curve>::FieldBytesSize as Add>::Output: ArrayLength<u8>,
source§impl<C> From<Signature<C>> for Signature<C>where
C: PrimeCurve,
<<<C as Curve>::FieldBytesSize as Add>::Output as Add<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B1>>>::Output: ArrayLength<u8>,
<<C as Curve>::FieldBytesSize as Add>::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>::Output as Add<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B1>>>::Output: ArrayLength<u8>, <<C as Curve>::FieldBytesSize as Add>::Output: Add<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B1>> + ArrayLength<u8>,
source§impl<C> LowerHex for Signature<C>where
C: PrimeCurve,
<<C as Curve>::FieldBytesSize as Add>::Output: ArrayLength<u8>,
impl<C> LowerHex for Signature<C>where C: PrimeCurve, <<C as Curve>::FieldBytesSize as Add>::Output: ArrayLength<u8>,
source§impl<C> PartialEq for Signature<C>where
C: PartialEq + PrimeCurve,
impl<C> PartialEq for Signature<C>where C: PartialEq + PrimeCurve,
source§impl<C> SignatureEncoding for Signature<C>where
C: PrimeCurve,
<<C as Curve>::FieldBytesSize as Add>::Output: ArrayLength<u8>,
impl<C> SignatureEncoding for Signature<C>where C: PrimeCurve, <<C as Curve>::FieldBytesSize as Add>::Output: ArrayLength<u8>,
§type Repr = GenericArray<u8, <<C as Curve>::FieldBytesSize as Add>::Output>
type Repr = GenericArray<u8, <<C as Curve>::FieldBytesSize as Add>::Output>
source§fn to_vec(&self) -> Vec<u8>
fn to_vec(&self) -> Vec<u8>
alloc
only.