Changeset View
Standalone View
shared/comm-opaque/src/client/login.rs
- This file was added.
use opaque_ke::{ | |||||||||
errors::ProtocolError, ClientLogin, ClientLoginFinishParameters, | |||||||||
ClientLoginStartParameters, CredentialResponse, | |||||||||
}; | |||||||||
use rand::rngs::OsRng; | |||||||||
use crate::Cipher; | |||||||||
#[allow(dead_code)] | |||||||||
varun: these are all `pub`, so we shouldn't need the `#[allow(dead_code)]` attribute on any of these | |||||||||
jonAuthorUnsubmitted Done Inline ActionsI can add a crate wide #![allow(dead_code)], but visibility doesn't silence the warning. https://stackoverflow.com/questions/25877285/how-to-disable-unused-code-warnings-in-rust jon: I can add a crate wide `#![allow(dead_code)]`, but visibility doesn't silence the warning. | |||||||||
varunUnsubmitted Not Done Inline Actionsyou just need to make the modules in lib.rs pub, and then you can remove the crate-wide #![allow(dead_code)] attribute varun: you just need to make the modules in `lib.rs` pub, and then you can remove the crate-wide `#! | |||||||||
pub struct Login { | |||||||||
state: Option<ClientLogin<Cipher>>, | |||||||||
rng: OsRng, | |||||||||
varunUnsubmitted Done Inline Actions
varun: | |||||||||
jonAuthorUnsubmitted Done Inline ActionsStructs can't hold a reference unless you start doing some intense lifetime decoration everywhere. Furthermore, impl Trait only allowed in function and inherent method types. Can't have a loosely defined thing in a struct. If this is about testing, I have a test in lib.rs jon: Structs can't hold a reference unless you start doing some intense lifetime decoration… | |||||||||
varunUnsubmitted Not Done Inline Actionsmakes sense varun: makes sense | |||||||||
export_key: Option<Vec<u8>>, | |||||||||
pub session_key: Option<Vec<u8>>, | |||||||||
} | |||||||||
impl Login { | |||||||||
#[allow(dead_code)] | |||||||||
pub fn new() -> Login { | |||||||||
varunUnsubmitted Done Inline Actionscan we have the constructor take a &mut (impl Rng + CryptoRng) param and use that for the rng field? varun: can we have the constructor take a `&mut (impl Rng + CryptoRng)` param and use that for the… | |||||||||
jonAuthorUnsubmitted Done Inline ActionsHmm, I guess, but for the wasm bindings I wanted this to be the constructor, similar to wasm-opaque. I will look into the best way to do this, might just be able to construction your own Login { ... } as well. jon: Hmm, I guess, but for the wasm bindings I wanted this to be the constructor, similar to `wasm… | |||||||||
jonAuthorUnsubmitted Done Inline Actionsthe constructor function can take a &mut (impl Rng + CryptoRng), but a struct can not store just an impl Trait. It needs to be a concrete type. jon: the constructor function can take a `&mut (impl Rng + CryptoRng)`, but a struct can not store… | |||||||||
Login { | |||||||||
state: None, | |||||||||
rng: OsRng, | |||||||||
session_key: None, | |||||||||
export_key: None, | |||||||||
} | |||||||||
} | |||||||||
#[allow(dead_code)] | |||||||||
pub fn start(&mut self, password: &str) -> Result<Vec<u8>, ProtocolError> { | |||||||||
let client_start_result = ClientLogin::<Cipher>::start( | |||||||||
&mut self.rng, | |||||||||
password.as_bytes(), | |||||||||
ClientLoginStartParameters::default(), | |||||||||
)?; | |||||||||
self.state = Some(client_start_result.state); | |||||||||
client_start_result.message.serialize() | |||||||||
} | |||||||||
#[allow(dead_code)] | |||||||||
pub fn finish( | |||||||||
&mut self, | |||||||||
response_payload: &[u8], | |||||||||
) -> Result<Vec<u8>, ProtocolError> { | |||||||||
let response = CredentialResponse::deserialize(response_payload)?; | |||||||||
let state = self | |||||||||
.state | |||||||||
.take() | |||||||||
.ok_or_else(|| ProtocolError::ClientError)?; | |||||||||
let result = | |||||||||
state.finish(response, ClientLoginFinishParameters::default())?; | |||||||||
self.session_key = Some(result.session_key.to_vec()); | |||||||||
self.export_key = Some(result.export_key.to_vec()); | |||||||||
Ok(result.message.serialize()?.to_vec()) | |||||||||
} | |||||||||
} |
these are all pub, so we shouldn't need the #[allow(dead_code)] attribute on any of these