Changeset View
Changeset View
Standalone View
Standalone View
shared/comm-opaque/src/client.rs
- This file was added.
use opaque_ke::{ | |||||
errors::ProtocolError, ClientLogin, ClientLoginFinishParameters, | |||||
ClientLoginFinishResult, ClientLoginStartParameters, ClientRegistration, | |||||
ClientRegistrationFinishParameters, CredentialResponse, RegistrationResponse, | |||||
}; | |||||
use rand::rngs::OsRng; | |||||
use crate::Cipher; | |||||
// These methods are used in other parts of the code base | |||||
#[allow(dead_code)] | |||||
pub fn register_start( | |||||
password: &[u8], | |||||
) -> Result<(ClientRegistration<Cipher>, Vec<u8>), ProtocolError> { | |||||
varun: can we use structs instead of tuples? it becomes confusing when you have to use `.0` and `.1`… | |||||
jonAuthorUnsubmitted Done Inline Actionsyou can destructure a tuple as part of a let let (foo, bar) = func(); I would like to avoid wrapping both the state and message in a struct to avoid lifetime issues: https://linear.app/comm/issue/ENG-3211/avoid-globbing-opaque-ke-structs-with-other-information-while-handling Either way, I'm probably going to wrap this in a struct, and expose to impls to move the state machinery forward: let client_login = client::Login::new(); let client_login_request = client_login.start(password); // send request to server // receive server response let client_upload = client_login.finish(server_response); // send upload to server Might be necessary because https://github.com/napi-rs/napi-rs#features-table doesn't support tuples, and will likely move closer to something like https://github.com/marucjmar/opaque-wasm/blob/master/src/client_registration.rs as it would be more JS friendly anyway. jon: you can destructure a tuple as part of a let
```
let (foo, bar) = func();
```
I would like to… | |||||
jonAuthorUnsubmitted Done Inline ActionsOn the JS side, this would like: const client_login = new Login(); const login_request = client_login.start(password); // send request to server // receive server response const client_upload = client_login.finish(server_response); // send upload to server jon: On the JS side, this would like:
```
const client_login = new Login();
const login_request… | |||||
let res = ClientRegistration::<Cipher>::start(&mut OsRng, password)?; | |||||
Ok((res.state, res.message.serialize())) | |||||
} | |||||
#[allow(dead_code)] | |||||
pub fn register_finish( | |||||
registration_result: ClientRegistration<Cipher>, | |||||
response_payload: &[u8], | |||||
) -> Result<Vec<u8>, ProtocolError> { | |||||
let response = RegistrationResponse::deserialize(response_payload)?; | |||||
let result = registration_result.finish( | |||||
&mut OsRng, | |||||
response, | |||||
ClientRegistrationFinishParameters::default(), | |||||
)?; | |||||
Ok(result.message.serialize()) | |||||
} | |||||
#[allow(dead_code)] | |||||
pub fn login_start( | |||||
password: &[u8], | |||||
) -> Result<(ClientLogin<Cipher>, Vec<u8>), ProtocolError> { | |||||
let start_result = ClientLogin::<Cipher>::start( | |||||
&mut OsRng, | |||||
password, | |||||
ClientLoginStartParameters::default(), | |||||
)?; | |||||
Ok((start_result.state, start_result.message.serialize()?)) | |||||
} | |||||
#[allow(dead_code)] | |||||
pub fn login_finish( | |||||
login_result: ClientLogin<Cipher>, | |||||
response_payload: &[u8], | |||||
) -> Result<ClientLoginFinishResult<Cipher>, ProtocolError> { | |||||
let response = CredentialResponse::deserialize(response_payload)?; | |||||
login_result.finish(response, ClientLoginFinishParameters::default()) | |||||
} |
can we use structs instead of tuples? it becomes confusing when you have to use .0 and .1 to access the data