mirror of
https://github.com/kristoferssolo/cipher-workshop.git
synced 2026-02-04 06:42:11 +00:00
feat(cli): make flat command structure
This commit is contained in:
@@ -37,6 +37,10 @@ impl Des {
|
||||
impl BlockCipher for Des {
|
||||
const BLOCK_SIZE: usize = 8;
|
||||
|
||||
fn from_key(key: &[u8]) -> Self {
|
||||
Self::new(key)
|
||||
}
|
||||
|
||||
fn transform_impl(
|
||||
&self,
|
||||
block: &[u8],
|
||||
|
||||
@@ -31,6 +31,21 @@ impl From<[u8; 8]> for Key {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&[u8]> for Key {
|
||||
fn from(value: &[u8]) -> Self {
|
||||
let mut bytes = [0; 8];
|
||||
let len = value.len().min(8);
|
||||
bytes[..len].copy_from_slice(&value[..len]);
|
||||
Self(bytes)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u64> for Key {
|
||||
fn from(key: u64) -> Self {
|
||||
Self(key.to_be_bytes())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Key> for [u8; 8] {
|
||||
fn from(key: Key) -> Self {
|
||||
key.0
|
||||
@@ -43,12 +58,6 @@ impl AsRef<[u8]> for Key {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u64> for Key {
|
||||
fn from(key: u64) -> Self {
|
||||
Self(key.to_be_bytes())
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for Key {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_str("Key([REDACTED])")
|
||||
|
||||
Reference in New Issue
Block a user