diff options
author | Neal H. Walfield <neal@pep.foundation> | 2022-12-26 17:47:56 +0100 |
---|---|---|
committer | Neal H. Walfield <neal@pep.foundation> | 2023-01-06 13:24:55 +0100 |
commit | f8bc3c86f3f556b71b64c92fb7a77f84f0882fff (patch) | |
tree | 06992c2b4903342925a676d28557589a365b813e /openpgp/src/cert | |
parent | 3d2edaab351e27267291b3aaa7f2335aaa125ca7 (diff) |
openpgp: KeyringValidator::push should allow unknown packages.
- When pushing a tag using `KeyringValidator::push`, allow
the `Tag::Unknown` and `Tag::Private` variants.
- The grammar already allows them.
Diffstat (limited to 'openpgp/src/cert')
-rw-r--r-- | openpgp/src/cert/parser/mod.rs | 77 |
1 files changed, 75 insertions, 2 deletions
diff --git a/openpgp/src/cert/parser/mod.rs b/openpgp/src/cert/parser/mod.rs index ad092799..fdb959f3 100644 --- a/openpgp/src/cert/parser/mod.rs +++ b/openpgp/src/cert/parser/mod.rs @@ -163,11 +163,13 @@ impl KeyringValidator { // Such a packet MUST be ignored when received. return; }, + Tag::Unknown(_) => Token::Unknown(tag, None), + Tag::Private(_) => Token::Unknown(tag, None), _ => { // Unknown token. self.error = Some(CertParserError::OpenPGP( Error::MalformedMessage( - format!("Invalid Cert: {:?} packet (at {}) not expected", + format!("Invalid Cert: {:?} packet (#{}) not expected", tag, self.n_packets)))); self.tokens.clear(); return; @@ -1057,7 +1059,7 @@ mod test { use crate::tests; #[test] - fn tokens() { + fn push_tokens() { use crate::cert::parser::low_level::lexer::{Token, Lexer}; use crate::cert::parser::low_level::lexer::Token::*; use crate::cert::parser::low_level::CertParser; @@ -1176,6 +1178,15 @@ mod test { ], result: false, }, + TestVector { + s: &[ SecretKey(None), Signature(None), + UserID(None), Signature(None), + SecretSubkey(None), Signature(None), + SecretSubkey(None), Signature(None), + Unknown(Tag::Private(61), None), + ], + result: true, + }, ]; for v in &test_vectors { @@ -1198,6 +1209,68 @@ mod test { } #[test] + fn push_tags() { + use Tag::*; + + struct TestVector<'a> { + s: &'a [Tag], + result: bool, + } + + let test_vectors = [ + TestVector { + s: &[ PublicKey ], + result: true, + }, + TestVector { + s: &[ SecretKey, Signature, + UserID, Signature, + SecretSubkey, Signature, + SecretSubkey, Signature, + Tag::Private(61), + ], + result: true, + }, + TestVector { + s: &[ SecretKey, Signature, + UserID, Signature, + SecretSubkey, Signature, + SecretSubkey, Signature, + Tag::Unknown(61), + ], + result: true, + }, + TestVector { + s: &[ SecretKey, Signature, + UserID, Signature, + SecretSubkey, Signature, + SecretSubkey, Signature, + Tag::Unknown(61), + SecretKey, Signature, + UserID, Signature, + SecretSubkey, Signature, + SecretSubkey, Signature, + ], + // This is a keyring, not a cert. + result: false, + }, + ]; + + for v in &test_vectors { + if v.result { + let mut l = CertValidator::new(); + for &tag in v.s.into_iter() { + l.push(tag.clone()); + assert_match!(CertValidity::CertPrefix = l.check()); + } + + l.finish(); + assert_match!(CertValidity::Cert = l.check()); + } + } + } + + #[test] fn marker_packet_ignored() { use crate::serialize::Serialize; let mut testy_with_marker = Vec::new(); |