diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2024-04-17 17:53:34 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2024-04-17 18:03:44 +0200 |
commit | 145e08d6dcf7c4baae60b844a886598f4bb4ee5a (patch) | |
tree | 371bcd328c2d6bff76834eb423e14bb058d62a6c /openpgp | |
parent | c1d016abf9863d48c84ecde477520f1237e1a6eb (diff) |
openpgp: Introduce a constructor for ComponentBundle.
Diffstat (limited to 'openpgp')
-rw-r--r-- | openpgp/src/cert/bundle.rs | 21 | ||||
-rw-r--r-- | openpgp/src/cert/parser/low_level/grammar.lalrpop | 90 |
2 files changed, 39 insertions, 72 deletions
diff --git a/openpgp/src/cert/bundle.rs b/openpgp/src/cert/bundle.rs index 077dfdc0..c5d7ab5b 100644 --- a/openpgp/src/cert/bundle.rs +++ b/openpgp/src/cert/bundle.rs @@ -179,6 +179,27 @@ impl<C> Deref for ComponentBundle<C> } impl<C> ComponentBundle<C> { + /// Creates a new component. + /// + /// Should only be used from the cert parser. However, we cannot + /// use `pub(in ...)` because the cert parser isn't an ancestor of + /// this module. + pub(crate) fn new(component: C, + hash_algo_security: HashAlgoSecurity, + sigs: Vec<Signature>) + -> ComponentBundle<C> + { + ComponentBundle { + component, + hash_algo_security, + self_signatures: vec![], + certifications: sigs, + attestations: vec![], + self_revocations: vec![], + other_revocations: vec![], + } + } + /// Returns a reference to the bundle's component. /// /// # Examples diff --git a/openpgp/src/cert/parser/low_level/grammar.lalrpop b/openpgp/src/cert/parser/low_level/grammar.lalrpop index f1bf420e..d566d420 100644 --- a/openpgp/src/cert/parser/low_level/grammar.lalrpop +++ b/openpgp/src/cert/parser/low_level/grammar.lalrpop @@ -52,15 +52,7 @@ pub Cert: Option<Cert> = { let sec = key.hash_algo_security(); let mut cert = Cert { - primary: PrimaryKeyBundle { - component: key, - hash_algo_security: sec, - self_signatures: vec![], - certifications: sigs, - attestations: vec![], - self_revocations: vec![], - other_revocations: vec![], - }, + primary: PrimaryKeyBundle::new(key, sec, sigs), subkeys: ComponentBundles::default(), userids: ComponentBundles::default(), user_attributes: ComponentBundles::default(), @@ -184,25 +176,12 @@ Component: Option<Component> = { let sigs = sigs.unwrap(); let sec = key.hash_algo_security(); - Some(Component::SubkeyBundle(SubkeyBundle { - component: key, - hash_algo_security: sec, - self_signatures: vec![], - certifications: sigs, - attestations: vec![], - self_revocations: vec![], - other_revocations: vec![], - })) + Some(Component::SubkeyBundle( + SubkeyBundle::new(key, sec, sigs))) }, - Some(Err(u)) => Some(Component::UnknownBundle(UnknownBundle { - component: u, - hash_algo_security: SecondPreImageResistance, - self_signatures: vec![], - certifications: sigs.unwrap_or_default(), - attestations: vec![], - self_revocations: vec![], - other_revocations: vec![], - })), + Some(Err(u)) => Some(Component::UnknownBundle( + UnknownBundle::new(u, SecondPreImageResistance, + sigs.unwrap_or_default()))), // Just validating a cert... None => None, } @@ -213,25 +192,12 @@ Component: Option<Component> = { let sigs = sigs.unwrap(); let sec = u.hash_algo_security(); - Some(Component::UserIDBundle(UserIDBundle { - component: u, - hash_algo_security: sec, - self_signatures: vec![], - certifications: sigs, - attestations: vec![], - self_revocations: vec![], - other_revocations: vec![], - })) + Some(Component::UserIDBundle( + UserIDBundle::new(u, sec, sigs))) }, - Some(Err(u)) => Some(Component::UnknownBundle(UnknownBundle { - component: u, - hash_algo_security: SecondPreImageResistance, - self_signatures: vec![], - certifications: sigs.unwrap_or_default(), - attestations: vec![], - self_revocations: vec![], - other_revocations: vec![], - })), + Some(Err(u)) => Some(Component::UnknownBundle( + UnknownBundle::new(u, SecondPreImageResistance, + sigs.unwrap_or_default()))), // Just validating a cert... None => None, } @@ -242,25 +208,12 @@ Component: Option<Component> = { let sigs = sigs.unwrap(); let sec = u.hash_algo_security(); - Some(Component::UserAttributeBundle(UserAttributeBundle { - component: u, - hash_algo_security: sec, - self_signatures: vec![], - certifications: sigs, - attestations: vec![], - self_revocations: vec![], - other_revocations: vec![], - })) + Some(Component::UserAttributeBundle( + UserAttributeBundle::new(u, sec, sigs))) }, - Some(Err(u)) => Some(Component::UnknownBundle(UnknownBundle { - component: u, - hash_algo_security: SecondPreImageResistance, - self_signatures: vec![], - certifications: sigs.unwrap_or_default(), - attestations: vec![], - self_revocations: vec![], - other_revocations: vec![], - })), + Some(Err(u)) => Some(Component::UnknownBundle( + UnknownBundle::new(u, SecondPreImageResistance, + sigs.unwrap_or_default()))), // Just validating a cert... None => None, } @@ -271,15 +224,8 @@ Component: Option<Component> = { let sigs = sigs.unwrap(); let sec = u.hash_algo_security(); - Some(Component::UnknownBundle(UnknownBundle { - component: u, - hash_algo_security: sec, - self_signatures: vec![], - certifications: sigs, - attestations: vec![], - self_revocations: vec![], - other_revocations: vec![], - })) + Some(Component::UnknownBundle( + UnknownBundle::new(u, sec, sigs))) }, // Just validating a cert... None => None, |