convenience function for converting to a block from a vec
@@ -104,6 +104,19 @@ impl Block {
pub fn flip(&self) -> Self {
unsafe { Block(_mm_xor_si128(self.0, ONES)) }
}
+
+ /// Try to create a Block from a Vec of bytes. The vec must have exactly 16 bytes.
+ #[inline]
+ pub fn try_from_vec(bytes_vec: Vec<u8>) -> Option<Self> {
+ if bytes_vec.len() != 16 {
+ return None;
+ }
+ let mut bytes = [0; 16];
+ for i in 0..16 {
+ bytes[i] = bytes_vec[i];
+ }
+ Some(Block::from(bytes))
+ }
}
impl Default for Block {
