hapi_iron_oxide/
options.rs1use crate::algorithm::Algorithm;
2
3#[derive(Debug, PartialEq)]
4pub struct EncryptionOptions {
5 pub algorithm: Algorithm,
6 pub iterations: i32,
7 pub minimum_password_length: i32,
8}
9
10#[derive(Debug, PartialEq)]
11pub struct SealOptions {
12 pub encryption: EncryptionOptions,
13 pub integrity: EncryptionOptions,
14 pub ttl: i64,
15 pub timestamp_skew: u32,
16 pub local_offset: i32,
17}
18
19pub struct SealOptionsBuilder {
20 encryption: EncryptionOptions,
21 integrity: EncryptionOptions,
22 ttl: i64,
23 timestamp_skew: u32,
24 local_offset: i32,
25}
26
27impl Default for SealOptionsBuilder {
28 fn default() -> Self {
29 Self {
30 encryption: EncryptionOptions {
31 algorithm: Algorithm::Aes256Cbc,
32 iterations: 1,
33 minimum_password_length: 32,
34 },
35 integrity: EncryptionOptions {
36 algorithm: Algorithm::Sha256,
37 iterations: 1,
38 minimum_password_length: 32,
39 },
40 ttl: 0,
41 timestamp_skew: 60,
42 local_offset: 0,
43 }
44 }
45}
46
47impl Default for SealOptions {
48 fn default() -> Self {
49 Self {
50 encryption: EncryptionOptions {
51 algorithm: Algorithm::Aes256Cbc,
52 iterations: 1,
53 minimum_password_length: 32,
54 },
55 integrity: EncryptionOptions {
56 algorithm: Algorithm::Sha256,
57 iterations: 1,
58 minimum_password_length: 32,
59 },
60 ttl: 0,
61 timestamp_skew: 60,
62 local_offset: 0,
63 }
64 }
65}
66
67impl SealOptions {
68 pub fn config(&self) -> &Self {
69 self
70 }
71}
72
73impl SealOptionsBuilder {
74 pub fn new() -> Self {
75 Self::default()
76 }
77
78 pub fn encryption(mut self, e: EncryptionOptions) -> Self {
79 self.encryption = e;
80 self
81 }
82
83 pub fn integrity(mut self, i: EncryptionOptions) -> Self {
84 self.integrity = i;
85 self
86 }
87
88 pub fn ttl(mut self, ttl: i64) -> Self {
89 self.ttl = ttl;
90 self
91 }
92
93 pub fn timestamp_skew(mut self, timestamp_skew: u32) -> Self {
94 self.timestamp_skew = timestamp_skew;
95 self
96 }
97
98 pub fn local_offset(mut self, local_offset: i32) -> Self {
99 self.local_offset = local_offset;
100 self
101 }
102
103 pub fn finish(self) -> SealOptions {
104 SealOptions {
105 encryption: self.encryption,
106 integrity: self.integrity,
107 ttl: self.ttl,
108 timestamp_skew: self.timestamp_skew,
109 local_offset: self.local_offset,
110 }
111 }
112}