Adds support for the SignatureBitStringEncoding trait (#328)

This commit is contained in:
Arthur Gautier 2023-05-04 23:12:43 +00:00 committed by GitHub
parent d61b501182
commit 7a58281a05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 3 deletions

5
Cargo.lock generated
View File

@ -536,6 +536,7 @@ dependencies = [
"sha2",
"sha3",
"signature",
"spki",
"subtle",
"zeroize",
]
@ -671,9 +672,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",

View File

@ -24,7 +24,8 @@ subtle = { version = "2.1.1", default-features = false }
digest = { version = "0.10.5", default-features = false, features = ["alloc", "oid"] }
pkcs1 = { version = "0.7.5", default-features = false, features = ["alloc", "pkcs8"] }
pkcs8 = { version = "0.10.2", default-features = false, features = ["alloc"] }
signature = { version = "2", default-features = false , features = ["digest", "rand_core"] }
signature = { version = "2", default-features = false , features = ["alloc", "digest", "rand_core"] }
spki = { version = "0.7.2", default-features = false, features = ["alloc"] }
zeroize = { version = "1.5", features = ["alloc"] }
# optional dependencies

View File

@ -3,6 +3,10 @@ pub use ::signature::{
DigestSigner, DigestVerifier, Error, Keypair, RandomizedDigestSigner, RandomizedSigner, Result,
SignatureEncoding, Signer, Verifier,
};
use spki::{
der::{asn1::BitString, Result as DerResult},
SignatureBitStringEncoding,
};
use crate::algorithms::pad::uint_to_be_pad;
use alloc::{boxed::Box, string::ToString};
@ -22,6 +26,12 @@ impl SignatureEncoding for Signature {
type Repr = Box<[u8]>;
}
impl SignatureBitStringEncoding for Signature {
fn to_bitstring(&self) -> DerResult<BitString> {
BitString::new(0, self.to_vec())
}
}
impl TryFrom<&[u8]> for Signature {
type Error = signature::Error;

View File

@ -3,6 +3,10 @@ pub use ::signature::{
DigestSigner, DigestVerifier, Error, Keypair, RandomizedDigestSigner, RandomizedSigner, Result,
SignatureEncoding, Signer, Verifier,
};
use spki::{
der::{asn1::BitString, Result as DerResult},
SignatureBitStringEncoding,
};
use crate::algorithms::pad::uint_to_be_pad;
use alloc::{boxed::Box, string::ToString};
@ -22,6 +26,12 @@ impl SignatureEncoding for Signature {
type Repr = Box<[u8]>;
}
impl SignatureBitStringEncoding for Signature {
fn to_bitstring(&self) -> DerResult<BitString> {
BitString::new(0, self.to_vec())
}
}
impl TryFrom<&[u8]> for Signature {
type Error = signature::Error;