Skip to content

Commit 91a72e8

Browse files
authored
Merge pull request #29 from hug-dev/new-interface
Import the new interface
2 parents 3ea9050 + 7f691cc commit 91a72e8

File tree

3 files changed

+31
-28
lines changed

3 files changed

+31
-28
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ edition = "2018"
1313
documentation = "https://docs.rs/crate/parsec-client"
1414

1515
[dependencies]
16-
parsec-interface = "0.14.0"
16+
parsec-interface = { git = "https://github.com/parallaxsecond/parsec-interface-rs" }
1717
num = "0.2.1"
1818
rand = "0.7.3"
1919
log = "0.4.8"

src/core/basic_client.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use parsec_interface::operations::psa_destroy_key::Operation as PsaDestroyKey;
1212
use parsec_interface::operations::psa_export_public_key::Operation as PsaExportPublicKey;
1313
use parsec_interface::operations::psa_generate_key::Operation as PsaGenerateKey;
1414
use parsec_interface::operations::psa_import_key::Operation as PsaImportKey;
15-
use parsec_interface::operations::psa_key_attributes::KeyAttributes;
15+
use parsec_interface::operations::psa_key_attributes::Attributes;
1616
use parsec_interface::operations::psa_sign_hash::Operation as PsaSignHash;
1717
use parsec_interface::operations::psa_verify_hash::Operation as PsaVerifyHash;
1818
use parsec_interface::operations::{NativeOperation, NativeResult};
@@ -117,23 +117,24 @@ use std::collections::HashSet;
117117
///# use parsec_client::core::interface::requests::ProviderID;
118118
///# let client: BasicClient = BasicClient::new(AuthenticationData::AppIdentity(String::from("app-name")));
119119
///use parsec_client::core::interface::operations::psa_algorithm::{Algorithm, AsymmetricSignature, Hash};
120-
///use parsec_client::core::interface::operations::psa_key_attributes::{KeyAttributes, KeyPolicy, KeyType, UsageFlags};
120+
///use parsec_client::core::interface::operations::psa_key_attributes::{Attributes, Lifetime, Policy, Type, UsageFlags};
121121
///
122122
///let key_name = String::from("rusty key 🔑");
123123
///// This algorithm identifier will be used within the key policy (i.e. what
124124
///// algorithms are usable with the key) and for indicating the desired
125125
///// algorithm for each operation involving the key.
126126
///let asym_sign_algo = AsymmetricSignature::RsaPkcs1v15Sign {
127-
/// hash_alg: Hash::Sha256,
127+
/// hash_alg: Hash::Sha256.into(),
128128
///};
129129
///
130130
///// The key attributes define and limit the usage of the key material stored
131131
///// by the underlying cryptographic provider.
132-
///let key_attrs = KeyAttributes {
133-
/// key_type: KeyType::RsaKeyPair,
134-
/// key_bits: 2048,
135-
/// key_policy: KeyPolicy {
136-
/// key_usage_flags: UsageFlags {
132+
///let key_attrs = Attributes {
133+
/// lifetime: Lifetime::Persistent,
134+
/// key_type: Type::RsaKeyPair,
135+
/// bits: 2048,
136+
/// policy: Policy {
137+
/// usage_flags: UsageFlags {
137138
/// export: true,
138139
/// copy: true,
139140
/// cache: true,
@@ -145,7 +146,7 @@ use std::collections::HashSet;
145146
/// verify_hash: false,
146147
/// derive: false,
147148
/// },
148-
/// key_algorithm: asym_sign_algo.into(),
149+
/// permitted_algorithms: asym_sign_algo.into(),
149150
/// },
150151
///};
151152
///
@@ -276,7 +277,7 @@ impl BasicClient {
276277
///
277278
/// See the operation-specific response codes returned by the service
278279
/// [here](https://parallaxsecond.github.io/parsec-book/parsec_client/operations/psa_generate_key.html#specific-response-status-codes).
279-
pub fn psa_generate_key(&self, key_name: String, key_attributes: KeyAttributes) -> Result<()> {
280+
pub fn psa_generate_key(&self, key_name: String, key_attributes: Attributes) -> Result<()> {
280281
let crypto_provider = self.can_provide_crypto()?;
281282

282283
let op = PsaGenerateKey {
@@ -356,7 +357,7 @@ impl BasicClient {
356357
&self,
357358
key_name: String,
358359
key_material: Vec<u8>,
359-
key_attributes: KeyAttributes,
360+
key_attributes: Attributes,
360361
) -> Result<()> {
361362
let crypto_provider = self.can_provide_crypto()?;
362363

@@ -415,7 +416,7 @@ impl BasicClient {
415416
/// **[Cryptographic Operation]** Create an asymmetric signature on a pre-computed message digest.
416417
///
417418
/// The key intended for signing **must** have its `sign_hash` flag set
418-
/// to `true` in its [key policy](https://docs.rs/parsec-interface/*/parsec_interface/operations/psa_key_attributes/struct.KeyPolicy.html).
419+
/// to `true` in its [key policy](https://docs.rs/parsec-interface/*/parsec_interface/operations/psa_key_attributes/struct.Policy.html).
419420
///
420421
/// The signature will be created with the algorithm defined in
421422
/// `sign_algorithm`, but only after checking that the key policy
@@ -466,7 +467,7 @@ impl BasicClient {
466467
/// **[Cryptographic Operation]** Verify an existing asymmetric signature over a pre-computed message digest.
467468
///
468469
/// The key intended for signing **must** have its `verify_hash` flag set
469-
/// to `true` in its [key policy](https://docs.rs/parsec-interface/*/parsec_interface/operations/psa_key_attributes/struct.KeyPolicy.html).
470+
/// to `true` in its [key policy](https://docs.rs/parsec-interface/*/parsec_interface/operations/psa_key_attributes/struct.Policy.html).
470471
///
471472
/// The signature will be verifyied with the algorithm defined in
472473
/// `sign_algorithm`, but only after checking that the key policy

src/core/testing/core_tests.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,12 @@ fn psa_generate_key_test() {
146146
NativeResult::PsaGenerateKey(operations::psa_generate_key::Result {}),
147147
));
148148
let key_name = String::from("key-name");
149-
let key_attrs = KeyAttributes {
150-
key_type: KeyType::Aes,
151-
key_bits: 192,
152-
key_policy: KeyPolicy {
153-
key_usage_flags: UsageFlags {
149+
let key_attrs = Attributes {
150+
lifetime: Lifetime::Persistent,
151+
key_type: Type::Aes,
152+
bits: 192,
153+
policy: Policy {
154+
usage_flags: UsageFlags {
154155
export: true,
155156
copy: true,
156157
cache: true,
@@ -162,7 +163,7 @@ fn psa_generate_key_test() {
162163
verify_hash: false,
163164
derive: false,
164165
},
165-
key_algorithm: Algorithm::Cipher(Cipher::Ctr),
166+
permitted_algorithms: Algorithm::Cipher(Cipher::Ctr),
166167
},
167168
};
168169

@@ -213,11 +214,12 @@ fn psa_import_key_test() {
213214
operations::psa_import_key::Result {},
214215
)));
215216
let key_name = String::from("key-name");
216-
let key_attrs = KeyAttributes {
217-
key_type: KeyType::Aes,
218-
key_bits: 192,
219-
key_policy: KeyPolicy {
220-
key_usage_flags: UsageFlags {
217+
let key_attrs = Attributes {
218+
lifetime: Lifetime::Persistent,
219+
key_type: Type::Aes,
220+
bits: 192,
221+
policy: Policy {
222+
usage_flags: UsageFlags {
221223
export: true,
222224
copy: true,
223225
cache: true,
@@ -229,7 +231,7 @@ fn psa_import_key_test() {
229231
verify_hash: false,
230232
derive: false,
231233
},
232-
key_algorithm: Algorithm::Cipher(Cipher::Ctr),
234+
permitted_algorithms: Algorithm::Cipher(Cipher::Ctr),
233235
},
234236
};
235237
let key_data = vec![0xff_u8; 128];
@@ -285,7 +287,7 @@ fn psa_sign_hash_test() {
285287
let hash = vec![0x77_u8; 32];
286288
let key_name = String::from("key_name");
287289
let sign_algorithm = AsymmetricSignature::Ecdsa {
288-
hash_alg: Hash::Sha256,
290+
hash_alg: Hash::Sha256.into(),
289291
};
290292
let signature = vec![0x33_u8; 128];
291293
client.set_mock_read(&get_response_bytes_from_result(NativeResult::PsaSignHash(
@@ -319,7 +321,7 @@ fn verify_hash_test() {
319321
let hash = vec![0x77_u8; 32];
320322
let key_name = String::from("key_name");
321323
let sign_algorithm = AsymmetricSignature::Ecdsa {
322-
hash_alg: Hash::Sha256,
324+
hash_alg: Hash::Sha256.into(),
323325
};
324326
let signature = vec![0x33_u8; 128];
325327
client.set_mock_read(&get_response_bytes_from_result(

0 commit comments

Comments
 (0)