Skip to content

Commit dbd6271

Browse files
committed
sha2: provide support for spki::AlgorithmIdentifier
This implements `AlgorithmIdentifier` according to [RFC5754 section 2] [RFC5754 section 2]: https://www.rfc-editor.org/rfc/rfc5754#section-2
1 parent 7160035 commit dbd6271

File tree

5 files changed

+53
-2
lines changed

5 files changed

+53
-2
lines changed

Cargo.lock

+20-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ opt-level = 2
3030

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

3536
sha1 = { path = "./sha1" }

sha2/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ hex-literal = "0.4"
3030
default = ["oid", "std"]
3131
std = ["digest/std"]
3232
oid = ["digest/oid"] # Enable OID support
33+
spki = ["oid", "digest/spki"]
3334
zeroize = ["digest/zeroize"]
3435
force-soft = [] # Force software implementation
3536

sha2/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ mod consts;
2222
mod core_api;
2323
mod sha256;
2424
mod sha512;
25+
#[cfg(feature = "spki")]
26+
mod spki;
2527

2628
pub use sha256::compress256;
2729
pub use sha512::compress512;

sha2/src/spki.rs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//! Implements [`AlgorithmIdentifier`] according to [RFC5754 section 2]
2+
//!
3+
//! [RFC5754 section 2]: https://www.rfc-editor.org/rfc/rfc5754#section-2
4+
5+
use digest::{
6+
const_oid::AssociatedOid,
7+
spki::{der::asn1::AnyRef, AlgorithmIdentifierRef, AssociatedAlgorithmIdentifier},
8+
};
9+
10+
use super::{OidSha224, OidSha256, OidSha384, OidSha512};
11+
12+
macro_rules! impl_aai {
13+
($name:ident) => {
14+
impl AssociatedAlgorithmIdentifier for $name {
15+
type Params = AnyRef<'static>;
16+
17+
const ALGORITHM_IDENTIFIER: AlgorithmIdentifierRef<'static> = AlgorithmIdentifierRef {
18+
oid: Self::OID,
19+
parameters: None,
20+
};
21+
}
22+
};
23+
}
24+
25+
impl_aai!(OidSha224);
26+
impl_aai!(OidSha256);
27+
impl_aai!(OidSha384);
28+
impl_aai!(OidSha512);

0 commit comments

Comments
 (0)