Skip to content

Add ListClients and DeleteClient operations #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ fn generate_proto_sources() -> Result<()> {
.path()
.into_os_string()
.into_string()
.or_else(|_| {
Err(Error::new(
.map_err(|_| {
Error::new(
ErrorKind::InvalidData,
"conversion from OsString to String failed",
))
)
})
})
// Fail the entire operation if there was an error.
Expand Down
2 changes: 1 addition & 1 deletion parsec-operations
16 changes: 16 additions & 0 deletions src/operations/delete_client.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2021 Contributors to the Parsec project.
// SPDX-License-Identifier: Apache-2.0
//! # DeleteClient operation
//!
//! Delete all data a client own in Parsec.

/// Native object for client deleting operation.
#[derive(Clone, Debug)]
pub struct Operation {
/// A client application name.
pub client: String,
}

/// Native object for client deleting result.
#[derive(Copy, Clone, Debug)]
pub struct Result;
16 changes: 16 additions & 0 deletions src/operations/list_clients.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2021 Contributors to the Parsec project.
// SPDX-License-Identifier: Apache-2.0
//! # ListClients operation
//!
//! Lists all clients owning data in Parsec.

/// Native object for client listing operation.
#[derive(Copy, Clone, Debug)]
pub struct Operation;

/// Native object for client listing result.
#[derive(Debug)]
pub struct Result {
/// A list of client application names.
pub clients: Vec<String>,
}
38 changes: 38 additions & 0 deletions src/operations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ pub mod list_opcodes;
pub mod list_providers;
pub mod list_authenticators;
pub mod list_keys;
pub mod delete_client;
pub mod list_clients;
pub mod psa_generate_random;
pub mod psa_raw_key_agreement;

