Trait crypto_common::KeyInit
source · pub trait KeyInit: KeySizeUser + Sized {
fn new(key: &Key<Self>) -> Self;
fn new_from_slice(key: &[u8]) -> Result<Self, InvalidLength> { ... }
fn generate_key(rng: impl CryptoRng + RngCore) -> Key<Self> { ... }
}
Expand description
Types which can be initialized from key.
Required Methods§
Provided Methods§
sourcefn new_from_slice(key: &[u8]) -> Result<Self, InvalidLength>
fn new_from_slice(key: &[u8]) -> Result<Self, InvalidLength>
Create new value from variable size key.
Examples found in repository?
src/lib.rs (line 278)
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
fn new_from_slices(key: &[u8], iv: &[u8]) -> Result<Self, InvalidLength> {
T::Inner::new_from_slice(key).and_then(|i| T::inner_iv_slice_init(i, iv))
}
}
impl<T> KeyInit for T
where
T: InnerInit,
T::Inner: KeyInit,
{
#[inline]
fn new(key: &Key<Self>) -> Self {
Self::inner_init(T::Inner::new(key))
}
#[inline]
fn new_from_slice(key: &[u8]) -> Result<Self, InvalidLength> {
T::Inner::new_from_slice(key)
.map_err(|_| InvalidLength)
.map(Self::inner_init)
}