Skip to content

Commit

Permalink
sha2: provide support for spki::AlgorithmIdentifier
Browse files Browse the repository at this point in the history
This implements `AlgorithmIdentifier` according to [RFC5754 section 2]

[RFC5754 section 2]: https://www.rfc-editor.org/rfc/rfc5754#section-2
  • Loading branch information
baloo committed May 22, 2024
1 parent 7160035 commit e478086
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 2 deletions.
21 changes: 20 additions & 1 deletion 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 @@ -30,6 +30,7 @@ opt-level = 2

[patch.crates-io]
# https://github.com/RustCrypto/traits/pull/1537 - Unreleased
digest = { git = "https://github.com/RustCrypto/traits.git" }
# https://github.com/RustCrypto/traits/pull/1575
digest = { git = "https://github.com/baloo/traits.git", branch = "baloo/digest/expose-spki" }

sha1 = { path = "./sha1" }
1 change: 1 addition & 0 deletions sha2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ hex-literal = "0.4"
default = ["oid", "std"]
std = ["digest/std"]
oid = ["digest/oid"] # Enable OID support
spki = ["oid", "digest/spki"]
zeroize = ["digest/zeroize"]
force-soft = [] # Force software implementation

Expand Down
2 changes: 2 additions & 0 deletions sha2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ mod consts;
mod core_api;
mod sha256;
mod sha512;
#[cfg(feature = "spki")]
mod spki;

pub use sha256::compress256;
pub use sha512::compress512;
Expand Down
28 changes: 28 additions & 0 deletions sha2/src/spki.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//! Implements [`AlgorithmIdentifier`] according to [RFC5754 section 2]
//!
//! [RFC5754 section 2]: https://www.rfc-editor.org/rfc/rfc5754#section-2

use digest::{
const_oid::AssociatedOid,
spki::{der::asn1::AnyRef, AlgorithmIdentifierRef, AssociatedAlgorithmIdentifier},
};

use super::{OidSha224, OidSha256, OidSha384, OidSha512};

macro_rules! impl_aai {
($name:ident) => {
impl AssociatedAlgorithmIdentifier for $name {
type Params = AnyRef<'static>;

const ALGORITHM_IDENTIFIER: AlgorithmIdentifierRef<'static> = AlgorithmIdentifierRef {
oid: Self::OID,
parameters: None,
};
}
};
}

impl_aai!(OidSha224);
impl_aai!(OidSha256);
impl_aai!(OidSha384);
impl_aai!(OidSha512);

0 comments on commit e478086

Please sign in to comment.