Changeset View
Changeset View
Standalone View
Standalone View
shared/comm-opaque/src/config.rs
- This file was added.
use curve25519_dalek::ristretto::RistrettoPoint; | |||||
use once_cell::sync::Lazy; | |||||
use opaque_ke::{ | |||||
ciphersuite::CipherSuite, errors::InternalPakeError, keypair::KeyPair, | |||||
}; | |||||
use rand::rngs::OsRng; | |||||
use std::{env, fs, path::Path}; | |||||
use crate::{ | |||||
constants::{SECRETS_DIRECTORY, SECRETS_FILE_EXTENSION, SECRETS_FILE_NAME}, | |||||
Cipher, | |||||
}; | |||||
pub static CONFIG: Lazy<Config> = | |||||
Lazy::new(|| Config::load().expect("failed to load config")); | |||||
#[allow(dead_code)] | |||||
pub(super) fn load_config() { | |||||
varun: this should probably be `pub` not `pub(super)` | |||||
jonAuthorUnsubmitted Done Inline ActionsI will be removing it jon: I will be removing it | |||||
Lazy::force(&CONFIG); | |||||
} | |||||
#[derive(Clone)] | |||||
pub struct Config { | |||||
pub server_keypair: KeyPair<RistrettoPoint>, | |||||
} | |||||
impl Config { | |||||
fn load() -> Result<Self, InternalPakeError> { | |||||
let mut path = env::current_dir().expect("Failed to determine CWD"); | |||||
varunUnsubmitted Done Inline Actionswhy are we panicking here? can we copy what we're doing in identity's config.rs today and have an Error enum that we return here? #[derive( Debug, derive_more::Display, derive_more::From, derive_more::Error, )] pub enum Error { #[display(...)] Pake(PakeError), #[display(...)] IO(io::Error), #[display(...)] Env(env::VarError), } varun: why are we panicking here? can we copy what we're doing in identity's `config.rs` today and… | |||||
jonAuthorUnsubmitted Done Inline Actionsbecause loading of the secrets file is critical to it working. Wanted to fail immediately, and made the error handling "cleaner" by just doing expect. However, I'll just be removing this altogether and delegating it to the service. jon: because loading of the secrets file is critical to it working. Wanted to fail immediately, and… | |||||
path.push(SECRETS_DIRECTORY); | |||||
path.push(SECRETS_FILE_NAME); | |||||
path.set_extension(SECRETS_FILE_EXTENSION); | |||||
let keypair = get_keypair_from_file(path)?; | |||||
Ok(Self { | |||||
server_keypair: keypair, | |||||
}) | |||||
} | |||||
} | |||||
#[cfg(test)] | |||||
fn get_keypair_from_file<P: AsRef<Path>>( | |||||
_: P, | |||||
) -> Result<KeyPair<RistrettoPoint>, InternalPakeError> { | |||||
Ok(Cipher::generate_random_keypair(&mut OsRng)) | |||||
} | |||||
#[cfg(not(test))] | |||||
fn get_keypair_from_file<P: AsRef<Path>>( | |||||
path: P, | |||||
) -> Result<KeyPair<RistrettoPoint>, InternalPakeError> { | |||||
let bytes = fs::read(path).expect("Unable to open secrets file"); | |||||
KeyPair::from_private_key_slice(&bytes) | |||||
} |
this should probably be pub not pub(super)