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
impl RingSigner
Sourcepub fn from_pkcs8(pkcs8_bytes: &[u8]) -> Result<Self>
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.
Sourcepub fn generate() -> Result<(Self, Vec<u8>)>
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
impl CaseSigner for RingSigner
Source§fn sign_p256_sha256(&self, message: &[u8]) -> Result<[u8; 64], SignerError>
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).