pub struct Signature(/* private fields */);
Expand description
An ECDSA signature
Implementations§
Source§impl Signature
impl Signature
Sourcepub fn from_der(secp: &Secp256k1, data: &[u8]) -> Result<Signature, Error>
pub fn from_der(secp: &Secp256k1, data: &[u8]) -> Result<Signature, Error>
Converts a DER-encoded byte slice to a signature
Sourcepub fn from_compact(secp: &Secp256k1, data: &[u8]) -> Result<Signature, Error>
pub fn from_compact(secp: &Secp256k1, data: &[u8]) -> Result<Signature, Error>
Converts a 64-byte compact-encoded byte slice to a signature
Sourcepub fn from_der_lax(secp: &Secp256k1, data: &[u8]) -> Result<Signature, Error>
pub fn from_der_lax(secp: &Secp256k1, data: &[u8]) -> Result<Signature, Error>
Converts a “lax DER”-encoded byte slice to a signature. This is basically only useful for validating signatures in the Bitcoin blockchain from before 2016. It should never be used in new applications. This library does not support serializing to this “format”
Sourcepub fn normalize_s(&mut self, secp: &Secp256k1)
pub fn normalize_s(&mut self, secp: &Secp256k1)
Normalizes a signature to a “low S” form. In ECDSA, signatures are of the form (r, s) where r and s are numbers lying in some finite field. The verification equation will pass for (r, s) iff it passes for (r, -s), so it is possible to ``modify’’ signatures in transit by flipping the sign of s. This does not constitute a forgery since the signed message still cannot be changed, but for some applications, changing even the signature itself can be a problem. Such applications require a “strong signature”. It is believed that ECDSA is a strong signature except for this ambiguity in the sign of s, so to accomodate these applications libsecp256k1 will only accept signatures for which s is in the lower half of the field range. This eliminates the ambiguity.
However, for some systems, signatures with high s-values are considered valid. (For example, parsing the historic Bitcoin blockchain requires this.) For these applications we provide this normalization function, which ensures that the s value lies in the lower half of its range.
Sourcepub fn as_ptr(&self) -> *const Signature
pub fn as_ptr(&self) -> *const Signature
Obtains a raw pointer suitable for use with FFI functions
Sourcepub fn as_mut_ptr(&mut self) -> *mut Signature
pub fn as_mut_ptr(&mut self) -> *mut Signature
Obtains a raw mutable pointer suitable for use with FFI functions
Sourcepub fn serialize_der(&self, secp: &Secp256k1) -> Vec<u8>
pub fn serialize_der(&self, secp: &Secp256k1) -> Vec<u8>
Serializes the signature in DER format
Sourcepub fn serialize_compact(&self, secp: &Secp256k1) -> [u8; 64]
pub fn serialize_compact(&self, secp: &Secp256k1) -> [u8; 64]
Serializes the signature in compact format
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Signature
impl<'de> Deserialize<'de> for Signature
Source§fn deserialize<D>(d: D) -> Result<Signature, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(d: D) -> Result<Signature, D::Error>where
D: Deserializer<'de>,
impl Copy for Signature
impl Eq for Signature
impl StructuralPartialEq for Signature
Auto Trait Implementations§
impl Freeze for Signature
impl RefUnwindSafe for Signature
impl Send for Signature
impl Sync for Signature
impl Unpin for Signature
impl UnwindSafe for Signature
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)