mirror of
https://github.com/Noratrieb/cluelessh.git
synced 2026-01-14 16:35:06 +01:00
parse config file
This commit is contained in:
parent
187478464c
commit
13c49524ba
8 changed files with 314 additions and 107 deletions
43
lib/cluelessh-keys/src/host_keys.rs
Normal file
43
lib/cluelessh-keys/src/host_keys.rs
Normal 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
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
pub mod authorized_keys;
|
||||
mod crypto;
|
||||
pub mod host_keys;
|
||||
pub mod private;
|
||||
pub mod public;
|
||||
pub mod signature;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue