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
32
33
//! `key` module provides a simple object struct to maintain
//! generated key and nonce used to encrypt and decrypt a message 

/// `Key` used to store `key` and `nonce`
///
/// The `key` field used to store bytes that defined by
/// `chacha20poly1305` key properties which is an alias of
/// `GenericArray<u8, U32>`  
///
/// The `nonce` field used when encrypt and decrypt given message
/// which is an alias of `GenericArray<u8, <A as AeadCore>::NonceSize>`
/// taken from `aead` crate
///
/// Both of these properties grouped into this single object to simplify
/// the API library
pub struct Key {
    key: [u8; 32],
    nonce: [u8; 24],
}

impl Key {
    pub fn generate(key: [u8; 32], nonce: [u8; 24]) -> Self {
        Self { key, nonce }
    }

    pub fn get_key(&self) -> [u8; 32] {
        self.key
    }

    pub fn get_nonce(&self) -> [u8; 24] {
        self.nonce
    }
}