Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

digest: add implementations of the AssociatedOid trait #1098

Merged
merged 12 commits into from
Sep 16, 2022
17 changes: 9 additions & 8 deletions Cargo.lock

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

7 changes: 7 additions & 0 deletions digest/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## UNRELEASED
### Added
- Feature-gated implementation of the `const_oid::AssociatedOid` trait
for the core wrappers. ([#1098])

[#1098]: https://github.com/RustCrypto/traits/pull/1098

## 0.10.3 (2022-02-16)
### Fixed
- Minimal versions build ([#940])
Expand Down
3 changes: 3 additions & 0 deletions digest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ crypto-common = { version = "0.1.3", path = "../crypto-common" }
block-buffer = { version = "0.10", optional = true }
subtle = { version = "=2.4", default-features = false, optional = true }
blobby = { version = "0.3", optional = true }
# Enable implementation of the `AssociatedOid` trait for the core wrappers.
# Enabling this feature bumps MSRV to 1.57.
const-oid = { version = "0.9", optional = true }

[features]
default = ["core-api"]
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 @@ -5,6 +5,8 @@ use super::{
use crate::HashMarker;
#[cfg(feature = "mac")]
use crate::MacMarker;
#[cfg(feature = "const-oid")]
use const_oid::{AssociatedOid, ObjectIdentifier};
use core::{fmt, marker::PhantomData};
use crypto_common::{
generic_array::{ArrayLength, GenericArray},
Expand Down Expand Up @@ -165,3 +167,16 @@ where
write!(f, "{}", OutSize::USIZE)
}
}

#[cfg(feature = "const-oid")]
#[cfg_attr(docsrs, doc(cfg(feature = "const-oid")))]
impl<T, OutSize> AssociatedOid for CtVariableCoreWrapper<T, OutSize>
where
T: VariableOutputCore + AssociatedOid,
OutSize: ArrayLength<u8> + IsLessOrEqual<T::OutputSize>,
LeEq<OutSize, T::OutputSize>: NonZero,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
const OID: ObjectIdentifier = T::OID;
}
13 changes: 13 additions & 0 deletions digest/src/core_api/rt_variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use crate::MacMarker;
use crate::{HashMarker, InvalidBufferSize};
use crate::{InvalidOutputSize, Reset, Update, VariableOutput, VariableOutputReset};
use block_buffer::BlockBuffer;
#[cfg(feature = "const-oid")]
use const_oid::{AssociatedOid, ObjectIdentifier};
use core::fmt;
use crypto_common::typenum::{IsLess, Le, NonZero, Unsigned, U256};

Expand Down Expand Up @@ -145,6 +147,17 @@ where
}
}

#[cfg(feature = "const-oid")]
#[cfg_attr(docsrs, doc(cfg(feature = "const-oid")))]
impl<T> AssociatedOid for RtVariableCoreWrapper<T>
where
T: VariableOutputCore + UpdateCore + AssociatedOid,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
const OID: ObjectIdentifier = T::OID;
}

#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl<T> std::io::Write for RtVariableCoreWrapper<T>
Expand Down
13 changes: 13 additions & 0 deletions digest/src/core_api/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use crypto_common::{

#[cfg(feature = "mac")]
use crate::MacMarker;
#[cfg(feature = "const-oid")]
use const_oid::{AssociatedOid, ObjectIdentifier};

/// Wrapper around [`BufferKindUser`].
///
Expand Down Expand Up @@ -227,6 +229,17 @@ where
}
}

#[cfg(feature = "const-oid")]
#[cfg_attr(docsrs, doc(cfg(feature = "const-oid")))]
impl<T> AssociatedOid for CoreWrapper<T>
where
T: BufferKindUser + AssociatedOid,
T::BlockSize: IsLess<U256>,
Le<T::BlockSize, U256>: NonZero,
{
const OID: ObjectIdentifier = T::OID;
}

#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl<T> std::io::Write for CoreWrapper<T>
Expand Down
3 changes: 3 additions & 0 deletions digest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ mod mac;
#[cfg(feature = "core-api")]
#[cfg_attr(docsrs, doc(cfg(feature = "core-api")))]
pub use block_buffer;
#[cfg(feature = "const-oid")]
newpavlov marked this conversation as resolved.
Show resolved Hide resolved
#[cfg_attr(docsrs, doc(cfg(feature = "const-oid")))]
pub use const_oid;
pub use crypto_common;

pub use crate::digest::{Digest, DynDigest, HashMarker};
Expand Down