Group revamp (#261)
* Revamp `KeGroup` trait * Update dependencies * Fix `hash_to_scalar` using `OprfGroup` instead of `KeGroup` * Relax constraints on associated types of `KeGroup` * Improve `KeGroup` implementation on `Curve` * Improve `KeyExchange` trait * Fix new Clippy 1.59 warnings
This commit is contained in:
@@ -12,7 +12,7 @@ use generic_array::typenum::{U0, U2};
|
||||
use generic_array::{ArrayLength, GenericArray};
|
||||
use hmac::Mac;
|
||||
|
||||
use crate::errors::ProtocolError;
|
||||
use crate::errors::{InternalError, ProtocolError};
|
||||
|
||||
// Corresponds to the I2OSP() function from RFC8017
|
||||
pub(crate) fn i2osp<L: ArrayLength<u8>>(
|
||||
@@ -157,6 +157,20 @@ impl<T: Mac> MacExt for T {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) trait GenericArrayExt {
|
||||
fn try_from_slice(slice: &[u8]) -> Result<&Self, InternalError>;
|
||||
}
|
||||
|
||||
impl<L: ArrayLength<u8>> GenericArrayExt for GenericArray<u8, L> {
|
||||
fn try_from_slice(slice: &[u8]) -> Result<&Self, InternalError> {
|
||||
if slice.len() == L::USIZE {
|
||||
Ok(Self::from_slice(slice))
|
||||
} else {
|
||||
Err(InternalError::InvalidByteSequence)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user