oca_bundle/state/oca/overlay/
credential_layout.rs1use crate::state::oca::OCABox;
2use crate::state::{attribute::Attribute, oca::layout::credential::Layout, oca::Overlay};
3use oca_ast::ast::OverlayType;
4use said::{sad::SerializationFormats, sad::SAD};
5use serde::{Deserialize, Serialize};
6use std::any::Any;
7
8pub trait CredentialLayouts {
9 fn add_credential_layout(&mut self, layout_str: String);
10}
11
12impl CredentialLayouts for OCABox {
13 fn add_credential_layout(&mut self, layout_str: String) {
14 let yaml: Result<Layout, _> = serde_yaml::from_str(&layout_str);
15 match yaml {
16 Ok(layout) => {
17 if let Some(layouts) = self.credential_layouts.as_mut() {
18 layouts.push(layout);
19 } else {
20 self.credential_layouts = Some(vec![layout]);
21 }
22 }
23 Err(e) => panic!("{:#?}", e),
24 }
25 }
26}
27
28#[derive(SAD, Serialize, Deserialize, Clone, Debug)]
29pub struct CredentialLayoutOverlay {
30 #[said]
31 #[serde(rename = "d")]
32 said: Option<said::SelfAddressingIdentifier>,
33 #[serde(rename = "type")]
34 overlay_type: OverlayType,
35 capture_base: Option<said::SelfAddressingIdentifier>,
36 pub layout: Layout,
37}
38
39impl Overlay for CredentialLayoutOverlay {
40 fn as_any(&self) -> &dyn Any {
41 self
42 }
43 fn capture_base(&self) -> &Option<said::SelfAddressingIdentifier> {
44 &self.capture_base
45 }
46 fn set_capture_base(&mut self, said: &said::SelfAddressingIdentifier) {
47 self.capture_base = Some(said.clone());
48 }
49 fn said(&self) -> &Option<said::SelfAddressingIdentifier> {
50 &self.said
51 }
52 fn overlay_type(&self) -> &OverlayType {
53 &self.overlay_type
54 }
55 fn attributes(&self) -> Vec<&String> {
56 vec![]
57 }
58
59 fn add(&mut self, _attribute: &Attribute) {}
60}
61
62impl CredentialLayoutOverlay {
63 pub fn new(layout: Layout) -> Self {
64 Self {
65 capture_base: None,
66 said: None,
67 overlay_type: OverlayType::Layout,
68 layout,
69 }
70 }
71}