Implement Clone for every message type

This commit is contained in:
Valentin Tolmer
2021-06-15 10:06:32 -07:00
committed by Kevin Lewi
parent 30e27a11e2
commit 2c7fe4e382
5 changed files with 194 additions and 7 deletions
+125
View File
@@ -36,6 +36,15 @@ pub struct ClientRegistration<CS: CipherSuite> {
pub(crate) token: oprf::Token<CS::Group>,
}
// Cannot be derived because it would require for CS to be Clone.
impl<CS: CipherSuite> Clone for ClientRegistration<CS> {
fn clone(&self) -> Self {
Self {
token: self.token.clone(),
}
}
}
impl<CS: CipherSuite> ClientRegistration<CS> {
/// Serialization into bytes
pub fn serialize(&self) -> Vec<u8> {
@@ -86,6 +95,7 @@ impl<CS: CipherSuite> ClientRegistration<CS> {
impl_serialize_and_deserialize_for!(ClientRegistration);
/// Optional parameters for client registration finish
#[derive(Clone)]
pub enum ClientRegistrationFinishParameters {
/// Specifying the identifiers idU and idS (corresponding to custom identifier mode)
WithIdentifiers(Vec<u8>, Vec<u8>),
@@ -107,6 +117,16 @@ pub struct ClientRegistrationStartResult<CS: CipherSuite> {
pub state: ClientRegistration<CS>,
}
// Cannot be derived because it would require for CS to be Clone.
impl<CS: CipherSuite> Clone for ClientRegistrationStartResult<CS> {
fn clone(&self) -> Self {
Self {
message: self.message.clone(),
state: self.state.clone(),
}
}
}
impl<CS: CipherSuite> ClientRegistration<CS> {
/// Returns an initial "blinded" request to send to the server, as well as a ClientRegistration
///
@@ -155,6 +175,18 @@ pub struct ClientRegistrationFinishResult<CS: CipherSuite> {
pub state: ClientRegistration<CS>,
}
// Cannot be derived because it would require for CS to be Clone.
impl<CS: CipherSuite> Clone for ClientRegistrationFinishResult<CS> {
fn clone(&self) -> Self {
Self {
message: self.message.clone(),
export_key: self.export_key.clone(),
#[cfg(test)]
state: self.state.clone(),
}
}
}
impl<CS: CipherSuite> ClientRegistration<CS> {
/// "Unblinds" the server's answer and returns a final message containing
/// cryptographic identifiers, to be sent to the server on setup finalization
@@ -230,6 +262,16 @@ pub struct ServerRegistrationStartResult<CS: CipherSuite> {
pub state: ServerRegistration<CS>,
}
// Cannot be derived because it would require for CS to be Clone.
impl<CS: CipherSuite> Clone for ServerRegistrationStartResult<CS> {
fn clone(&self) -> Self {
Self {
message: self.message.clone(),
state: self.state.clone(),
}
}
}
/// The state elements the server holds to record a registration
pub struct ServerRegistration<CS: CipherSuite> {
envelope: Option<Envelope<CS::Hash>>,
@@ -237,6 +279,17 @@ pub struct ServerRegistration<CS: CipherSuite> {
pub(crate) oprf_key: <CS::Group as Group>::Scalar,
}
// Cannot be derived because it would require for CS to be Clone.
impl<CS: CipherSuite> Clone for ServerRegistration<CS> {
fn clone(&self) -> Self {
Self {
envelope: self.envelope.clone(),
client_s_pk: self.client_s_pk.clone(),
oprf_key: self.oprf_key.clone(),
}
}
}
impl<CS: CipherSuite> ServerRegistration<CS> {
/// Serialization into bytes
pub fn serialize(&self) -> Vec<u8> {
@@ -400,6 +453,17 @@ pub struct ClientLogin<CS: CipherSuite> {
serialized_credential_request: Vec<u8>,
}
// Cannot be derived because it would require for CS to be Clone.
impl<CS: CipherSuite> Clone for ClientLogin<CS> {
fn clone(&self) -> Self {
Self {
token: self.token.clone(),
ke1_state: self.ke1_state.clone(),
serialized_credential_request: self.serialized_credential_request.clone(),
}
}
}
impl<CS: CipherSuite> ClientLogin<CS> {
/// Serialization into bytes
pub fn serialize(&self) -> Vec<u8> {
@@ -462,6 +526,7 @@ impl<CS: CipherSuite> ClientLogin<CS> {
impl_serialize_and_deserialize_for!(ClientLogin);
/// Optional parameters for client login start
#[derive(Clone)]
pub enum ClientLoginStartParameters {
/// Specifying a plaintext info field that will be sent to the server
WithInfo(Vec<u8>),
@@ -481,7 +546,18 @@ pub struct ClientLoginStartResult<CS: CipherSuite> {
pub state: ClientLogin<CS>,
}
// Cannot be derived because it would require for CS to be Clone.
impl<CS: CipherSuite> Clone for ClientLoginStartResult<CS> {
fn clone(&self) -> Self {
Self {
message: self.message.clone(),
state: self.state.clone(),
}
}
}
/// Optional parameters for client login finish
#[derive(Clone)]
pub enum ClientLoginFinishParameters {
/// Specifying a user identifier and server identifier that will be matched against the client
WithIdentifiers(Vec<u8>, Vec<u8>),
@@ -512,6 +588,21 @@ pub struct ClientLoginFinishResult<CS: CipherSuite> {
pub state: ClientLogin<CS>,
}
// Cannot be derived because it would require for CS to be Clone.
impl<CS: CipherSuite> Clone for ClientLoginFinishResult<CS> {
fn clone(&self) -> Self {
Self {
message: self.message.clone(),
session_key: self.session_key.clone(),
export_key: self.export_key.clone(),
server_s_pk: self.server_s_pk.clone(),
confidential_info: self.confidential_info.clone(),
#[cfg(test)]
state: self.state.clone(),
}
}
}
impl<CS: CipherSuite> ClientLogin<CS> {
/// Returns an initial "blinded" password request to send to the server, as well as a ClientLogin
///
@@ -660,7 +751,18 @@ pub struct ServerLogin<CS: CipherSuite> {
_cs: PhantomData<CS>,
}
// Cannot be derived because it would require for CS to be Clone.
impl<CS: CipherSuite> Clone for ServerLogin<CS> {
fn clone(&self) -> Self {
Self {
ke2_state: self.ke2_state.clone(),
_cs: PhantomData,
}
}
}
/// Optional parameters for server login start
#[derive(Clone)]
pub enum ServerLoginStartParameters {
/// Specifying a confidential info field that will be sent to the client
WithInfo(Vec<u8>),
@@ -688,6 +790,17 @@ pub struct ServerLoginStartResult<CS: CipherSuite> {
pub plain_info: Vec<u8>,
}
// Cannot be derived because it would require for CS to be Clone.
impl<CS: CipherSuite> Clone for ServerLoginStartResult<CS> {
fn clone(&self) -> Self {
Self {
message: self.message.clone(),
state: self.state.clone(),
plain_info: self.plain_info.clone(),
}
}
}
/// Contains the fields that are returned by a server login finish
pub struct ServerLoginFinishResult<CS: CipherSuite> {
/// The session key between client and server
@@ -698,6 +811,18 @@ pub struct ServerLoginFinishResult<CS: CipherSuite> {
pub state: ServerLogin<CS>,
}
// Cannot be derived because it would require for CS to be Clone.
impl<CS: CipherSuite> Clone for ServerLoginFinishResult<CS> {
fn clone(&self) -> Self {
Self {
session_key: self.session_key.clone(),
_cs: PhantomData,
#[cfg(test)]
state: self.state.clone(),
}
}
}
impl<CS: CipherSuite> ServerLogin<CS> {
/// Serialization into bytes
pub fn serialize(&self) -> Vec<u8> {