|
@@ -1,6 +1,7 @@
|
|
|
use std::collections::HashMap;
|
|
|
use ring::signature::Ed25519KeyPair;
|
|
|
use sha2::Digest;
|
|
|
+use crate::schema;
|
|
|
|
|
|
pub struct CertStore<'a> {
|
|
|
db: &'a crate::DB,
|
|
@@ -12,8 +13,8 @@ impl<'a> CertStore<'a> {
|
|
|
Self { db, keys: HashMap::new() }
|
|
|
}
|
|
|
|
|
|
- fn realm_id(&self, realm_name: &str) -> Option<microrm::query::ID> {
|
|
|
- microrm::query::get_one_by(self.db, crate::schema::RealmColumns::Shortname, realm_name).map(|x| x.id())
|
|
|
+ fn realm_id(&self, realm_name: &str) -> Option<schema::RealmID> {
|
|
|
+ microrm::query::get_one_by(self.db, schema::RealmColumns::Shortname, realm_name).map(|x| x.id())
|
|
|
}
|
|
|
|
|
|
pub fn generate_in(&self, realm_name: &str) -> Result<String, &'static str> {
|
|
@@ -22,7 +23,7 @@ impl<'a> CertStore<'a> {
|
|
|
|
|
|
let realm_id = self.realm_id(realm_name).ok_or("Failed to find realm")?;
|
|
|
|
|
|
- if let Err(e) = sign_generated {
|
|
|
+ if let Err(_) = sign_generated {
|
|
|
return Err("Failed to generate key")
|
|
|
}
|
|
|
let sign_generated = sign_generated.unwrap();
|
|
@@ -34,7 +35,7 @@ impl<'a> CertStore<'a> {
|
|
|
let mut key_id = base64::encode(key_hasher.finalize());
|
|
|
key_id.truncate(16);
|
|
|
|
|
|
- microrm::query::add(self.db, &crate::schema::Key { realm: realm_id, key_id: key_id.clone(), keydata }).expect("Couldn't add key");
|
|
|
+ microrm::query::add(self.db, &schema::Key { realm: realm_id, key_id: key_id.clone(), keydata }).expect("Couldn't add key");
|
|
|
|
|
|
Ok(key_id)
|
|
|
}
|
|
@@ -43,7 +44,7 @@ impl<'a> CertStore<'a> {
|
|
|
pub fn inspect(db: &crate::DB, realm_name: &str) {
|
|
|
let cs = CertStore::new(db);
|
|
|
println!("Certstore loaded.");
|
|
|
- let realm = microrm::query::get_one_by(db, crate::schema::RealmColumns::Shortname, realm_name);
|
|
|
+ let realm = microrm::query::get_one_by(db, schema::RealmColumns::Shortname, realm_name);
|
|
|
if realm.is_none() {
|
|
|
println!("No such realm {}", realm_name);
|
|
|
return
|
|
@@ -51,7 +52,7 @@ pub fn inspect(db: &crate::DB, realm_name: &str) {
|
|
|
let realm = realm.unwrap();
|
|
|
|
|
|
println!("Retrieving keys for {} realm...", realm_name);
|
|
|
- let keys = microrm::query::get_all_by(db, crate::schema::KeyColumns::Realm, realm.id()).expect("Can get keys");
|
|
|
+ let keys = microrm::query::get_all_by(db, schema::KeyColumns::Realm, realm.id()).expect("Can get keys");
|
|
|
for key in keys {
|
|
|
println!("[{:20}]", key.key_id);
|
|
|
}
|