1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use crate::TinkError;
#[derive(Default)]
pub struct MemReaderWriter {
pub keyset: Option<tink_proto::Keyset>,
pub encrypted_keyset: Option<tink_proto::EncryptedKeyset>,
}
impl super::Reader for MemReaderWriter {
fn read(&mut self) -> Result<tink_proto::Keyset, TinkError> {
match &self.keyset {
Some(keyset) => Ok(keyset.clone()),
None => Err("no keyset available".into()),
}
}
fn read_encrypted(&mut self) -> Result<tink_proto::EncryptedKeyset, TinkError> {
match &self.encrypted_keyset {
Some(keyset) => Ok(keyset.clone()),
None => Err("no keyset available".into()),
}
}
}
impl super::Writer for MemReaderWriter {
fn write(&mut self, keyset: &tink_proto::Keyset) -> Result<(), TinkError> {
self.keyset = Some(keyset.clone());
Ok(())
}
fn write_encrypted(&mut self, keyset: &tink_proto::EncryptedKeyset) -> Result<(), TinkError> {
self.encrypted_keyset = Some(keyset.clone());
Ok(())
}
}