|
1 | 1 | use std::{collections::HashSet, fs, path::PathBuf, process::Command}; |
2 | 2 |
|
3 | 3 | use assert_cmd::prelude::*; |
| 4 | +use clap::ValueEnum; |
4 | 5 | use cosmian_kms_cli::reexport::cosmian_kms_client::{ |
5 | 6 | read_bytes_from_file, |
6 | 7 | reexport::cosmian_kms_client_utils::rsa_utils::{HashFn, RsaEncryptionAlgorithm}, |
@@ -43,9 +44,20 @@ pub(crate) fn encrypt( |
43 | 44 | args.push("--key-id"); |
44 | 45 | args.push(public_key_id); |
45 | 46 | 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(); |
47 | 52 | 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(); |
49 | 61 | if hash_fn.is_some() { |
50 | 62 | args.push("--hashing-algorithm"); |
51 | 63 | args.push(&hash_fn_s); |
@@ -81,9 +93,20 @@ pub(crate) fn decrypt( |
81 | 93 |
|
82 | 94 | let mut args = vec!["decrypt", input_file, "--key-id", private_key_id]; |
83 | 95 | 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(); |
85 | 101 | 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(); |
87 | 110 | if hash_fn.is_some() { |
88 | 111 | args.push("--hashing-algorithm"); |
89 | 112 | args.push(&hash_fn_str); |
|
0 commit comments