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
use ethereum_types::H512;
use v1::types::Bytes;
#[derive(Default, Debug, Serialize, PartialEq)]
#[cfg_attr(test, derive(Deserialize))]
pub struct EncryptedDocumentKey {
pub common_point: H512,
pub encrypted_point: H512,
pub encrypted_key: Bytes,
}
#[cfg(test)]
mod tests {
use super::EncryptedDocumentKey;
use ethereum_types::H512;
use serde_json;
#[test]
fn test_serialize_encrypted_document_key() {
let initial = EncryptedDocumentKey {
common_point: H512::from_low_u64_be(1),
encrypted_point: H512::from_low_u64_be(2),
encrypted_key: vec![3].into(),
};
let serialized = serde_json::to_string(&initial).unwrap();
assert_eq!(
serialized,
r#"{"common_point":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001","encrypted_point":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002","encrypted_key":"0x03"}"#
);
let deserialized: EncryptedDocumentKey = serde_json::from_str(&serialized).unwrap();
assert_eq!(deserialized.common_point, H512::from_low_u64_be(1));
assert_eq!(deserialized.encrypted_point, H512::from_low_u64_be(2));
assert_eq!(deserialized.encrypted_key, vec![3].into());
}
}