Struct oca_rust::state::oca::OCABuilder
source · pub struct OCABuilder {
pub oca: OCA,
pub meta_translations: HashMap<Language, OCATranslation>,
pub form_layout: Option<String>,
pub default_form_layout: bool,
pub form_layout_reference: BTreeMap<String, String>,
pub credential_layout: Option<String>,
pub default_credential_layout: bool,
pub credential_layout_reference: BTreeMap<String, String>,
/* private fields */
}
Fields§
§oca: OCA
§meta_translations: HashMap<Language, OCATranslation>
§form_layout: Option<String>
§default_form_layout: bool
§form_layout_reference: BTreeMap<String, String>
§credential_layout: Option<String>
§default_credential_layout: bool
§credential_layout_reference: BTreeMap<String, String>
Implementations§
source§impl OCABuilder
impl OCABuilder
pub fn new(default_encoding: Encoding) -> OCABuilder
pub fn add_classification(self, classification: String) -> OCABuilder
pub fn add_form_layout(self, layout: String) -> OCABuilder
pub fn add_default_form_layout(self) -> OCABuilder
pub fn add_credential_layout(self, layout: String) -> OCABuilder
pub fn add_default_credential_layout(self) -> OCABuilder
pub fn add_name(self, names: HashMap<Language, String>) -> OCABuilder
pub fn add_description(
self,
descriptions: HashMap<Language, String>
) -> OCABuilder
pub fn add_attribute(self, attr: Attribute) -> OCABuilder
pub fn finalize(self) -> OCA
sourcepub fn build_default_form_layout(&self) -> String
pub fn build_default_form_layout(&self) -> String
Examples found in repository?
src/state/oca.rs (line 715)
703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780
pub fn finalize(mut self) -> OCA {
for (lang, translation) in self.meta_translations.iter() {
self.oca
.overlays
.push(overlay::Meta::new(lang.to_string(), translation));
}
let mut form_layout_tmp = None;
if let Some(ref layout) = self.form_layout {
if !layout.is_empty() {
form_layout_tmp = Some(layout.clone());
}
} else if self.default_form_layout {
form_layout_tmp = Some(self.build_default_form_layout());
}
if let Some(mut layout) = form_layout_tmp {
for (i, (name, ref_layout)) in self.form_layout_reference.iter().enumerate() {
if i == 0 {
layout.push_str(
r#"
reference_layouts:"#,
);
}
layout.push_str(
format!(
r#"
{}:
{}"#,
name,
ref_layout.replace('\n', "\n ")
)
.as_str(),
);
}
self.oca.overlays.push(overlay::FormLayout::new(layout));
}
let mut credential_layout_tmp = None;
if let Some(ref layout) = self.credential_layout {
if !layout.is_empty() {
credential_layout_tmp = Some(layout.clone());
}
} else if self.default_credential_layout {
credential_layout_tmp = Some(self.build_default_credential_layout());
}
if let Some(mut layout) = credential_layout_tmp {
for (i, (name, ref_layout)) in self.credential_layout_reference.iter().enumerate() {
if i == 0 {
layout.push_str(
r#"
reference_layouts:"#,
);
}
layout.push_str(
format!(
r#"
{}:
{}"#,
name,
ref_layout.replace('\n', "\n ")
)
.as_str(),
);
}
self.oca
.overlays
.push(overlay::CredentialLayout::new(layout));
}
let cs_json = serde_json::to_string(&self.oca.capture_base).unwrap();
let sai = format!("{}", SelfAddressing::Blake3_256.derive(cs_json.as_bytes()));
for o in self.oca.overlays.iter_mut() {
o.sign(&sai);
}
self.oca
}
pub fn add_form_layout_reference(&mut self, name: String, layout: String)
sourcepub fn build_default_credential_layout(&self) -> String
pub fn build_default_credential_layout(&self) -> String
Examples found in repository?
src/state/oca.rs (line 746)
703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780
pub fn finalize(mut self) -> OCA {
for (lang, translation) in self.meta_translations.iter() {
self.oca
.overlays
.push(overlay::Meta::new(lang.to_string(), translation));
}
let mut form_layout_tmp = None;
if let Some(ref layout) = self.form_layout {
if !layout.is_empty() {
form_layout_tmp = Some(layout.clone());
}
} else if self.default_form_layout {
form_layout_tmp = Some(self.build_default_form_layout());
}
if let Some(mut layout) = form_layout_tmp {
for (i, (name, ref_layout)) in self.form_layout_reference.iter().enumerate() {
if i == 0 {
layout.push_str(
r#"
reference_layouts:"#,
);
}
layout.push_str(
format!(
r#"
{}:
{}"#,
name,
ref_layout.replace('\n', "\n ")
)
.as_str(),
);
}
self.oca.overlays.push(overlay::FormLayout::new(layout));
}
let mut credential_layout_tmp = None;
if let Some(ref layout) = self.credential_layout {
if !layout.is_empty() {
credential_layout_tmp = Some(layout.clone());
}
} else if self.default_credential_layout {
credential_layout_tmp = Some(self.build_default_credential_layout());
}
if let Some(mut layout) = credential_layout_tmp {
for (i, (name, ref_layout)) in self.credential_layout_reference.iter().enumerate() {
if i == 0 {
layout.push_str(
r#"
reference_layouts:"#,
);
}
layout.push_str(
format!(
r#"
{}:
{}"#,
name,
ref_layout.replace('\n', "\n ")
)
.as_str(),
);
}
self.oca
.overlays
.push(overlay::CredentialLayout::new(layout));
}
let cs_json = serde_json::to_string(&self.oca.capture_base).unwrap();
let sai = format!("{}", SelfAddressing::Blake3_256.derive(cs_json.as_bytes()));
for o in self.oca.overlays.iter_mut() {
o.sign(&sai);
}
self.oca
}
pub fn add_credential_layout_reference(&mut self, name: String, layout: String)
Trait Implementations§
source§impl<'de> Deserialize<'de> for OCABuilder
impl<'de> Deserialize<'de> for OCABuilder
source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more