Unified · Split
| @@ -60,6 +60,7 @@ pub mod parsed { · 59 unmodified lines | |||
| 60 | pub name_raw: &'data [u8], | 60 | pub name_raw: &'data [u8], |
| 61 | pub target_kind: Kind, | 61 | pub target_kind: Kind, |
| 62 | pub message: Option<&'data [u8]>, | 62 | pub message: Option<&'data [u8]>, |
| 63 | pub pgp_signature: Option<&'data [u8]>, | ||
| 63 | pub signature: Signature<'data>, | 64 | pub signature: Signature<'data>, |
| 64 | } | 65 | } |
| 65 | 66 | ||
| @@ -173,29 +174,32 @@ pub mod parsed { · 107 unmodified lines | |||
| 173 | _ => bail!("Expected four lines: target, type, tag and tagger"), | 174 | _ => bail!("Expected four lines: target, type, tag and tagger"), |
| 174 | }; | 175 | }; |
| 175 | 176 | ||
| 176 | let message = match lines.next() { | 177 | let (message, pgp_signature) = match lines.next() { |
| 177 | Some(l) if l.len() == 0 => { | 178 | Some(l) if l.len() == 0 => { |
| 178 | let msg_begin = (l.as_ptr().wrapping_offset_from(d.as_ptr()) + 1) as usize; | 179 | let msg_begin = (l.as_ptr().wrapping_offset_from(d.as_ptr()) + 1) as usize; |
| 179 | if msg_begin >= d.len() { | 180 | if msg_begin >= d.len() { |
| 180 | bail!("Message separator was not followed by message") | 181 | bail!("Message separator was not followed by message") |
| 181 | } | 182 | } |
| 182 | let mut msg_end = d.len(); | 183 | let mut msg_end = d.len(); |
| 183 | if let Some(pgp_begin_line) = lines.find(|l| l.starts_with(PGP_SIGNATURE_BEGIN)) { | 184 | let mut pgp_signature = None; |
| 185 | if let Some(pgp_begin_line) = lines.find(|l| l.starts_with(PGP_SIGNATURE_BEGIN)) | ||
| 186 | { | ||
| 184 | match lines.find(|l| l.starts_with(PGP_SIGNATURE_END)) { | 187 | match lines.find(|l| l.starts_with(PGP_SIGNATURE_END)) { |
| 185 | None => bail!("Didn't find end of signature marker"), | 188 | None => bail!("Didn't find end of signature marker"), |
| 186 | Some(pgp_end_line) => { | 189 | Some(_) => { |
| 187 | msg_end = pgp_begin_line.as_ptr().wrapping_offset_from(d.as_ptr()) | 190 | msg_end = pgp_begin_line.as_ptr().wrapping_offset_from(d.as_ptr()) |
| 188 | as usize; | 191 | as usize; |
| 192 | pgp_signature = Some(&d[msg_end..]) | ||
| 189 | } | 193 | } |
| 190 | } | 194 | } |
| 191 | } | 195 | } |
| 192 | Some(&d[msg_begin..msg_end]) | 196 | (Some(&d[msg_begin..msg_end]), pgp_signature) |
| 193 | } | 197 | } |
| 194 | Some(l) => bail!( | 198 | Some(l) => bail!( |
| 195 | "Expected empty newline to separate message, got {:?}", | 199 | "Expected empty newline to separate message, got {:?}", |
| 196 | str::from_utf8(l), | 200 | str::from_utf8(l), |
| 197 | ), | 201 | ), |
| 198 | None => None, | 202 | None => (None, None), |
| 199 | }; | 203 | }; |
| 200 | 204 | ||
| 201 | Ok(Tag { | 205 | Ok(Tag { |
| @@ -204,6 +208,7 @@ pub mod parsed { · 2 unmodified lines | |||
| 204 | target_kind, | 208 | target_kind, |
| 205 | message, | 209 | message, |
| 206 | signature, | 210 | signature, |
| 211 | pgp_signature, | ||
| 207 | }) | 212 | }) |
| 208 | } | 213 | } |
| 209 | } | 214 | } |
| @@ -29,6 +29,10 @@ fn fixture_bytes(path: &str) -> Vec<u8> { · 28 unmodified lines | |||
| 29 | fn bin(hex: &str) -> [u8; 20] { | 29 | fn bin(hex: &str) -> [u8; 20] { |
| 30 | <[u8; 20]>::from_hex(hex).unwrap() | 30 | <[u8; 20]>::from_hex(hex).unwrap() |
| 31 | } | 31 | } |
| 32 | fn as_str(d: &[u8]) -> &str { | ||
| 33 | ::std::str::from_utf8(d).unwrap() | ||
| 34 | } | ||
| 35 | |||
| 32 | fn ldb() -> Db { | 36 | fn ldb() -> Db { |
| 33 | odb::loose::at(fixture("objects")) | 37 | odb::loose::at(fixture("objects")) |
| 34 | } | 38 | } |
| @@ -64,6 +68,7 @@ fn loose_find() { · 29 unmodified lines | |||
| 64 | fn loose_tag_parse() { | 68 | fn loose_tag_parse() { |
| 65 | let fixture = fixture_bytes("objects/tag.txt"); | 69 | let fixture = fixture_bytes("objects/tag.txt"); |
| 66 | let actual = parsed::Tag::from_bytes(&fixture).unwrap(); | 70 | let actual = parsed::Tag::from_bytes(&fixture).unwrap(); |
| 71 | println!("{}", as_str(actual.pgp_signature.unwrap())); | ||
| 67 | assert_eq!(actual, tag_fixture(9000)); | 72 | assert_eq!(actual, tag_fixture(9000)); |
| 68 | assert_eq!( | 73 | assert_eq!( |
| 69 | actual.target(), | 74 | actual.target(), |
| @@ -78,6 +83,26 @@ fn tag_fixture(offset: i32) -> parsed::Tag<'static> { · 8 unmodified lines | |||
| 78 | name_raw: b"1.0.0", | 83 | name_raw: b"1.0.0", |
| 79 | target_kind: Kind::Commit, | 84 | target_kind: Kind::Commit, |
| 80 | message: Some(b"for the signature\n"), | 85 | message: Some(b"for the signature\n"), |
| 86 | pgp_signature: Some( | ||
| 87 | b"-----BEGIN PGP SIGNATURE----- | ||
| 88 | Comment: GPGTools - https://gpgtools.org | ||
| 89 | |||
| 90 | iQIzBAABCgAdFiEEw7xSvXbiwjusbsBqZl+Z+p2ZlmwFAlsapyYACgkQZl+Z+p2Z | ||
| 91 | lmy6Ug/+KzvzqiNpzz1bMVVAzp8NCbiEO3QGYPyeQc521lBwpaTrRYR+oHJY15r3 | ||
| 92 | OdL5WDysTpjN8N5FNyfmvzkuPdTkK3JlYmO7VRjdA2xu/B6vIZLaOfAowFrhMvKo | ||
| 93 | 8eoqwGcAP3rC5TuWEgzq2qhbjS4JXFLd4NLjWEFqT2Y2UKm+g8TeGOsa/0pF4Nq5 | ||
| 94 | xeW4qCYR0WcQLFedbpkKHxag2GfaXKvzNNJdqYhVQssNa6BeSmsfDvlWYNe617wV | ||
| 95 | NvsR/zJT0wHb5SSH+h6QmwA7LQIQF//83Vc3aF7kv9D54r3ibXW5TjZ3WoeTUZO7 | ||
| 96 | kefkzJ12EYDCFLPhHvXPog518nO8Ot46dX+okrF0/B4N3RFTvjKr7VAGTzv2D/Dg | ||
| 97 | DrD531S2F71b+JIRh641eeP7bjWFQi3tWLtrEOtjjsKPJfYRMKpYFnAO4UUJ6Rck | ||
| 98 | Z5fFXEUCO8d5WT56jzKDjmVoY01lA87O1YsP/J+zQAlc9v1k6jqeQ53LZNgTN+ue | ||
| 99 | 5fJuSPT3T43pSOD1VQSr3aZ2Anc4Qu7K8uX9lkpxF9Sc0tDbeCosFLZMWNVp6m+e | ||
| 100 | cjHJZXWmV4CcRfmLsXzU8s2cR9A0DBvOxhPD1TlKC2JhBFXigjuL9U4Rbq9tdegB | ||
| 101 | 2n8f2douw6624Tn/6Lm4a7AoxmU+CMiYagDxDL3RuZ8CAfh3bn0= | ||
| 102 | =aIns | ||
| 103 | -----END PGP SIGNATURE----- | ||
| 104 | ", | ||
| 105 | ), | ||
| 81 | signature: parsed::Signature { | 106 | signature: parsed::Signature { |
| 82 | name: b"Sebastian Thiel", | 107 | name: b"Sebastian Thiel", |
| 83 | email: b"byronimo@gmail.com", | 108 | email: b"byronimo@gmail.com", |