magic_crypt/
secure_bit.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use core::convert::TryFrom;

/// How secure does your encryption need to be?
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum SecureBit {
    Bit64,
    Bit128,
    Bit192,
    Bit256,
}

impl Default for SecureBit {
    fn default() -> Self {
        SecureBit::Bit128
    }
}

impl TryFrom<u16> for SecureBit {
    type Error = &'static str;

    #[inline]
    fn try_from(bit_number: u16) -> Result<Self, Self::Error> {
        Ok(match bit_number {
            64 => SecureBit::Bit64,
            128 => SecureBit::Bit128,
            192 => SecureBit::Bit192,
            256 => SecureBit::Bit256,
            _ => return Err("Unsupported number of bits."),
        })
    }
}