1use oca_bundle::state::oca_bundle::OCABundleModel;
2
3struct OCABundleDTO {
4 bundle: OCABundleModel,
5}
6
7#[allow(dead_code)]
8impl OCABundleDTO {
9 fn new(bundle: OCABundleModel) -> Self {
10 Self { bundle }
11 }
12}
13
14impl From<OCABundleDTO> for Vec<u8> {
15 fn from(val: OCABundleDTO) -> Self {
16 let mut digests: Vec<u8> = Vec::new();
17 if let Some(ref said) = val.bundle.capture_base.digest {
18 digests.push(said.to_string().len().try_into().unwrap());
19 digests.extend(said.to_string().as_bytes());
20 }
21
22 val.bundle.overlays.iter().for_each(|overlay| {
23 if let Some(ref said) = overlay.digest {
24 digests.push(said.to_string().len().try_into().unwrap());
25 digests.extend(said.to_string().as_bytes());
27 }
28 });
29
30 digests
31 }
32}
33
34#[cfg(test)]
35mod tests {
36 use overlay_file::overlay_registry::OverlayLocalRegistry;
37
38 use super::*;
39
40 #[test]
41 #[ignore]
42 fn test_to_digests() {
43 let oca_str = r#"
45{
46 "v": "OCAS02JSON0007c1_",
47 "digest": "EDTaoqiaaL50dP-HTxYWuiniwhrzGcP9ji-mPeJgudLk",
48 "capture_base": {
49 "digest": "EA0l-Sazi2X9cLn2pbVLr6C-t4-lVsSx3E_yJyEwTwum",
50 "type": "capture_base/2.0.0",
51 "attributes": {
52 "d": "Text",
53 "el": "Text",
54 "i": "Text",
55 "list": [
56 "Text"
57 ],
58 "passed": "Boolean"
59 }
60 },
61 "overlays": [
62 {
63 "digest": "EKN9PGIHxLuZe92ZDyrZulScFgTfAdjEc9xXEVb_WULX",
64 "capture_base": "EA0l-Sazi2X9cLn2pbVLr6C-t4-lVsSx3E_yJyEwTwum",
65 "type": "Meta/2.0.0",
66 "description": "Entrance credential",
67 "name": "Entrance credential"
68 },
69 {
70 "digest": "EFOAxxDMSnOiuah9OwoCdwkns8EfsurcHXF57-XdGnen",
71 "capture_base": "EA0l-Sazi2X9cLn2pbVLr6C-t4-lVsSx3E_yJyEwTwum",
72 "type": "Character_Encoding/2.0.0",
73 "d": "utf-8",
74 "i": "utf-8",
75 "passed": "utf-8"
76 },
77 {
78 "digest": "ELivUa6QlCOpidnqLDs9Il1uqILb9pBUj2rLdGgqWDwv",
79 "capture_base": "EA0l-Sazi2X9cLn2pbVLr6C-t4-lVsSx3E_yJyEwTwum",
80 "type": "conformance/2.0.0",
81 "d": "M",
82 "i": "M",
83 "passed": "M"
84 },
85 {
86 "digest": "ECsW-Zb7A0TfG_M_HNH9wwKqil3rSiyKEfPE4398aQdC",
87 "capture_base": "EA0l-Sazi2X9cLn2pbVLr6C-t4-lVsSx3E_yJyEwTwum",
88 "type": "label/2.0.0",
89 "d": "Schema digest",
90 "i": "Credential Issuee",
91 "passed": "Passed"
92 },
93 {
94 "digest": "EJcEfNE3s_lZeUF1C_tez3qbThSsIJq4qV6WHlo-hmIL",
95 "capture_base": "EA0l-Sazi2X9cLn2pbVLr6C-t4-lVsSx3E_yJyEwTwum",
96 "type": "format/2.0.0",
97 "d": "image/jpeg"
98 },
99 {
100 "digest": "EICOF_bxwUyKC7W-blp51-YPPieJxqDPL7wrSkeT8jOg",
101 "capture_base": "EA0l-Sazi2X9cLn2pbVLr6C-t4-lVsSx3E_yJyEwTwum",
102 "type": "unit/2.0.0",
103 "i": "m"
104 },
105 {
106 "digest": "EPT1EDp2ofO1xJSQFehyZb8kCfMqXV8giTs0MeqQOp2a",
107 "capture_base": "EA0l-Sazi2X9cLn2pbVLr6C-t4-lVsSx3E_yJyEwTwum",
108 "type": "cardinality/2.0.0",
109 "list": "1-2"
110 },
111 {
112 "digest": "EKJ1z6PIFXqfP7wy6Hj21Of23HcoiT-b5P1qs_DgYJHo",
113 "capture_base": "EA0l-Sazi2X9cLn2pbVLr6C-t4-lVsSx3E_yJyEwTwum",
114 "type": "ENTRY_CODE/2.0.0",
115 "el": [
116 "o1",
117 "o2",
118 "o3"
119 ],
120 "list": "entry_code_said"
121 },
122 {
123 "digest": "EKohdNuyxHWPZ1dy-Om5Rx4RxufHM5jjDKBa3jyRvp52",
124 "capture_base": "EA0l-Sazi2X9cLn2pbVLr6C-t4-lVsSx3E_yJyEwTwum",
125 "type": "ENTRY/2.0.0",
126 "el": {
127 "o1": "o1_label",
128 "o2": "o2_label",
129 "o3": "o3_label"
130 },
131 "list": "refs:ENrf7niTCnz7HD-Ci88rlxHlxkpQ2NIZNNv08fQnXANI"
132 }
133 ]
134}
135"#;
136 let registry = OverlayLocalRegistry::from_dir("../overlay-file/core_overlays/").unwrap();
137 let oca = oca_bundle::controller::load_oca(&mut oca_str.as_bytes(), ®istry).unwrap();
138 let digests: Vec<u8> = OCABundleDTO::new(oca).into();
139 assert_eq!(
140 digests,
141 vec![
142 44, 69, 73, 74, 71, 74, 109, 83, 95, 80, 57, 106, 119, 90, 68, 97, 109, 66, 54, 99,
143 84, 71, 57, 77, 111, 88, 75, 82, 117, 50, 49, 109, 121, 106, 88, 115, 77, 105, 55,
144 71, 89, 100, 100, 68, 121
145 ]
146 )
147 }
148}