Expand All @@ -47,6 +49,10 @@ pub enum NativeOperation {
ListAuthenticators(list_authenticators::Operation),
/// ListKeys operation
ListKeys(list_keys::Operation),
/// ListClients operation
ListClients(list_clients::Operation),
/// DeleteClient operation
DeleteClient(delete_client::Operation),
/// Ping operation
Ping(ping::Operation),
/// PsaGenerateKey operation
Expand Down Expand Up @@ -99,6 +105,8 @@ impl NativeOperation {
NativeOperation::ListProviders(_) => Opcode::ListProviders,
NativeOperation::ListAuthenticators(_) => Opcode::ListAuthenticators,
NativeOperation::ListKeys(_) => Opcode::ListKeys,
NativeOperation::ListClients(_) => Opcode::ListClients,
NativeOperation::DeleteClient(_) => Opcode::DeleteClient,
NativeOperation::PsaAsymmetricEncrypt(_) => Opcode::PsaAsymmetricEncrypt,
NativeOperation::PsaAsymmetricDecrypt(_) => Opcode::PsaAsymmetricDecrypt,
NativeOperation::PsaAeadEncrypt(_) => Opcode::PsaAeadEncrypt,
Expand All @@ -121,6 +129,10 @@ pub enum NativeResult {
ListAuthenticators(list_authenticators::Result),
/// ListKeys result
ListKeys(list_keys::Result),
/// ListClients result
ListClients(list_clients::Result),
/// DeleteClient result
DeleteClient(delete_client::Result),
/// Ping result
Ping(ping::Result),
/// PsaGenerateKey result
Expand Down Expand Up @@ -173,6 +185,8 @@ impl NativeResult {
NativeResult::ListProviders(_) => Opcode::ListProviders,
NativeResult::ListAuthenticators(_) => Opcode::ListAuthenticators,
NativeResult::ListKeys(_) => Opcode::ListKeys,
NativeResult::ListClients(_) => Opcode::ListClients,
NativeResult::DeleteClient(_) => Opcode::DeleteClient,
NativeResult::PsaAsymmetricEncrypt(_) => Opcode::PsaAsymmetricEncrypt,
NativeResult::PsaAsymmetricDecrypt(_) => Opcode::PsaAsymmetricDecrypt,
NativeResult::PsaAeadEncrypt(_) => Opcode::PsaAeadEncrypt,
Expand Down Expand Up @@ -238,6 +252,18 @@ impl From<list_keys::Operation> for NativeOperation {
}
}

impl From<list_clients::Operation> for NativeOperation {
fn from(op: list_clients::Operation) -> Self {
NativeOperation::ListClients(op)
}
}

impl From<delete_client::Operation> for NativeOperation {
fn from(op: delete_client::Operation) -> Self {
NativeOperation::DeleteClient(op)
}
}

impl From<ping::Operation> for NativeOperation {
fn from(op: ping::Operation) -> Self {
NativeOperation::Ping(op)
Expand Down Expand Up @@ -357,6 +383,18 @@ impl From<list_keys::Result> for NativeResult {
}
}

impl From<list_clients::Result> for NativeResult {
fn from(op: list_clients::Result) -> Self {
NativeResult::ListClients(op)
}
}

impl From<delete_client::Result> for NativeResult {
fn from(op: delete_client::Result) -> Self {
NativeResult::DeleteClient(op)
}
}

impl From<ping::Result> for NativeResult {
fn from(op: ping::Result) -> Self {
NativeResult::Ping(op)
Expand Down
58 changes: 58 additions & 0 deletions src/operations_protobuf/convert_delete_client.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2021 Contributors to the Parsec project.
// SPDX-License-Identifier: Apache-2.0
use super::generated_ops::delete_client::{Operation as OperationProto, Result as ResultProto};
use crate::operations::delete_client::{Operation, Result};

impl From<OperationProto> for Operation {
fn from(proto_op: OperationProto) -> Self {
Operation {
client: proto_op.client,
}
}
}

impl From<Operation> for OperationProto {
fn from(op: Operation) -> Self {
OperationProto { client: op.client }
}
}

impl From<ResultProto> for Result {
fn from(_proto_op: ResultProto) -> Self {
Result {}
}
}

impl From<Result> for ResultProto {
fn from(_op: Result) -> Self {
ResultProto {}
}
}

#[cfg(test)]
mod test {
use super::super::generated_ops::delete_client::Operation as OperationProto;
use crate::operations::delete_client::Operation;

#[test]
fn proto_to_resp() {
let mut proto: OperationProto = Default::default();

proto.client = String::from("toto");

let resp: Operation = proto.into();

assert_eq!(resp.client, String::from("toto"));
}

#[test]
fn resp_to_proto() {
let resp: Operation = Operation {
client: String::from("toto"),
};

let proto: OperationProto = resp.into();

assert_eq!(proto.client, String::from("toto"));
}
}
62 changes: 62 additions & 0 deletions src/operations_protobuf/convert_list_clients.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright 2021 Contributors to the Parsec project.
// SPDX-License-Identifier: Apache-2.0
use super::generated_ops::list_clients::{Operation as OperationProto, Result as ResultProto};
use crate::operations::list_clients::{Operation, Result};

impl From<OperationProto> for Operation {
fn from(_proto_op: OperationProto) -> Self {
Operation {}
}
}

impl From<Operation> for OperationProto {
fn from(_op: Operation) -> Self {
Default::default()
}
}

impl From<ResultProto> for Result {
fn from(proto_op: ResultProto) -> Self {
Result {
clients: proto_op.clients,
}
}
}

impl From<Result> for ResultProto {
fn from(op: Result) -> Self {
ResultProto {
clients: op.clients,
}
}
}

#[cfg(test)]
mod test {
use super::super::generated_ops::list_clients::Result as ResultProto;
use crate::operations::list_clients::Result;

#[test]
fn proto_to_resp() {
let mut proto: ResultProto = Default::default();

proto.clients.push(String::from("toto"));

let resp: Result = proto.into();

assert_eq!(resp.clients.len(), 1);
assert_eq!(resp.clients[0], String::from("toto"));
}

#[test]
fn resp_to_proto() {
let resp: Result = Result {
clients: vec![String::from("toto")],
};

let proto: ResultProto = resp.into();

assert_eq!(proto.clients.len(), 1);
assert_eq!(proto.clients[0], String::from("toto"));
}
}
8 changes: 7 additions & 1 deletion src/operations_protobuf/generated_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ include_protobuf_as_module!(list_opcodes);
include_protobuf_as_module!(list_providers);
include_protobuf_as_module!(list_authenticators);
include_protobuf_as_module!(list_keys);
include_protobuf_as_module!(list_clients);
include_protobuf_as_module!(delete_client);
include_protobuf_as_module!(ping);
include_protobuf_as_module!(psa_key_attributes);
include_protobuf_as_module!(psa_algorithm);
Expand Down Expand Up @@ -143,6 +145,10 @@ empty_clear_message!(list_authenticators::Operation);
empty_clear_message!(list_authenticators::Result);
empty_clear_message!(list_keys::Operation);
empty_clear_message!(list_keys::Result);
empty_clear_message!(list_clients::Operation);
empty_clear_message!(list_clients::Result);
empty_clear_message!(delete_client::Operation);
empty_clear_message!(delete_client::Result);
empty_clear_message!(ping::Operation);
empty_clear_message!(ping::Result);
empty_clear_message!(psa_destroy_key::Operation);
Expand Down Expand Up @@ -270,4 +276,4 @@ impl ClearProtoMessage for psa_raw_key_agreement::Result {
fn clear_message(&mut self) {
self.shared_secret.zeroize();
}
}
}
34 changes: 34 additions & 0 deletions src/operations_protobuf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ mod convert_list_providers;
mod convert_list_opcodes;
mod convert_list_authenticators;
mod convert_list_keys;
mod convert_list_clients;
mod convert_delete_client;
mod convert_psa_asymmetric_encrypt;
mod convert_psa_asymmetric_decrypt;
mod convert_psa_aead_encrypt;
Expand All @@ -34,7 +36,9 @@ use crate::operations::{Convert, NativeOperation, NativeResult};
use crate::requests::{
request::RequestBody, response::ResponseBody, BodyType, Opcode, ResponseStatus, Result,
};
use generated_ops::delete_client as delete_client_proto;
use generated_ops::list_authenticators as list_authenticators_proto;
use generated_ops::list_clients as list_clients_proto;
use generated_ops::list_keys as list_keys_proto;
use generated_ops::list_opcodes as list_opcodes_proto;
use generated_ops::list_providers as list_providers_proto;
Expand Down Expand Up @@ -109,6 +113,14 @@ impl Convert for ProtobufConverter {
body.bytes(),
list_keys_proto::Operation
))),
Opcode::ListClients => Ok(NativeOperation::ListClients(wire_to_native!(
body.bytes(),
list_clients_proto::Operation
))),
Opcode::DeleteClient => Ok(NativeOperation::DeleteClient(wire_to_native!(
body.bytes(),
delete_client_proto::Operation
))),
Opcode::Ping => Ok(NativeOperation::Ping(wire_to_native!(
body.bytes(),
ping_proto::Operation
Expand Down Expand Up @@ -189,6 +201,12 @@ impl Convert for ProtobufConverter {
operation,
list_keys_proto::Operation
))),
NativeOperation::ListClients(operation) => Ok(RequestBody::from_bytes(
native_to_wire!(operation, list_clients_proto::Operation),
)),
NativeOperation::DeleteClient(operation) => Ok(RequestBody::from_bytes(
native_to_wire!(operation, delete_client_proto::Operation),
)),
NativeOperation::Ping(operation) => Ok(RequestBody::from_bytes(native_to_wire!(
operation,
ping_proto::Operation
Expand Down Expand Up @@ -259,6 +277,14 @@ impl Convert for ProtobufConverter {
body.bytes(),
list_keys_proto::Result
))),
Opcode::ListClients => Ok(NativeResult::ListClients(wire_to_native!(
body.bytes(),
list_clients_proto::Result
))),
Opcode::DeleteClient => Ok(NativeResult::DeleteClient(wire_to_native!(
body.bytes(),
delete_client_proto::Result
))),
Opcode::Ping => Ok(NativeResult::Ping(wire_to_native!(
body.bytes(),
ping_proto::Result
Expand Down Expand Up @@ -341,6 +367,14 @@ impl Convert for ProtobufConverter {
result,
list_keys_proto::Result
))),
NativeResult::ListClients(result) => Ok(ResponseBody::from_bytes(native_to_wire!(
result,
list_clients_proto::Result
))),
NativeResult::DeleteClient(result) => Ok(ResponseBody::from_bytes(native_to_wire!(
result,
delete_client_proto::Result
))),
NativeResult::Ping(result) => Ok(ResponseBody::from_bytes(native_to_wire!(
result,
ping_proto::Result
Expand Down
Loading