Skip to content

Commit

Permalink
Vical builder WIP: extensions convenience improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-pronin committed Dec 17, 2024
1 parent 95a7cef commit 4273e75
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ use crate::definitions::traits::ToCbor;
#[isomdl(crate = "crate")]
pub struct Extensions(BTreeMap<String, ByteStr>);

impl Extensions {
pub fn new(extensions: BTreeMap<String, ByteStr>) -> Self {
Self(extensions)
}
}
impl From<Extensions> for ciborium::Value {
fn from(extensions: Extensions) -> ciborium::Value {
ciborium::Value::Map(extensions.0.into_iter().map(|(k, v)| (k.to_cbor(), v.to_cbor())).collect())
Expand Down
16 changes: 11 additions & 5 deletions src/definitions/namespaces/org_iso_18013_5_1_vical/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ mod certificate_profile;
mod doc_type;
mod vical_cose_sign1;

use std::collections::BTreeMap;
use std::str::FromStr;
pub use certificate_info::{CertificateInfos, CertificateInfo};
pub use extension::Extensions;
use crate::definitions::helpers::ByteStr;
pub use super::latin1::Latin1;
pub use super::org_iso_18013_5_1::TDate;
use crate::macros::{FromJson, ToCbor};
Expand Down Expand Up @@ -39,7 +41,7 @@ pub struct VicalBuilder {
certificate_infos: Vec<CertificateInfo>,
vical_issue_id: Option<u32>,
next_update: Option<String>,
extensions: Option<Extensions>,
extensions: Option<BTreeMap<String, ByteStr>>,
}

impl VicalBuilder {
Expand All @@ -66,8 +68,8 @@ impl VicalBuilder {
self.certificate_infos = certificate_infos;
self
}
pub fn extensions(mut self, extensions: Option<Extensions>) -> Self {
self.extensions = extensions;
pub fn extensions(mut self, extensions: BTreeMap<String, ByteStr>) -> Self {
self.extensions = Some(extensions);
self
}
pub fn build(self) -> OrgIso1901351Vical {
Expand All @@ -77,10 +79,14 @@ impl VicalBuilder {
date: TDate::from_str(self.date.as_str()).unwrap(),
vical_issue_id: self.vical_issue_id,
certificate_infos: CertificateInfos::new(self.certificate_infos),
extensions: self.extensions,
extensions: match self.extensions {
Some(s) => Some(Extensions::new(s)),
None => None,
},
next_update: match self.next_update {
Some(s) => Some(TDate::from_str(s.as_str()).unwrap()),
None => None,},
None => None,
},
}
}
}
Expand Down

0 comments on commit 4273e75

Please sign in to comment.