prople_crypto/keysecure/
objects.rs

1//! `objects` provides multiple data objects used to generate `KeySecure` data format
2use rst_common::standard::serde::{self, Deserialize, Serialize};
3
4use crate::keysecure::types::constants::*;
5use crate::passphrase::kdf_params::KdfParams as PassphraseKDFParams;
6
7/// `KeySecureCryptoParams` store a single field for the `nonce`
8#[derive(Debug, Serialize, Deserialize, Clone)]
9#[serde(crate = "self::serde")]
10pub struct KeySecureCryptoParams {
11    pub nonce: String,
12}
13
14/// `KeySecureCrypto` will be used to store the encrypted data including for
15/// it's supported components
16///
17/// This data will consists of:
18/// - cipher
19/// - cipher_text
20/// - cipher_params
21/// - kdf
22/// - kdf_params
23#[derive(Debug, Serialize, Deserialize, Clone)]
24#[serde(crate = "self::serde")]
25pub struct KeySecureCrypto {
26    pub cipher: String,
27
28    #[serde(rename = "cipherText")]
29    pub cipher_text: String,
30
31    #[serde(rename = "cipherParams")]
32    pub cipher_params: KeySecureCryptoParams,
33
34    pub kdf: String,
35
36    #[serde(rename = "kdfParams")]
37    pub kdf_params: KdfParams,
38}
39
40impl KeySecureCrypto {
41    pub fn new(nonce: String, ciphertext: String, kdf_params: KdfParams) -> Self {
42        let params = KeySecureCryptoParams { nonce };
43        Self {
44            cipher: CRYPTO_CIPHER_ALGO.to_string(),
45            cipher_text: ciphertext,
46            cipher_params: params,
47            kdf: KDF_ALGO.to_string(),
48            kdf_params,
49        }
50    }
51}
52
53/// `KdfParams` used to store passphrase kdf params and it's salt
54#[derive(Debug, Serialize, Deserialize, Clone)]
55#[serde(crate = "self::serde")]
56pub struct KdfParams {
57    pub params: PassphraseKDFParams,
58    pub salt: String,
59}
60
61impl KdfParams {
62    pub fn new(params: PassphraseKDFParams, salt: String) -> Self {
63        Self { params, salt }
64    }
65}