-
Notifications
You must be signed in to change notification settings - Fork 216
digest: add implementations of the AssociatedOid trait #1098
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
Changes from 7 commits
1779c4b
b7debee
b3fb730
626edc5
f628a51
9ab1fbf
2198fed
b8441dc
a9159a1
46948c0
14add17
8889c4c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,17 +5,24 @@ use super::{ | |
use crate::HashMarker; | ||
#[cfg(feature = "mac")] | ||
use crate::MacMarker; | ||
#[cfg(feature = "oid")] | ||
use const_oid::{AssociatedOid, ObjectIdentifier}; | ||
use core::{fmt, marker::PhantomData}; | ||
use crypto_common::{ | ||
generic_array::{ArrayLength, GenericArray}, | ||
typenum::{IsLess, IsLessOrEqual, Le, LeEq, NonZero, U256}, | ||
Block, BlockSizeUser, OutputSizeUser, | ||
}; | ||
|
||
/// Dummy type used with [`CtVariableCoreWrapper`] in cases when | ||
/// resulting hash does not have a known OID. | ||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] | ||
pub struct NoOid; | ||
|
||
/// Wrapper around [`VariableOutputCore`] which selects output size | ||
/// at compile time. | ||
#[derive(Clone)] | ||
pub struct CtVariableCoreWrapper<T, OutSize> | ||
pub struct CtVariableCoreWrapper<T, OutSize, O = NoOid> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of using an extra generic type here, could That would avoid complicating the type signature and eliminate the need for Ditto for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I understand you correctly, then no, it will not work. See the SHA-224 vs SHA-256 issue raised in my earlier comment. They have the same core (i.e. the same There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ugh, ok. That's really rather unfortunate. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally we would use |
||
where | ||
T: VariableOutputCore, | ||
OutSize: ArrayLength<u8> + IsLessOrEqual<T::OutputSize>, | ||
|
@@ -24,10 +31,10 @@ where | |
Le<T::BlockSize, U256>: NonZero, | ||
{ | ||
inner: T, | ||
_out: PhantomData<OutSize>, | ||
_out: PhantomData<(OutSize, O)>, | ||
} | ||
|
||
impl<T, OutSize> HashMarker for CtVariableCoreWrapper<T, OutSize> | ||
impl<T, OutSize, O> HashMarker for CtVariableCoreWrapper<T, OutSize, O> | ||
where | ||
T: VariableOutputCore + HashMarker, | ||
OutSize: ArrayLength<u8> + IsLessOrEqual<T::OutputSize>, | ||
|
@@ -38,7 +45,7 @@ where | |
} | ||
|
||
#[cfg(feature = "mac")] | ||
impl<T, OutSize> MacMarker for CtVariableCoreWrapper<T, OutSize> | ||
impl<T, OutSize, O> MacMarker for CtVariableCoreWrapper<T, OutSize, O> | ||
where | ||
T: VariableOutputCore + MacMarker, | ||
OutSize: ArrayLength<u8> + IsLessOrEqual<T::OutputSize>, | ||
|
@@ -48,7 +55,7 @@ where | |
{ | ||
} | ||
|
||
impl<T, OutSize> BlockSizeUser for CtVariableCoreWrapper<T, OutSize> | ||
impl<T, OutSize, O> BlockSizeUser for CtVariableCoreWrapper<T, OutSize, O> | ||
where | ||
T: VariableOutputCore, | ||
OutSize: ArrayLength<u8> + IsLessOrEqual<T::OutputSize>, | ||
|
@@ -59,7 +66,7 @@ where | |
type BlockSize = T::BlockSize; | ||
} | ||
|
||
impl<T, OutSize> UpdateCore for CtVariableCoreWrapper<T, OutSize> | ||
impl<T, OutSize, O> UpdateCore for CtVariableCoreWrapper<T, OutSize, O> | ||
where | ||
T: VariableOutputCore, | ||
OutSize: ArrayLength<u8> + IsLessOrEqual<T::OutputSize>, | ||
|
@@ -73,7 +80,7 @@ where | |
} | ||
} | ||
|
||
impl<T, OutSize> OutputSizeUser for CtVariableCoreWrapper<T, OutSize> | ||
impl<T, OutSize, O> OutputSizeUser for CtVariableCoreWrapper<T, OutSize, O> | ||
where | ||
T: VariableOutputCore, | ||
OutSize: ArrayLength<u8> + IsLessOrEqual<T::OutputSize> + 'static, | ||
|
@@ -84,7 +91,7 @@ where | |
type OutputSize = OutSize; | ||
} | ||
|
||
impl<T, OutSize> BufferKindUser for CtVariableCoreWrapper<T, OutSize> | ||
impl<T, OutSize, O> BufferKindUser for CtVariableCoreWrapper<T, OutSize, O> | ||
where | ||
T: VariableOutputCore, | ||
OutSize: ArrayLength<u8> + IsLessOrEqual<T::OutputSize>, | ||
|
@@ -95,7 +102,7 @@ where | |
type BufferKind = T::BufferKind; | ||
} | ||
|
||
impl<T, OutSize> FixedOutputCore for CtVariableCoreWrapper<T, OutSize> | ||
impl<T, OutSize, O> FixedOutputCore for CtVariableCoreWrapper<T, OutSize, O> | ||
where | ||
T: VariableOutputCore, | ||
OutSize: ArrayLength<u8> + IsLessOrEqual<T::OutputSize> + 'static, | ||
|
@@ -120,7 +127,7 @@ where | |
} | ||
} | ||
|
||
impl<T, OutSize> Default for CtVariableCoreWrapper<T, OutSize> | ||
impl<T, OutSize, O> Default for CtVariableCoreWrapper<T, OutSize, O> | ||
where | ||
T: VariableOutputCore, | ||
OutSize: ArrayLength<u8> + IsLessOrEqual<T::OutputSize>, | ||
|
@@ -137,7 +144,7 @@ where | |
} | ||
} | ||
|
||
impl<T, OutSize> Reset for CtVariableCoreWrapper<T, OutSize> | ||
impl<T, OutSize, O> Reset for CtVariableCoreWrapper<T, OutSize, O> | ||
where | ||
T: VariableOutputCore, | ||
OutSize: ArrayLength<u8> + IsLessOrEqual<T::OutputSize>, | ||
|
@@ -151,7 +158,7 @@ where | |
} | ||
} | ||
|
||
impl<T, OutSize> AlgorithmName for CtVariableCoreWrapper<T, OutSize> | ||
impl<T, OutSize, O> AlgorithmName for CtVariableCoreWrapper<T, OutSize, O> | ||
where | ||
T: VariableOutputCore + AlgorithmName, | ||
OutSize: ArrayLength<u8> + IsLessOrEqual<T::OutputSize>, | ||
|
@@ -165,3 +172,33 @@ where | |
write!(f, "{}", OutSize::USIZE) | ||
} | ||
} | ||
|
||
#[cfg(feature = "oid")] | ||
#[cfg_attr(docsrs, doc(cfg(feature = "oid")))] | ||
impl<T, OutSize, O> AssociatedOid for CtVariableCoreWrapper<T, OutSize, O> | ||
where | ||
T: VariableOutputCore, | ||
O: AssociatedOid, | ||
OutSize: ArrayLength<u8> + IsLessOrEqual<T::OutputSize>, | ||
LeEq<OutSize, T::OutputSize>: NonZero, | ||
T::BlockSize: IsLess<U256>, | ||
Le<T::BlockSize, U256>: NonZero, | ||
{ | ||
const OID: ObjectIdentifier = O::OID; | ||
} | ||
|
||
/// Implement dummy type with hidden docs which is used to "carry" hasher | ||
/// OID for [`CtVariableCoreWrapper`]. | ||
#[macro_export] | ||
macro_rules! impl_oid_carrier { | ||
($name:ident, $oid:literal) => { | ||
#[doc(hidden)] | ||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] | ||
pub struct $name; | ||
|
||
#[cfg(feature = "oid")] | ||
impl AssociatedOid for $name { | ||
const OID: ObjectIdentifier = ObjectIdentifier::new_unwrap($oid); | ||
} | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder how can we handle it better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can split out a separate job for it with a comment to re-unify them when MSRV is bumped.