diff --git a/services/identity/rustfmt.toml b/services/identity/rustfmt.toml index b196eaa2d..205c72c3a 100644 --- a/services/identity/rustfmt.toml +++ b/services/identity/rustfmt.toml @@ -1 +1,2 @@ tab_spaces = 2 +max_width = 80 diff --git a/services/identity/src/config.rs b/services/identity/src/config.rs index 56c754c0d..fe94a8ee2 100644 --- a/services/identity/src/config.rs +++ b/services/identity/src/config.rs @@ -1,33 +1,35 @@ use opaque_ke::{errors::PakeError, keypair::Key}; use std::{env, fs, io, path::Path}; #[derive(Default, Debug)] pub struct Config { server_secret_key: Option, } impl Config { pub fn load() -> Result { let mut path = env::current_dir()?; path.push("secrets"); path.push("secret_key"); path.set_extension("txt"); let key = get_key_from_file(path)?; Ok(Self { server_secret_key: Some(key), }) } } -#[derive(Debug, derive_more::Display, derive_more::From, derive_more::Error)] +#[derive( + Debug, derive_more::Display, derive_more::From, derive_more::Error, +)] pub enum Error { #[display(...)] Pake(PakeError), #[display(...)] IO(io::Error), } fn get_key_from_file>(path: P) -> Result { let bytes = fs::read(path)?; Key::from_bytes(&bytes).map_err(|e| Error::Pake(e)) } diff --git a/services/identity/src/opaque.rs b/services/identity/src/opaque.rs index e3c656ebf..a6b5fd73a 100644 --- a/services/identity/src/opaque.rs +++ b/services/identity/src/opaque.rs @@ -1,29 +1,30 @@ use argon2::Argon2; use digest::{generic_array::GenericArray, Digest}; use opaque_ke::{ - ciphersuite::CipherSuite, errors::InternalPakeError, hash::Hash, slow_hash::SlowHash, + ciphersuite::CipherSuite, errors::InternalPakeError, hash::Hash, + slow_hash::SlowHash, }; pub struct Cipher; impl CipherSuite for Cipher { type Group = curve25519_dalek::ristretto::RistrettoPoint; type KeyExchange = opaque_ke::key_exchange::tripledh::TripleDH; type Hash = sha2::Sha512; type SlowHash = ArgonWrapper; } pub struct ArgonWrapper(Argon2<'static>); impl SlowHash for ArgonWrapper { fn hash( input: GenericArray::OutputSize>, ) -> Result, InternalPakeError> { let params = Argon2::default(); let mut output = vec![0u8; ::output_size()]; params .hash_password_into(&input, &[0; argon2::MIN_SALT_LEN], &mut output) .map_err(|_| InternalPakeError::SlowHashError)?; Ok(output) } } diff --git a/services/identity/src/service.rs b/services/identity/src/service.rs index f7289080b..df1e59308 100644 --- a/services/identity/src/service.rs +++ b/services/identity/src/service.rs @@ -1,55 +1,59 @@ use futures_core::Stream; use std::pin::Pin; use tonic::{Request, Response, Status}; use crate::config::Config; use crate::database::DatabaseClient; pub use proto::identity_service_server::IdentityServiceServer; use proto::{ - identity_service_server::IdentityService, LoginRequest, LoginResponse, RegistrationRequest, - RegistrationResponse, VerifyUserTokenRequest, VerifyUserTokenResponse, + identity_service_server::IdentityService, LoginRequest, LoginResponse, + RegistrationRequest, RegistrationResponse, VerifyUserTokenRequest, + VerifyUserTokenResponse, }; mod proto { tonic::include_proto!("identity"); } #[derive(derive_more::Constructor)] pub struct MyIdentityService { config: Config, client: DatabaseClient, } #[tonic::async_trait] impl IdentityService for MyIdentityService { - type RegisterUserStream = - Pin> + Send + 'static>>; + type RegisterUserStream = Pin< + Box< + dyn Stream> + Send + 'static, + >, + >; async fn register_user( &self, request: Request>, ) -> Result, Status> { println!("Got a registration request: {:?}", request); unimplemented!() } type LoginUserStream = Pin> + Send + 'static>>; async fn login_user( &self, request: Request>, ) -> Result, Status> { println!("Got a login request: {:?}", request); unimplemented!() } async fn verify_user_token( &self, request: Request, ) -> Result, Status> { println!("Got a lookup request: {:?}", request); unimplemented!() } }