Skip to content

Commit

Permalink
Adds support for the SignatureBitStringEncoding trait (#328)
Browse files Browse the repository at this point in the history
  • Loading branch information
baloo authored May 4, 2023
1 parent d61b501 commit 7a58281
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/pkcs1v15/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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;

Expand Down
10 changes: 10 additions & 0 deletions src/pss/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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;

Expand Down

0 comments on commit 7a58281

Please sign in to comment.