use std::convert::TryInto;
use crate::mac::MacAlgorithm;
use crate::Error;
#[derive(Debug)]
pub struct Key;
pub struct Clear {}
impl super::Cipher for Clear {
fn key_len(&self) -> usize {
0
}
fn make_opening_key(
&self,
_: &[u8],
_: &[u8],
_: &[u8],
_: &dyn MacAlgorithm,
) -> Box<dyn super::OpeningKey + Send> {
Box::new(Key {})
}
fn make_sealing_key(
&self,
_: &[u8],
_: &[u8],
_: &[u8],
_: &dyn MacAlgorithm,
) -> Box<dyn super::SealingKey + Send> {
Box::new(Key {})
}
}
impl super::OpeningKey for Key {
fn decrypt_packet_length(&self, _seqn: u32, packet_length: &[u8]) -> [u8; 4] {
#[allow(clippy::unwrap_used, clippy::indexing_slicing)]
packet_length.try_into().unwrap()
}
fn tag_len(&self) -> usize {
0
}
fn open<'a>(
&mut self,
_seqn: u32,
ciphertext_and_tag: &'a mut [u8],
) -> Result<&'a [u8], Error> {
#[allow(clippy::indexing_slicing)] Ok(&ciphertext_and_tag[4..])
}
}
impl super::SealingKey for Key {
fn padding_length(&self, payload: &[u8]) -> usize {
let block_size = 8;
let padding_len = block_size - ((5 + payload.len()) % block_size);
if padding_len < 4 {
padding_len + block_size
} else {
padding_len
}
}
fn fill_padding(&self, padding_out: &mut [u8]) {
for padding_byte in padding_out {
*padding_byte = 0;
}
}
fn tag_len(&self) -> usize {
0
}
fn seal(&mut self, _seqn: u32, _plaintext_in_ciphertext_out: &mut [u8], tag_out: &mut [u8]) {
debug_assert_eq!(tag_out.len(), self.tag_len());
}
}