Skip to content

Commit

Permalink
spki: Adds a SignatureBitStringEncoding trait
Browse files Browse the repository at this point in the history
This is used to differentiate the different encoding for signatures as
x509 related structures rely on `BitString` encoding of the various
signatures.

This is mostly used as a marker trait to ensure misuse resistance of the
API.
  • Loading branch information
baloo committed May 4, 2023
1 parent 476d1a0 commit e467cef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions spki/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub use {
spki::SubjectPublicKeyInfoOwned,
traits::{
DynAssociatedAlgorithmIdentifier, DynSignatureAlgorithmIdentifier, EncodePublicKey,
SignatureBitStringEncoding,
},
},
der::Document,
Expand Down
11 changes: 10 additions & 1 deletion spki/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use der::{EncodeValue, Tagged};
#[cfg(feature = "alloc")]
use {
crate::AlgorithmIdentifierOwned,
der::{Any, Document},
der::{asn1::BitString, Any, Document},
};

#[cfg(feature = "pem")]
Expand Down Expand Up @@ -173,3 +173,12 @@ where
})
}
}

/// Returns the `BitString` encoding of the signature.
///
/// X.509 and CSR structures require signatures to be BitString encoded.
#[cfg(feature = "alloc")]
pub trait SignatureBitStringEncoding {
/// `BitString` encoding for this signature.
fn to_bitstring(&self) -> der::Result<BitString>;
}

0 comments on commit e467cef

Please sign in to comment.