From 3e34190eded3a1493209ab84cf3a19eef925ae90 Mon Sep 17 00:00:00 2001 From: bad Date: Fri, 19 Aug 2022 13:47:32 +0200 Subject: [PATCH 1/3] Fix the sig parsing in narinfo parsing code Unlike references, multiple signatures are stored as separate key-value pairs. Previously this crate assumed that narinfo sigs were stored as a single key, separated by spaces. --- src/narinfo/from_str.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/narinfo/from_str.rs b/src/narinfo/from_str.rs index c7ebc5f..980d7ca 100644 --- a/src/narinfo/from_str.rs +++ b/src/narinfo/from_str.rs @@ -23,6 +23,8 @@ impl<'a> NarInfo<'a> { /// ``` pub fn parse(value: &'a str) -> ParsingResult { let mut builder = NarInfoBuilder::default(); + let mut sigs = Vec::new(); + for line in value.lines() { let (key, value) = line .split_once(':') @@ -46,20 +48,15 @@ impl<'a> NarInfo<'a> { "Deriver" => builder.deriver(Some(Cow::from(value))), "System" => builder.system(Some(Cow::from(value))), "References" => builder.references(value.split(' ').map(Cow::from).collect()), - // TODO: replace with try_collect once that gets stabilized - "Sig" => builder.sigs(value.split(' ').map(Sig::try_from).try_fold( - Vec::new(), - |mut a, c| { - c.map(|c| { - a.push(c); - a - }) - }, - )?), + "Sig" => { + sigs.push(Sig::try_from(value)?); + &mut builder + }, _ => return Err(ParsingError::UnknownKey { key }), }; } + builder.sigs(sigs); builder.build() } } -- 2.45.2 From b5156b645f46f695a73e92fc1b4679b35b3e335a Mon Sep 17 00:00:00 2001 From: bad Date: Fri, 19 Aug 2022 15:53:40 +0200 Subject: [PATCH 2/3] Fix signature serialization --- src/narinfo/to_str.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/narinfo/to_str.rs b/src/narinfo/to_str.rs index edea976..70a1ba6 100644 --- a/src/narinfo/to_str.rs +++ b/src/narinfo/to_str.rs @@ -17,8 +17,8 @@ impl<'a> NarInfo<'a> { write!(w, "\nNarSize: {}", self.nar_size)?; write!(w, "\nReferences: {}", self.references.join(" "))?; - write!(w, "\nSig: ")?; for sig in self.sigs.iter() { + write!(w, "\nSig: ")?; sig.serialize_into(w)?; } -- 2.45.2 From 6bed1a222e20d33d5d97ad30d82034a5758c268a Mon Sep 17 00:00:00 2001 From: bad Date: Fri, 19 Aug 2022 15:55:03 +0200 Subject: [PATCH 3/3] Update tests to include multiple signatures --- sample.narinfo | 1 + src/narinfo/from_str.rs | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/sample.narinfo b/sample.narinfo index b7c0044..8f88702 100644 --- a/sample.narinfo +++ b/sample.narinfo @@ -8,3 +8,4 @@ NarSize: 11374872 References: mhhlymrg2m70r8h94cwhv2d7a0c8l7g6-glibc-2.34-210 ppn8983d9b5r6k7mnhkbg6rqw7vgl1ij-libyaml-0.2.5 qm2lv1gpbyn0rsfai40cbvj3h4gz69yc-bash-5.1-p16 sn0w3f12547crckss4ybmnxmi29gpgq7-perl-5.34.1 zzxrhj9056vjlanfjkinvhd7458yc2z8-liblouis-3.22.0 Deriver: dlxmsgfc0am35fh0kiy88zqr91x2dn5j-liblouis-3.22.0.drv Sig: cache.nixos.org-1:BJ5QGcOta2s76XC6sep9DbAv0x3TILh3hHSKyR+9rFWYuBDTWdHs1KHeUEpw2espE/zPPBp2yURO6/J4Dhf9DQ== +Sig: fake-test-sig-1:BJ5QGcOta2s76XC6sep9DbAv0x3TILh3hHSKyR+9rFWYuBDTWdHs1KHeUEpw2espE/zPPBp2yURO6/J4Dhf9DQ== diff --git a/src/narinfo/from_str.rs b/src/narinfo/from_str.rs index 980d7ca..b1932ab 100644 --- a/src/narinfo/from_str.rs +++ b/src/narinfo/from_str.rs @@ -121,6 +121,10 @@ mod tests { assert_eq!(sig.key_name, "cache.nixos.org-1"); assert_eq!(sig.sig, "BJ5QGcOta2s76XC6sep9DbAv0x3TILh3hHSKyR+9rFWYuBDTWdHs1KHeUEpw2espE/zPPBp2yURO6/J4Dhf9DQ=="); - assert!(info.sigs.len() == 1); + let sig = &info.sigs[1]; + assert_eq!(sig.key_name, "fake-test-sig-1"); + assert_eq!(sig.sig, "BJ5QGcOta2s76XC6sep9DbAv0x3TILh3hHSKyR+9rFWYuBDTWdHs1KHeUEpw2espE/zPPBp2yURO6/J4Dhf9DQ=="); + + assert!(info.sigs.len() == 2); } } -- 2.45.2