parse config file

This commit is contained in:
nora 2024-08-26 22:34:26 +02:00
parent 187478464c
commit 13c49524ba
8 changed files with 314 additions and 107 deletions

View file

@ -0,0 +1,43 @@
use std::collections::HashSet;
use thiserror::Error;
use crate::private::PlaintextPrivateKey;
/// A set of host keys, ensuring there are no duplicated algorithms.
#[derive(Debug, Default)]
pub struct HostKeySet {
algs: HashSet<&'static str>,
keys: Vec<PlaintextPrivateKey>,
}
impl HostKeySet {
pub fn new() -> Self {
Self::default()
}
pub fn into_keys(self) -> Vec<PlaintextPrivateKey> {
self.keys
}
pub fn insert(&mut self, key: PlaintextPrivateKey) -> Result<(), DuplicateHostKeyAlgorithm> {
let alg = key.private_key.algorithm_name();
let newly_inserted = self.algs.insert(alg);
if !newly_inserted {
return Err(DuplicateHostKeyAlgorithm { alg });
}
self.keys.push(key);
Ok(())
}
}
#[derive(Debug, Error)]
#[error("another host key with algorithm {alg} has already been loaded")]
pub struct DuplicateHostKeyAlgorithm {
alg: &'static str,
}
// TODO: write tests

View file

@ -1,5 +1,6 @@
pub mod authorized_keys;
mod crypto;
pub mod host_keys;
pub mod private;
pub mod public;
pub mod signature;