Skip to content

Commit 9134a28

Browse files
fixup! Add policy parsing
1 parent 91d9cc1 commit 9134a28

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/policy/parsing.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ macro_rules! bail {
2020
type Result<T> = std::result::Result<T, ParsePolicyError>;
2121

2222
impl Policy {
23+
/// Parse a policy from its string representation according to the
24+
/// [sigsum-go spec](https://git.glasklar.is/sigsum/core/sigsum-go/-/blob/main/doc/policy.md).
2325
pub fn parse(data: &str) -> Result<Policy> {
2426
parse_policy(data)
2527
}
@@ -85,7 +87,8 @@ fn parse_policy(data: &str) -> Result<Policy> {
8587
}
8688
}
8789
["quorum", ..] => bail!(lineno, "invalid quorum rule: expected exactly one argument"),
88-
_ => todo!(),
90+
[unknown, ..] => bail!(lineno, "unknown keyword `{unknown}`"),
91+
[] => unreachable!("PolicyLines skips empty lines"),
8992
}
9093
}
9194
Ok(builder.build())
@@ -357,4 +360,9 @@ mod tests {
357360
@"line 4: invalid quorum rule: quorum already set",
358361
);
359362
}
363+
364+
#[test]
365+
fn parse_policy_unknown_keyword() {
366+
insta::assert_snapshot!(parse_policy("foo bar").unwrap_err(), @"line 1: unknown keyword `foo`")
367+
}
360368
}

0 commit comments

Comments
 (0)