Skip to main content

rskit_encryption/
factory.rs

1use crate::aes_gcm::AesGcmEncryptor;
2use crate::chacha20::ChaCha20Encryptor;
3use crate::traits::{Algorithm, Encryptor};
4
5/// Creates a new encryptor for the specified algorithm.
6///
7/// # Arguments
8///
9/// * `key` - The encryption passphrase (used with PBKDF2-SHA256 to derive keys)
10/// * `algorithm` - The encryption algorithm to use
11///
12/// # Returns
13///
14/// A boxed trait object implementing [`Encryptor`].
15///
16/// # Examples
17///
18/// ```no_run
19/// use rskit_encryption::{new_encryptor, Algorithm};
20///
21/// let encryptor = new_encryptor(b"secret-key", Algorithm::ChaCha20Poly1305);
22/// ```
23pub fn new_encryptor(key: &[u8], algorithm: Algorithm) -> Box<dyn Encryptor> {
24    match algorithm {
25        Algorithm::AesGcm => Box::new(AesGcmEncryptor::new(key)),
26        Algorithm::ChaCha20Poly1305 => Box::new(ChaCha20Encryptor::new(key)),
27    }
28}