From 648f14ede2e1b90c0a67d30b2553d853719d9851 Mon Sep 17 00:00:00 2001 From: Arthur Gautier Date: Thu, 4 May 2023 10:36:32 -0700 Subject: [PATCH] ecdsa: Adds support for the `SignatureBitStringEncoding` trait --- Cargo.lock | 5 +++-- ecdsa/Cargo.toml | 3 ++- ecdsa/src/der.rs | 13 +++++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 447325da..04d5eaf1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -177,6 +177,7 @@ dependencies = [ "serdect", "sha2", "signature", + "spki", ] [[package]] @@ -650,9 +651,9 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" [[package]] name = "spki" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37a5be806ab6f127c3da44b7378837ebf01dadca8510a0e572460216b228bd0e" +checksum = "9d1e996ef02c474957d681f1b05213dfb0abab947b446a62d37770b23500184a" dependencies = [ "base64ct", "der", diff --git a/ecdsa/Cargo.toml b/ecdsa/Cargo.toml index bc4316a9..f70ac3f0 100644 --- a/ecdsa/Cargo.toml +++ b/ecdsa/Cargo.toml @@ -25,6 +25,7 @@ digest = { version = "0.10.6", optional = true, default-features = false, featur rfc6979 = { version = "0.4", optional = true, path = "../rfc6979" } serdect = { version = "0.2", optional = true, default-features = false, features = ["alloc"] } sha2 = { version = "0.10", optional = true, default-features = false, features = ["oid"] } +spki = { version = "0.7.2", optional = true, default-features = false } [dev-dependencies] elliptic-curve = { version = "0.13", default-features = false, features = ["dev"] } @@ -33,7 +34,7 @@ sha2 = { version = "0.10", default-features = false } [features] default = ["digest"] -alloc = ["elliptic-curve/alloc", "signature/alloc"] +alloc = ["elliptic-curve/alloc", "signature/alloc", "spki/alloc"] std = ["alloc", "elliptic-curve/std", "signature/std"] arithmetic = ["elliptic-curve/arithmetic"] diff --git a/ecdsa/src/der.rs b/ecdsa/src/der.rs index 5395dff6..b4b03c17 100644 --- a/ecdsa/src/der.rs +++ b/ecdsa/src/der.rs @@ -19,6 +19,7 @@ use elliptic_curve::{ use { alloc::{boxed::Box, vec::Vec}, signature::SignatureEncoding, + spki::{der::asn1::BitString, SignatureBitStringEncoding}, }; #[cfg(feature = "serde")] @@ -309,6 +310,18 @@ where } } +#[cfg(feature = "alloc")] +impl SignatureBitStringEncoding for Signature +where + C: PrimeCurve, + MaxSize: ArrayLength, + as Add>::Output: Add + ArrayLength, +{ + fn to_bitstring(&self) -> der::Result { + BitString::new(0, self.to_vec()) + } +} + #[cfg(feature = "serde")] impl Serialize for Signature where