Changeset View
Changeset View
Standalone View
Standalone View
shared/comm-opaque2/src/client/register.rs
use opaque_ke::{ | use opaque_ke::{ | ||||
errors::ProtocolError, ClientRegistration, | errors::ProtocolError, ClientRegistration, | ||||
ClientRegistrationFinishParameters, RegistrationResponse, | ClientRegistrationFinishParameters, RegistrationResponse, | ||||
}; | }; | ||||
use rand::rngs::OsRng; | use rand::rngs::OsRng; | ||||
use wasm_bindgen::prelude::*; | |||||
use crate::error::OpaqueError; | |||||
use crate::Cipher; | use crate::Cipher; | ||||
#[wasm_bindgen] | |||||
pub struct Registration { | pub struct Registration { | ||||
state: Option<ClientRegistration<Cipher>>, | state: Option<ClientRegistration<Cipher>>, | ||||
rng: OsRng, | rng: OsRng, | ||||
export_key: Option<Vec<u8>>, | export_key: Option<Vec<u8>>, | ||||
} | } | ||||
#[wasm_bindgen] | |||||
impl Registration { | impl Registration { | ||||
#[wasm_bindgen(constructor)] | |||||
pub fn new() -> Registration { | pub fn new() -> Registration { | ||||
Registration { | Registration { | ||||
state: None, | state: None, | ||||
rng: OsRng, | rng: OsRng, | ||||
export_key: None, | export_key: None, | ||||
} | } | ||||
} | } | ||||
pub fn start(&mut self, password: &str) -> Result<Vec<u8>, ProtocolError> { | pub fn start(&mut self, password: &str) -> Result<Vec<u8>, OpaqueError> { | ||||
let result = | let result = | ||||
ClientRegistration::<Cipher>::start(&mut self.rng, password.as_bytes())?; | ClientRegistration::<Cipher>::start(&mut self.rng, password.as_bytes())?; | ||||
self.state = Some(result.state); | self.state = Some(result.state); | ||||
Ok(result.message.serialize().to_vec()) | Ok(result.message.serialize().to_vec()) | ||||
} | } | ||||
pub fn finish( | pub fn finish( | ||||
&mut self, | &mut self, | ||||
password: &str, | password: &str, | ||||
response_payload: &[u8], | response_payload: &[u8], | ||||
) -> Result<Vec<u8>, ProtocolError> { | ) -> Result<Vec<u8>, OpaqueError> { | ||||
let response = RegistrationResponse::deserialize(response_payload)?; | let response = RegistrationResponse::deserialize(response_payload)?; | ||||
let state = self | let state = self | ||||
.state | .state | ||||
.take() | .take() | ||||
.ok_or_else(|| ProtocolError::InvalidLoginError)?; | .ok_or_else(|| ProtocolError::InvalidLoginError)?; | ||||
let result = state.finish( | let result = state.finish( | ||||
&mut self.rng, | &mut self.rng, | ||||
password.as_bytes(), | password.as_bytes(), | ||||
Show All 9 Lines |