Skip to content

Commit 878c45d

Browse files
authored
Merge pull request #53 from joechrisellis/add-list-keys
Add ListKeys support
2 parents 1604a59 + d8d630b commit 878c45d

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ mockstream = "0.0.3"
2626
[features]
2727
testing = ["parsec-interface/testing", "no-fs-permission-check"]
2828
no-fs-permission-check = []
29+
30+
[patch.crates-io]
31+
parsec-interface = { git = "https://github.com/parallaxsecond/parsec-interface-rs.git", rev = "ce3590dc0cb7f345f328fec0dc22073da1b4699c" }

src/core/basic_client.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::error::{ClientErrorKind, Error, Result};
77
use parsec_interface::operations::list_authenticators::{
88
AuthenticatorInfo, Operation as ListAuthenticators,
99
};
10+
use parsec_interface::operations::list_keys::{KeyInfo, Operation as ListKeys};
1011
use parsec_interface::operations::list_opcodes::Operation as ListOpcodes;
1112
use parsec_interface::operations::list_providers::{Operation as ListProviders, ProviderInfo};
1213
use parsec_interface::operations::ping::Operation as Ping;
@@ -271,6 +272,22 @@ impl BasicClient {
271272
}
272273
}
273274

275+
/// **[Core Operation]** List all keys belonging to the application.
276+
pub fn list_keys(&self) -> Result<Vec<KeyInfo>> {
277+
let res = self.op_client.process_operation(
278+
NativeOperation::ListKeys(ListKeys {}),
279+
ProviderID::Core,
280+
&self.auth_data,
281+
)?;
282+
if let NativeResult::ListKeys(res) = res {
283+
Ok(res.keys)
284+
} else {
285+
// Should really not be reached given the checks we do, but it's not impossible if some
286+
// changes happen in the interface
287+
Err(Error::Client(ClientErrorKind::InvalidServiceResponseType))
288+
}
289+
}
290+
274291
/// **[Core Operation]** Send a ping request to the service.
275292
///
276293
/// This operation is intended for testing connectivity to the

src/core/testing/core_tests.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::error::{ClientErrorKind, Error};
66
use crate::BasicClient;
77
use mockstream::{FailingMockStream, MockStream};
88
use parsec_interface::operations;
9+
use parsec_interface::operations::list_keys::KeyInfo;
910
use parsec_interface::operations::list_providers::{ProviderInfo, Uuid};
1011
use parsec_interface::operations::psa_algorithm::*;
1112
use parsec_interface::operations::psa_key_attributes::*;
@@ -118,6 +119,57 @@ fn list_opcodes_test() {
118119
assert!(opcodes.contains(&Opcode::PsaGenerateKey) && opcodes.contains(&Opcode::PsaDestroyKey));
119120
}
120121

122+
#[test]
123+
fn list_keys_test() {
124+
use parsec_interface::operations::psa_key_attributes::{
125+
Attributes, Lifetime, Policy, Type, UsageFlags,
126+
};
127+
128+
let mut client: TestBasicClient = Default::default();
129+
let mut key_info = Vec::new();
130+
key_info.push(KeyInfo {
131+
provider_id: ProviderID::MbedCrypto,
132+
name: String::from("Foo"),
133+
attributes: Attributes {
134+
lifetime: Lifetime::Persistent,
135+
key_type: Type::RsaKeyPair,
136+
bits: 1024,
137+
policy: Policy {
138+
usage_flags: UsageFlags {
139+
export: true,
140+
copy: true,
141+
cache: true,
142+
encrypt: true,
143+
decrypt: true,
144+
sign_message: true,
145+
verify_message: true,
146+
sign_hash: true,
147+
verify_hash: true,
148+
derive: true,
149+
},
150+
permitted_algorithms: Algorithm::AsymmetricSignature(
151+
AsymmetricSignature::RsaPkcs1v15Sign {
152+
hash_alg: Hash::Sha256.into(),
153+
},
154+
),
155+
},
156+
},
157+
});
158+
159+
client.set_mock_read(&get_response_bytes_from_result(NativeResult::ListKeys(
160+
operations::list_keys::Result { keys: key_info },
161+
)));
162+
163+
let keys = client.list_keys().expect("Failed to list keys");
164+
// Check request:
165+
// ListKeys request is empty so no checking to be done
166+
167+
// Check response:
168+
assert_eq!(keys.len(), 1);
169+
assert_eq!(keys[0].name, "Foo");
170+
assert_eq!(keys[0].provider_id, ProviderID::MbedCrypto);
171+
}
172+
121173
#[test]
122174
fn no_crypto_provider_test() {
123175
let client = BasicClient::new(AuthenticationData::AppIdentity(Secret::new(String::from(

0 commit comments

Comments
 (0)