Skip to main content

RingSigner

Struct RingSigner 

Source
pub struct RingSigner { /* private fields */ }
Expand description

CaseSigner backed by the p256 crate’s RFC 6979 deterministic ECDSA.

The name RingSigner is kept for API stability (this type was introduced in M4.1). Key generation still uses ring ([Self::generate]), but signing uses p256::ecdsa::SigningKey (RFC 6979 deterministic) and the public key is derived from the same p256 signing key. This enables byte-for-byte test-vector parity with @noble/curves (JavaScript) as captured by cargo xtask capture-case.

Use Self::from_pkcs8 to load existing keys (e.g., from a fabric store), or Self::generate in tests to mint a fresh keypair.

Implementations§

Source§

impl RingSigner

Source

pub fn from_pkcs8(pkcs8_bytes: &[u8]) -> Result<Self>

Construct from PKCS#8 v1 encoded private key bytes.

Parses the PKCS#8 DER bytes using p256::ecdsa::SigningKey, which also derives the matching public key. The 65-byte SEC1-uncompressed public key is extracted from the p256 verifying key.

§Errors

Returns Error::SigningFailed with SignerError::Internal if the bytes are not a valid PKCS#8-encoded P-256 key.

Source

pub fn generate() -> Result<(Self, Vec<u8>)>

Generate a fresh ECDSA-P256 keypair. Returns the signer plus the PKCS#8 bytes so the caller can persist them.

Key generation uses ring’s EcdsaKeyPair::generate_pkcs8 for its well-audited RNG plumbing. The resulting PKCS#8 is then loaded via from_pkcs8 so that signing uses the deterministic p256 path.

§Errors

Returns Error::SigningFailed with SignerError::Internal if the OS RNG or key-generation step fails (extremely unlikely in practice).

Trait Implementations§

Source§

impl CaseSigner for RingSigner

Source§

fn sign_p256_sha256(&self, message: &[u8]) -> Result<[u8; 64], SignerError>

Sign message using RFC 6979 deterministic ECDSA-P256-SHA256.

Uses p256::ecdsa::SigningKey::sign which follows RFC 6979 for nonce generation (same algorithm as @noble/curves in JavaScript), enabling byte-for-byte reproducible test vectors captured by cargo xtask capture-case.

The signature is low-s normalized (s ≤ n/2), matching @noble/curves behavior. Both s and n - s are valid ECDSA signatures; this ensures the Rust output is byte-identical with matter.js.

The returned signature is in IEEE P1363 compact format (raw r||s, 64 bytes), which is the Matter wire format for ECDSA signatures.

§Errors

Returns SignerError::Internal on signing failure (not expected for valid keys and any message length).

Source§

fn public_key(&self) -> &PublicKey

The 65-byte SEC1-uncompressed P-256 public key matching the NOC.
Source§

impl Debug for RingSigner

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.