1use serde::{Deserialize, Serialize};
6
7#[derive(Clone, Debug, Serialize, Deserialize)]
8pub struct Vault {
9 pub data: String,
10 pub iv: String,
11 pub salt: Option<String>,
12}
13
14#[derive(Clone, Debug, Serialize, Deserialize)]
15#[serde(untagged)]
16pub enum StringOrBytes {
17 String(String),
18 Bytes(Vec<u8>),
19}
20
21impl std::fmt::Display for StringOrBytes {
22 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
23 match self {
24 StringOrBytes::String(s) => write!(f, "{}", s),
25 StringOrBytes::Bytes(_) => Ok(()),
26 }
27 }
28}
29
30#[derive(Clone, Debug, Serialize, Deserialize)]
31#[serde(rename_all = "camelCase")]
32pub struct MnemoicData {
33 pub mnemonic: StringOrBytes,
34 pub number_of_accounts: Option<u32>,
35 pub hd_path: Option<String>,
36}
37
38#[derive(Clone, Debug, Serialize, Deserialize)]
39pub struct DecryptedVault {
40 pub r#type: Option<String>,
41 pub data: MnemoicData,
42}
43
44#[cfg(test)]
45mod tests {
46 use super::*;
47
48 #[test]
49 fn test_string_or_bytes_display() {
50 let string = StringOrBytes::String("hello".to_string());
51 let bytes = StringOrBytes::Bytes(vec![0x68, 0x65, 0x6c, 0x6c, 0x6f]);
52
53 assert_eq!(format!("{}", string), "hello");
54 assert_eq!(format!("{}", bytes), "");
55 }
56}