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>
impl<C> Signature<C>
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>
Available on crate feature der
only.
pub fn from_der(bytes: &[u8]) -> Result<Signature<C>, Error>
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.
Trait Implementations§
Source§impl<C> From<Signature<C>> for GenericArray<u8, <<C as Curve>::FieldBytesSize as Add>::Output>
impl<C> From<Signature<C>> for GenericArray<u8, <<C as Curve>::FieldBytesSize as Add>::Output>
Source§fn from(
signature: Signature<C>,
) -> GenericArray<u8, <<C as Curve>::FieldBytesSize as Add>::Output>
fn from( signature: Signature<C>, ) -> GenericArray<u8, <<C as Curve>::FieldBytesSize as Add>::Output>
Source§impl<C> SignatureEncoding for Signature<C>
impl<C> SignatureEncoding for Signature<C>
Source§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.