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.
This commit is contained in:
bad 2022-08-19 13:47:32 +02:00
parent 3b8681360f
commit 3e34190ede

View file

@ -23,6 +23,8 @@ impl<'a> NarInfo<'a> {
/// ```
pub fn parse(value: &'a str) -> ParsingResult<Self> {
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()
}
}