Skip to content
This repository was archived by the owner on Mar 12, 2026. It is now read-only.

Commit df9b845

Browse files
committed
fix: update KMS repo
1 parent 704136e commit df9b845

11 files changed

Lines changed: 75 additions & 43 deletions

File tree

crate/cli/src/tests/kms/attributes/get.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::{collections::HashMap, process::Command};
22

33
use assert_cmd::cargo::CommandCargoExt;
4+
use clap::ValueEnum;
45
use cosmian_kms_cli::reexport::cosmian_kms_client::{
56
kmip_2_1::kmip_types::Tag, reexport::cosmian_kms_client_utils::attributes_utils::CLinkType,
67
};
@@ -46,7 +47,12 @@ pub(crate) fn get_attributes(
4647

4748
for link_type in attribute_link_types {
4849
args.push("--link-type".to_owned());
49-
args.push(link_type.to_string());
50+
let name = link_type
51+
.to_possible_value()
52+
.expect("valid CLinkType")
53+
.get_name()
54+
.to_string();
55+
args.push(name);
5056
}
5157

5258
let mut cmd = Command::cargo_bin(PROG_NAME)?;

crate/cli/src/tests/kms/certificates/certify.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::{path::PathBuf, process::Command};
22

33
use assert_cmd::cargo::CommandCargoExt;
4+
use clap::ValueEnum;
45
use cosmian_kms_cli::reexport::cosmian_kms_client::{
56
cosmian_kmip::{
67
kmip_2_1::{kmip_objects::Object, kmip_types::LinkType},
@@ -91,7 +92,12 @@ pub(crate) fn certify(cli_conf_path: &str, certify_op: CertifyOp) -> CosmianResu
9192
}
9293
if let Some(algorithm) = certify_op.algorithm {
9394
args.push("--algorithm".to_owned());
94-
args.push(algorithm.to_string());
95+
let name = algorithm
96+
.to_possible_value()
97+
.expect("valid Algorithm")
98+
.get_name()
99+
.to_string();
100+
args.push(name);
95101
}
96102
if let Some(certificate_id) = certify_op.certificate_id {
97103
args.push("--certificate-id".to_owned());

crate/cli/src/tests/kms/derive_key/derive_key_tests.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::process::Command;
22

33
use assert_cmd::prelude::*;
4+
use clap::ValueEnum;
45
use cosmian_kms_cli::{
56
actions::kms::{
67
derive_key::DeriveKeyAction, mac::CHashingAlgorithm,
@@ -43,7 +44,12 @@ pub(crate) fn derive_key(cli_conf_path: &str, action: DeriveKeyAction) -> Cosmia
4344
let mut args: Vec<String> = vec![
4445
// Algorithm and length are explicit to avoid relying on defaults
4546
"--algorithm".to_owned(),
46-
action.algorithm.to_string(),
47+
action
48+
.algorithm
49+
.to_possible_value()
50+
.expect("possible value")
51+
.get_name()
52+
.to_string(),
4753
"--length".to_owned(),
4854
action.cryptographic_length.to_string(),
4955
"--derivation-method".to_owned(),

crate/cli/src/tests/kms/elliptic_curve/sign_verify.rs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,7 @@ fn ec_sign(
2929
let mut cmd = Command::cargo_bin(PROG_NAME)?;
3030
cmd.env(COSMIAN_CLI_CONF_ENV, cli_conf_path);
3131

32-
let mut args = vec![
33-
"sign",
34-
input_file,
35-
"--key-id",
36-
key_id,
37-
"-s",
38-
"ecdsa-with-sha256",
39-
];
32+
let mut args = vec!["sign", input_file, "--key-id", key_id];
4033
if digested {
4134
args.push("--digested");
4235
}
@@ -69,15 +62,7 @@ fn ec_sign_verify(
6962
let mut cmd = Command::cargo_bin(PROG_NAME)?;
7063
cmd.env(COSMIAN_CLI_CONF_ENV, cli_conf_path);
7164

72-
let mut args = vec![
73-
"sign-verify",
74-
data_file,
75-
signature_file,
76-
"--key-id",
77-
key_id,
78-
"-s",
79-
"ecdsa-with-sha256",
80-
];
65+
let mut args = vec!["sign-verify", data_file, signature_file, "--key-id", key_id];
8166
if digested {
8267
args.push("--digested");
8368
}

crate/cli/src/tests/kms/rsa/encrypt_decrypt.rs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::{collections::HashSet, fs, path::PathBuf, process::Command};
22

33
use assert_cmd::prelude::*;
4+
use clap::ValueEnum;
45
use cosmian_kms_cli::reexport::cosmian_kms_client::{
56
read_bytes_from_file,
67
reexport::cosmian_kms_client_utils::rsa_utils::{HashFn, RsaEncryptionAlgorithm},
@@ -43,9 +44,20 @@ pub(crate) fn encrypt(
4344
args.push("--key-id");
4445
args.push(public_key_id);
4546
args.push("--encryption-algorithm");
46-
let encryption_algorithm = encryption_algorithm.to_string();
47+
let encryption_algorithm = encryption_algorithm
48+
.to_possible_value()
49+
.expect("valid RSA algorithm")
50+
.get_name()
51+
.to_string();
4752
args.push(&encryption_algorithm);
48-
let hash_fn_s = hash_fn.map(|h| h.to_string()).unwrap_or_default();
53+
let hash_fn_s = hash_fn
54+
.map(|h| {
55+
h.to_possible_value()
56+
.expect("valid hash")
57+
.get_name()
58+
.to_string()
59+
})
60+
.unwrap_or_default();
4961
if hash_fn.is_some() {
5062
args.push("--hashing-algorithm");
5163
args.push(&hash_fn_s);
@@ -81,9 +93,20 @@ pub(crate) fn decrypt(
8193

8294
let mut args = vec!["decrypt", input_file, "--key-id", private_key_id];
8395
args.push("--encryption-algorithm");
84-
let encryption_algorithm = encryption_algorithm.to_string();
96+
let encryption_algorithm = encryption_algorithm
97+
.to_possible_value()
98+
.expect("valid RSA algorithm")
99+
.get_name()
100+
.to_string();
85101
args.push(&encryption_algorithm);
86-
let hash_fn_str = hash_fn.map(|h| h.to_string()).unwrap_or_default();
102+
let hash_fn_str = hash_fn
103+
.map(|h| {
104+
h.to_possible_value()
105+
.expect("valid hash")
106+
.get_name()
107+
.to_string()
108+
})
109+
.unwrap_or_default();
87110
if hash_fn.is_some() {
88111
args.push("--hashing-algorithm");
89112
args.push(&hash_fn_str);

crate/cli/src/tests/kms/rsa/sign_verify.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn rsa_sign(
3030
let mut cmd = Command::cargo_bin(PROG_NAME)?;
3131
cmd.env(COSMIAN_CLI_CONF_ENV, cli_conf_path);
3232

33-
let mut args = vec!["sign", input_file, "--key-id", key_id, "-s", "rsassapss"];
33+
let mut args = vec!["sign", input_file, "--key-id", key_id];
3434
if digested {
3535
args.push("--digested");
3636
}
@@ -63,15 +63,7 @@ fn rsa_sign_verify(
6363
let mut cmd = Command::cargo_bin(PROG_NAME)?;
6464
cmd.env(COSMIAN_CLI_CONF_ENV, cli_conf_path);
6565

66-
let mut args = vec![
67-
"sign-verify",
68-
data_file,
69-
signature_file,
70-
"--key-id",
71-
key_id,
72-
"-s",
73-
"rsassapss",
74-
];
66+
let mut args = vec!["sign-verify", data_file, signature_file, "--key-id", key_id];
7567
if digested {
7668
args.push("--digested");
7769
}

crate/cli/src/tests/kms/shared/export.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::path::Path;
33
use std::process::Command;
44

55
use assert_cmd::prelude::*;
6+
use clap::ValueEnum;
67
#[cfg(feature = "non-fips")]
78
use cosmian_kms_cli::reexport::cosmian_kms_client::{
89
kmip_0::kmip_types::BlockCipherMode,
@@ -102,7 +103,12 @@ pub(crate) fn export_key(params: ExportKeyParams) -> CosmianResult<()> {
102103
}
103104
if let Some(wrapping_algorithm) = &params.wrapping_algorithm {
104105
args.push("--wrapping-algorithm".to_owned());
105-
args.push(wrapping_algorithm.to_string());
106+
let name = wrapping_algorithm
107+
.to_possible_value()
108+
.expect("valid wrapping algorithm")
109+
.get_name()
110+
.to_string();
111+
args.push(name);
106112
}
107113

108114
let mut cmd = Command::cargo_bin(PROG_NAME)?;

crate/cli/src/tests/kms/shared/export_import.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub(crate) async fn test_wrap_on_export_unwrap_on_import() -> CosmianResult<()>
3939

4040
// Export and import the key with different block cipher modes
4141
for wrapping_algorithm in [WrappingAlgorithm::AesGCM, WrappingAlgorithm::NistKeyWrap] {
42-
debug!("wrapping algorithm: {wrapping_algorithm}",);
42+
debug!("wrapping algorithm: {:?}", wrapping_algorithm);
4343
export_key(ExportKeyParams {
4444
cli_conf_path: user_client_conf_path.clone(),
4545
sub_command: "sym".to_owned(),

crate/cli/src/tests/kms/shared/locate.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ pub(crate) async fn test_locate_cover_crypt() -> CosmianResult<()> {
103103
assert!(ids.contains(&master_private_key_id));
104104
assert!(ids.contains(&master_public_key_id));
105105

106-
// Locate with cryptographic algorithm
107-
// this should be case insensitive
106+
// Locate with cryptographic algorithm (CLI expects lowercase names)
108107
let ids = locate(
109108
&owner_client_conf_path,
110109
Some(&["test_cc"]),
@@ -345,7 +344,7 @@ pub(crate) async fn test_locate_symmetric_key() -> CosmianResult<()> {
345344
let ids = locate(
346345
&owner_client_conf_path,
347346
Some(&["test_sym"]),
348-
Some("Aes"),
347+
Some("aes"),
349348
None,
350349
None,
351350
)?;
@@ -363,11 +362,11 @@ pub(crate) async fn test_locate_symmetric_key() -> CosmianResult<()> {
363362
assert_eq!(ids.len(), 1);
364363
assert!(ids.contains(&key_id));
365364

366-
//locate using tags and cryptographic algorithm and key format type
365+
// locate using tags and cryptographic algorithm and key format type
367366
let ids = locate(
368367
&owner_client_conf_path,
369368
Some(&["test_sym"]),
370-
Some("AES"),
369+
Some("aes"),
371370
None,
372371
Some("TransparentSymmetricKey"),
373372
)?;

crate/cli/src/tests/kms/symmetric/create_key.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::process::Command;
22

33
use assert_cmd::prelude::*;
44
use base64::{Engine as _, engine::general_purpose};
5+
use clap::ValueEnum;
56
use cosmian_kms_cli::{
67
actions::kms::symmetric::keys::create_key::CreateKeyAction,
78
reexport::{
@@ -45,7 +46,15 @@ pub(crate) fn create_symmetric_key(
4546
if let Some(wrap_key_b64) = action.wrap_key_b64.clone() {
4647
args.extend(vec!["--bytes-b64".to_owned(), wrap_key_b64]);
4748
}
48-
args.extend(vec!["--algorithm".to_owned(), action.algorithm.to_string()]);
49+
args.extend(vec![
50+
"--algorithm".to_owned(),
51+
action
52+
.algorithm
53+
.to_possible_value()
54+
.expect("possible value")
55+
.get_name()
56+
.to_string(),
57+
]);
4958

5059
// add tags
5160
for tag in action.tags {

0 commit comments

Comments
 (0)