feat(nix-compat/narinfo/signature): add new() constructor

This is useful when creating a new Signature struct where the individual
elements are already parsed.

Change-Id: Ie33c66287641951e7a030aaa1e7ff0a86b2628ac
Reviewed-on: https://cl.tvl.fyi/c/depot/+/10111
Reviewed-by: edef <edef@edef.eu>
Autosubmit: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
This commit is contained in:
Florian Klink 2023-11-22 21:47:28 +02:00 committed by flokli
parent c44cbc852a
commit 639cca3e22

View file

@ -4,11 +4,16 @@ use data_encoding::BASE64;
#[derive(Debug)]
pub struct Signature<'a> {
/// TODO(edef): be stricter with signature names here, they especially shouldn't have newlines!
name: &'a str,
bytes: [u8; 64],
}
impl<'a> Signature<'a> {
pub fn new(name: &'a str, bytes: [u8; 64]) -> Self {
Self { name, bytes }
}
pub fn parse(input: &'a str) -> Result<Signature<'a>, SignatureError> {
let (name, bytes64) = input
.split_once(':')