netstack/security/
secret.rs

1const SECRET_SIZE: usize = 32;
2
3#[derive(Debug, Eq, PartialEq, Clone)]
4pub struct Secret([u8; SECRET_SIZE]);
5
6impl Secret {
7    pub fn from_slice(slice: &[u8]) -> Result<Self, ()> {
8        if slice.len() != SECRET_SIZE {
9            panic!("TODO slice wrong size")
10        }
11
12        let mut bytes = [0; SECRET_SIZE];
13        for i in 0..SECRET_SIZE {
14            bytes[i] = slice[i];
15        }
16
17        Ok(Self(bytes))
18    }
19    
20    pub fn from_bytes(bytes: [u8; SECRET_SIZE]) -> Self {
21        Self(bytes)
22    }
23
24    pub fn get_bytes(&self) -> &[u8] {
25        &self.0
26    }
27}