prople_crypto/keysecure/
types.rs1use rst_common::standard::serde::{self, Deserialize, Serialize};
3
4use crate::keysecure::KeySecure;
5
6pub mod constants {
7 pub const KDF_ALGO: &str = "argon2";
8 pub const CRYPTO_CIPHER_ALGO: &str = "xchacha20poly1305";
9}
10
11pub mod errors {
12 use rst_common::with_errors::thiserror::{self, Error};
13
14 pub use crate::errors::CommonError;
15
16 #[derive(Debug, Error, PartialEq)]
19 pub enum KeySecureError {
20 #[error("keysecure: unable to build key secure: `{0}`")]
21 BuildKeySecureError(String),
22
23 #[error("keysecure: unable to decrypt: `{0}`")]
24 DecryptError(String),
25
26 #[error("eddsa: common error")]
27 Common(#[from] CommonError),
28 }
29}
30
31use crate::types::StringValue;
32
33#[derive(Clone, Debug, Serialize, Deserialize)]
34#[serde(crate = "self::serde")]
35pub enum ContextOptions {
36 X25519,
37 ED25519,
38}
39
40impl ContextOptions {
41 pub fn get(&self) -> String {
42 match self {
43 ContextOptions::X25519 => String::from("X25519"),
44 ContextOptions::ED25519 => String::from("Ed25519"),
45 }
46 }
47}
48
49#[derive(Clone, Debug)]
50pub struct Password(String);
51
52impl StringValue for Password {
53 fn get_string(&self) -> String {
54 self.0.to_owned()
55 }
56}
57
58impl From<String> for Password {
59 fn from(value: String) -> Self {
60 Password(value)
61 }
62}
63
64pub trait ToKeySecure {
67 fn to_keysecure(&self, password: Password) -> Result<KeySecure, errors::KeySecureError>;
68}