Skip to content

Commit 2e1dc92

Browse files
committed
Add ListClients and DeleteClient operations
Also adds the new response status code Signed-off-by: Hugues de Valon <[email protected]>
1 parent 49aab6e commit 2e1dc92

11 files changed

+247
-6
lines changed

build.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ fn generate_proto_sources() -> Result<()> {
1717
.path()
1818
.into_os_string()
1919
.into_string()
20-
.or_else(|_| {
21-
Err(Error::new(
20+
.map_err(|_| {
21+
Error::new(
2222
ErrorKind::InvalidData,
2323
"conversion from OsString to String failed",
24-
))
24+
)
2525
})
2626
})
2727
// Fail the entire operation if there was an error.

src/operations/delete_client.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2021 Contributors to the Parsec project.
2+
// SPDX-License-Identifier: Apache-2.0
3+
//! # DeleteClient operation
4+
//!
5+
//! Delete all data a client own in Parsec.
6+
7+
/// Native object for client deleting operation.
8+
#[derive(Clone, Debug)]
9+
pub struct Operation {
10+
/// A client application name.
11+
pub client: String,
12+
}
13+
14+
/// Native object for client deleting result.
15+
#[derive(Copy, Clone, Debug)]
16+
pub struct Result;

src/operations/list_clients.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2021 Contributors to the Parsec project.
2+
// SPDX-License-Identifier: Apache-2.0
3+
//! # ListClients operation
4+
//!
5+
//! Lists all clients owning data in Parsec.
6+
7+
/// Native object for client listing operation.
8+
#[derive(Copy, Clone, Debug)]
9+
pub struct Operation;
10+
11+
/// Native object for client listing result.
12+
#[derive(Debug)]
13+
pub struct Result {
14+
/// A list of client application names.
15+
pub clients: Vec<String>,
16+
}

src/operations/mod.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ pub mod list_opcodes;
2727
pub mod list_providers;
2828
pub mod list_authenticators;
2929
pub mod list_keys;
30+
pub mod delete_client;
31+
pub mod list_clients;
3032
pub mod psa_generate_random;
3133
pub mod psa_raw_key_agreement;
3234

@@ -47,6 +49,10 @@ pub enum NativeOperation {
4749
ListAuthenticators(list_authenticators::Operation),
4850
/// ListKeys operation
4951
ListKeys(list_keys::Operation),
52+
/// ListClients operation
53+
ListClients(list_clients::Operation),
54+
/// DeleteClient operation
55+
DeleteClient(delete_client::Operation),
5056
/// Ping operation
5157
Ping(ping::Operation),
5258
/// PsaGenerateKey operation
@@ -99,6 +105,8 @@ impl NativeOperation {
99105
NativeOperation::ListProviders(_) => Opcode::ListProviders,
100106
NativeOperation::ListAuthenticators(_) => Opcode::ListAuthenticators,
101107
NativeOperation::ListKeys(_) => Opcode::ListKeys,
108+
NativeOperation::ListClients(_) => Opcode::ListClients,
109+
NativeOperation::DeleteClient(_) => Opcode::DeleteClient,
102110
NativeOperation::PsaAsymmetricEncrypt(_) => Opcode::PsaAsymmetricEncrypt,
103111
NativeOperation::PsaAsymmetricDecrypt(_) => Opcode::PsaAsymmetricDecrypt,
104112
NativeOperation::PsaAeadEncrypt(_) => Opcode::PsaAeadEncrypt,
@@ -121,6 +129,10 @@ pub enum NativeResult {
121129
ListAuthenticators(list_authenticators::Result),
122130
/// ListKeys result
123131
ListKeys(list_keys::Result),
132+
/// ListClients result
133+
ListClients(list_clients::Result),
134+
/// DeleteClient result
135+
DeleteClient(delete_client::Result),
124136
/// Ping result
125137
Ping(ping::Result),
126138
/// PsaGenerateKey result
@@ -173,6 +185,8 @@ impl NativeResult {
173185
NativeResult::ListProviders(_) => Opcode::ListProviders,
174186
NativeResult::ListAuthenticators(_) => Opcode::ListAuthenticators,
175187
NativeResult::ListKeys(_) => Opcode::ListKeys,
188+
NativeResult::ListClients(_) => Opcode::ListClients,
189+
NativeResult::DeleteClient(_) => Opcode::DeleteClient,
176190
NativeResult::PsaAsymmetricEncrypt(_) => Opcode::PsaAsymmetricEncrypt,
177191
NativeResult::PsaAsymmetricDecrypt(_) => Opcode::PsaAsymmetricDecrypt,
178192
NativeResult::PsaAeadEncrypt(_) => Opcode::PsaAeadEncrypt,
@@ -238,6 +252,18 @@ impl From<list_keys::Operation> for NativeOperation {
238252
}
239253
}
240254

255+
impl From<list_clients::Operation> for NativeOperation {
256+
fn from(op: list_clients::Operation) -> Self {
257+
NativeOperation::ListClients(op)
258+
}
259+
}
260+
261+
impl From<delete_client::Operation> for NativeOperation {
262+
fn from(op: delete_client::Operation) -> Self {
263+
NativeOperation::DeleteClient(op)
264+
}
265+
}
266+
241267
impl From<ping::Operation> for NativeOperation {
242268
fn from(op: ping::Operation) -> Self {
243269
NativeOperation::Ping(op)
@@ -357,6 +383,18 @@ impl From<list_keys::Result> for NativeResult {
357383
}
358384
}
359385

386+
impl From<list_clients::Result> for NativeResult {
387+
fn from(op: list_clients::Result) -> Self {
388+
NativeResult::ListClients(op)
389+
}
390+
}
391+
392+
impl From<delete_client::Result> for NativeResult {
393+
fn from(op: delete_client::Result) -> Self {
394+
NativeResult::DeleteClient(op)
395+
}
396+
}
397+
360398
impl From<ping::Result> for NativeResult {
361399
fn from(op: ping::Result) -> Self {
362400
NativeResult::Ping(op)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright 2021 Contributors to the Parsec project.
2+
// SPDX-License-Identifier: Apache-2.0
3+
use super::generated_ops::delete_client::{Operation as OperationProto, Result as ResultProto};
4+
use crate::operations::delete_client::{Operation, Result};
5+
6+
impl From<OperationProto> for Operation {
7+
fn from(proto_op: OperationProto) -> Self {
8+
Operation {
9+
client: proto_op.client,
10+
}
11+
}
12+
}
13+
14+
impl From<Operation> for OperationProto {
15+
fn from(op: Operation) -> Self {
16+
OperationProto { client: op.client }
17+
}
18+
}
19+
20+
impl From<ResultProto> for Result {
21+
fn from(_proto_op: ResultProto) -> Self {
22+
Result {}
23+
}
24+
}
25+
26+
impl From<Result> for ResultProto {
27+
fn from(_op: Result) -> Self {
28+
ResultProto {}
29+
}
30+
}
31+
32+
#[cfg(test)]
33+
mod test {
34+
use super::super::generated_ops::delete_client::Operation as OperationProto;
35+
use crate::operations::delete_client::Operation;
36+
37+
#[test]
38+
fn proto_to_resp() {
39+
let mut proto: OperationProto = Default::default();
40+
41+
proto.client = String::from("toto");
42+
43+
let resp: Operation = proto.into();
44+
45+
assert_eq!(resp.client, String::from("toto"));
46+
}
47+
48+
#[test]
49+
fn resp_to_proto() {
50+
let resp: Operation = Operation {
51+
client: String::from("toto"),
52+
};
53+
54+
let proto: OperationProto = resp.into();
55+
56+
assert_eq!(proto.client, String::from("toto"));
57+
}
58+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright 2021 Contributors to the Parsec project.
2+
// SPDX-License-Identifier: Apache-2.0
3+
use super::generated_ops::list_clients::{Operation as OperationProto, Result as ResultProto};
4+
use crate::operations::list_clients::{Operation, Result};
5+
6+
impl From<OperationProto> for Operation {
7+
fn from(_proto_op: OperationProto) -> Self {
8+
Operation {}
9+
}
10+
}
11+
12+
impl From<Operation> for OperationProto {
13+
fn from(_op: Operation) -> Self {
14+
Default::default()
15+
}
16+
}
17+
18+
impl From<ResultProto> for Result {
19+
fn from(proto_op: ResultProto) -> Self {
20+
Result {
21+
clients: proto_op.clients,
22+
}
23+
}
24+
}
25+
26+
impl From<Result> for ResultProto {
27+
fn from(op: Result) -> Self {
28+
ResultProto {
29+
clients: op.clients,
30+
}
31+
}
32+
}
33+
34+
#[cfg(test)]
35+
mod test {
36+
use super::super::generated_ops::list_clients::Result as ResultProto;
37+
use crate::operations::list_clients::Result;
38+
39+
#[test]
40+
fn proto_to_resp() {
41+
let mut proto: ResultProto = Default::default();
42+
43+
proto.clients.push(String::from("toto"));
44+
45+
let resp: Result = proto.into();
46+
47+
assert_eq!(resp.clients.len(), 1);
48+
assert_eq!(resp.clients[0], String::from("toto"));
49+
}
50+
51+
#[test]
52+
fn resp_to_proto() {
53+
let resp: Result = Result {
54+
clients: vec![String::from("toto")],
55+
};
56+
57+
let proto: ResultProto = resp.into();
58+
59+
assert_eq!(proto.clients.len(), 1);
60+
assert_eq!(proto.clients[0], String::from("toto"));
61+
}
62+
}

src/operations_protobuf/generated_ops.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ include_protobuf_as_module!(list_opcodes);
3030
include_protobuf_as_module!(list_providers);
3131
include_protobuf_as_module!(list_authenticators);
3232
include_protobuf_as_module!(list_keys);
33+
include_protobuf_as_module!(list_clients);
34+
include_protobuf_as_module!(delete_client);
3335
include_protobuf_as_module!(ping);
3436
include_protobuf_as_module!(psa_key_attributes);
3537
include_protobuf_as_module!(psa_algorithm);
@@ -143,6 +145,10 @@ empty_clear_message!(list_authenticators::Operation);
143145
empty_clear_message!(list_authenticators::Result);
144146
empty_clear_message!(list_keys::Operation);
145147
empty_clear_message!(list_keys::Result);
148+
empty_clear_message!(list_clients::Operation);
149+
empty_clear_message!(list_clients::Result);
150+
empty_clear_message!(delete_client::Operation);
151+
empty_clear_message!(delete_client::Result);
146152
empty_clear_message!(ping::Operation);
147153
empty_clear_message!(ping::Result);
148154
empty_clear_message!(psa_destroy_key::Operation);
@@ -270,4 +276,4 @@ impl ClearProtoMessage for psa_raw_key_agreement::Result {
270276
fn clear_message(&mut self) {
271277
self.shared_secret.zeroize();
272278
}
273-
}
279+
}

src/operations_protobuf/mod.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ mod convert_list_providers;
1919
mod convert_list_opcodes;
2020
mod convert_list_authenticators;
2121
mod convert_list_keys;
22+
mod convert_list_clients;
23+
mod convert_delete_client;
2224
mod convert_psa_asymmetric_encrypt;
2325
mod convert_psa_asymmetric_decrypt;
2426
mod convert_psa_aead_encrypt;
@@ -34,7 +36,9 @@ use crate::operations::{Convert, NativeOperation, NativeResult};
3436
use crate::requests::{
3537
request::RequestBody, response::ResponseBody, BodyType, Opcode, ResponseStatus, Result,
3638
};
39+
use generated_ops::delete_client as delete_client_proto;
3740
use generated_ops::list_authenticators as list_authenticators_proto;
41+
use generated_ops::list_clients as list_clients_proto;
3842
use generated_ops::list_keys as list_keys_proto;
3943
use generated_ops::list_opcodes as list_opcodes_proto;
4044
use generated_ops::list_providers as list_providers_proto;
@@ -109,6 +113,14 @@ impl Convert for ProtobufConverter {
109113
body.bytes(),
110114
list_keys_proto::Operation
111115
))),
116+
Opcode::ListClients => Ok(NativeOperation::ListClients(wire_to_native!(
117+
body.bytes(),
118+
list_clients_proto::Operation
119+
))),
120+
Opcode::DeleteClient => Ok(NativeOperation::DeleteClient(wire_to_native!(
121+
body.bytes(),
122+
delete_client_proto::Operation
123+
))),
112124
Opcode::Ping => Ok(NativeOperation::Ping(wire_to_native!(
113125
body.bytes(),
114126
ping_proto::Operation
@@ -189,6 +201,12 @@ impl Convert for ProtobufConverter {
189201
operation,
190202
list_keys_proto::Operation
191203
))),
204+
NativeOperation::ListClients(operation) => Ok(RequestBody::from_bytes(
205+
native_to_wire!(operation, list_clients_proto::Operation),
206+
)),
207+
NativeOperation::DeleteClient(operation) => Ok(RequestBody::from_bytes(
208+
native_to_wire!(operation, delete_client_proto::Operation),
209+
)),
192210
NativeOperation::Ping(operation) => Ok(RequestBody::from_bytes(native_to_wire!(
193211
operation,
194212
ping_proto::Operation
@@ -259,6 +277,14 @@ impl Convert for ProtobufConverter {
259277
body.bytes(),
260278
list_keys_proto::Result
261279
))),
280+
Opcode::ListClients => Ok(NativeResult::ListClients(wire_to_native!(
281+
body.bytes(),
282+
list_clients_proto::Result
283+
))),
284+
Opcode::DeleteClient => Ok(NativeResult::DeleteClient(wire_to_native!(
285+
body.bytes(),
286+
delete_client_proto::Result
287+
))),
262288
Opcode::Ping => Ok(NativeResult::Ping(wire_to_native!(
263289
body.bytes(),
264290
ping_proto::Result
@@ -341,6 +367,14 @@ impl Convert for ProtobufConverter {
341367
result,
342368
list_keys_proto::Result
343369
))),
370+
NativeResult::ListClients(result) => Ok(ResponseBody::from_bytes(native_to_wire!(
371+
result,
372+
list_clients_proto::Result
373+
))),
374+
NativeResult::DeleteClient(result) => Ok(ResponseBody::from_bytes(native_to_wire!(
375+
result,
376+
delete_client_proto::Result
377+
))),
344378
NativeResult::Ping(result) => Ok(ResponseBody::from_bytes(native_to_wire!(
345379
result,
346380
ping_proto::Result

src/requests/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,12 @@ pub enum Opcode {
115115
PsaAeadDecrypt = 0x0012,
116116
/// PsaRawKeyAgreement operation
117117
PsaRawKeyAgreement = 0x0013,
118-
/// ListKeys operations
118+
/// ListKeys operation
119119
ListKeys = 0x001A,
120+
/// ListClients operation
121+
ListClients = 0x001B,
122+
/// DeleteClient operation
123+
DeleteClient = 0x001C,
120124
}
121125

122126
impl Opcode {
@@ -129,6 +133,8 @@ impl Opcode {
129133
Opcode::ListOpcodes => true,
130134
Opcode::ListAuthenticators => true,
131135
Opcode::ListKeys => true,
136+
Opcode::ListClients => true,
137+
Opcode::DeleteClient => true,
132138
Opcode::PsaGenerateKey => false,
133139
Opcode::PsaDestroyKey => false,
134140
Opcode::PsaSignHash => false,

0 commit comments

Comments
 (0)