Skip to content

Commit

Permalink
digest: expose AssociatedAlgorithmIdentifier through CoreWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
baloo committed May 22, 2024
1 parent f79f286 commit f32b565
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions digest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ block-buffer = { version = "=0.11.0-pre.5", optional = true }
subtle = { version = "2.4", default-features = false, optional = true }
blobby = { version = "0.3", optional = true }
const-oid = { version = "=0.10.0-pre.2", optional = true }
spki = { version = "=0.8.0-pre.0", optional = true }
zeroize = { version = "1.7", optional = true, default-features = false }

[features]
Expand All @@ -28,6 +29,7 @@ core-api = ["block-buffer"] # Enable Core API traits
mac = ["subtle"] # Enable MAC traits
rand_core = ["crypto-common/rand_core"] # Enable random key generation methods
oid = ["const-oid"]
spki = ["oid", "dep:spki"]
zeroize = ["dep:zeroize", "block-buffer?/zeroize"]
alloc = []
std = ["alloc", "crypto-common/std"]
Expand Down
15 changes: 15 additions & 0 deletions digest/src/core_api/ct_variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ use crypto_common::{
typenum::{IsLess, IsLessOrEqual, Le, LeEq, NonZero, Sum, U1, U256},
Block, BlockSizeUser, OutputSizeUser,
};
#[cfg(feature = "spki")]
use spki::{AlgorithmIdentifier, AssociatedAlgorithmIdentifier};

/// Dummy type used with [`CtVariableCoreWrapper`] in cases when
/// resulting hash does not have a known OID.
Expand Down Expand Up @@ -167,6 +169,19 @@ where
const OID: ObjectIdentifier = O::OID;
}

#[cfg(feature = "spki")]
impl<T, OutSize, O> AssociatedAlgorithmIdentifier for CtVariableCoreWrapper<T, OutSize, O>
where
T: VariableOutputCore,
O: AssociatedAlgorithmIdentifier,
OutSize: ArraySize + IsLessOrEqual<T::OutputSize>,
LeEq<OutSize, T::OutputSize>: NonZero,
{
type Params = O::Params;

const ALGORITHM_IDENTIFIER: AlgorithmIdentifier<Self::Params> = O::ALGORITHM_IDENTIFIER;
}

#[cfg(feature = "zeroize")]
impl<T, OutSize, O> zeroize::ZeroizeOnDrop for CtVariableCoreWrapper<T, OutSize, O>
where
Expand Down
12 changes: 12 additions & 0 deletions digest/src/core_api/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ use crypto_common::{
use crate::MacMarker;
#[cfg(feature = "oid")]
use const_oid::{AssociatedOid, ObjectIdentifier};
#[cfg(feature = "spki")]
use spki::{AlgorithmIdentifier, AssociatedAlgorithmIdentifier};

/// Wrapper around [`BufferKindUser`].
///
Expand Down Expand Up @@ -179,6 +181,16 @@ where
const OID: ObjectIdentifier = T::OID;
}

#[cfg(feature = "spki")]
impl<T> AssociatedAlgorithmIdentifier for CoreWrapper<T>
where
T: BufferKindUser + AssociatedAlgorithmIdentifier,
{
type Params = T::Params;

const ALGORITHM_IDENTIFIER: AlgorithmIdentifier<Self::Params> = T::ALGORITHM_IDENTIFIER;
}

type CoreWrapperSerializedStateSize<T> =
Sum<Sum<<T as SerializableState>::SerializedStateSize, U1>, <T as BlockSizeUser>::BlockSize>;

Expand Down
2 changes: 2 additions & 0 deletions digest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ pub use block_buffer;
#[cfg(feature = "oid")]
pub use const_oid;
pub use crypto_common;
#[cfg(feature = "spki")]
pub use spki;

#[cfg(feature = "const-oid")]
pub use crate::digest::DynDigestWithOid;
Expand Down

0 comments on commit f32b565

Please sign in to comment.