kryptonite 0.1.0

Zero-dependency cryptographic utilities in modern Rust.
Documentation
pub enum Key {
    Sized128Bits([u8; 16]),
    Sized192Bits([u8; 24]),
    Sized256Bits([u8; 32]),
}

#[repr(u8)]
#[derive(Debug)]
pub enum Rounds {
    Count10 = 10,
    Count12 = 12,
    Count14 = 14,
}

impl Key {
    pub fn rounds(self: &Self) -> Rounds {
        match self {
            Self::Sized128Bits(_) => Rounds::Count10,
            Self::Sized192Bits(_) => Rounds::Count12,
            Self::Sized256Bits(_) => Rounds::Count14,
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn rounds_from_key_size() {
        #[cfg_attr(rustfmt, rustfmt_skip)]
        let example_key_128bits: [u8; 16] = [
            0x54, 0x68, 0x61, 0x74, 0x73, 0x20, 0x6d, 0x79,
            0x20, 0x4b, 0x75, 0x6e, 0x67, 0x20, 0x46, 0x75,
        ];

        #[cfg_attr(rustfmt, rustfmt_skip)]
        let example_key_192bits: [u8; 24] = [
            0x54, 0x68, 0x61, 0x74, 0x73, 0x20, 0x6d, 0x79,
            0x20, 0x4b, 0x75, 0x6e, 0x67, 0x20, 0x46, 0x75,
            0x54, 0x68, 0x61, 0x74, 0x73, 0x20, 0x6d, 0x79,
        ];

        #[cfg_attr(rustfmt, rustfmt_skip)]
        let example_key_256bits: [u8; 32] = [
            0x54, 0x68, 0x61, 0x74, 0x73, 0x20, 0x6d, 0x79,
            0x20, 0x4b, 0x75, 0x6e, 0x67, 0x20, 0x46, 0x75,
            0x54, 0x68, 0x61, 0x74, 0x73, 0x20, 0x6d, 0x79,
            0x20, 0x4b, 0x75, 0x6e, 0x67, 0x20, 0x46, 0x75,
        ];

        let k128 = Key::Sized128Bits(example_key_128bits);
        assert_eq!(k128.rounds() as u8, 10);

        let k192 = Key::Sized192Bits(example_key_192bits);
        assert_eq!(k192.rounds() as u8, 12);

        let k256 = Key::Sized256Bits(example_key_256bits);
        assert_eq!(k256.rounds() as u8, 14);
    }
}