-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrypto.rs
More file actions
99 lines (89 loc) · 2.13 KB
/
crypto.rs
File metadata and controls
99 lines (89 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//! Cryptographic operation commands
use anyhow::Result;
use super::common::{get_user_pin, CommandContext};
pub fn handle_sign(
ctx: CommandContext,
label: Option<String>,
user_pin: Option<String>,
key_label: String,
input: String,
output: String,
json: bool,
pin_stdin: bool,
) -> Result<()> {
let token_label = ctx.token_label(label)?;
let user_pin_value = get_user_pin(user_pin, pin_stdin)?;
rust_hsm_core::keys::sign(
&ctx.module_path,
&token_label,
&user_pin_value,
&key_label,
&input,
&output,
json,
ctx.config.observe_enabled,
&ctx.config.observe_log_file,
)
}
pub fn handle_verify(
ctx: CommandContext,
label: Option<String>,
user_pin: Option<String>,
key_label: String,
input: String,
signature: String,
json: bool,
pin_stdin: bool,
) -> Result<()> {
let token_label = ctx.token_label(label)?;
let user_pin_value = get_user_pin(user_pin, pin_stdin)?;
rust_hsm_core::keys::verify(
&ctx.module_path,
&token_label,
&user_pin_value,
&key_label,
&input,
&signature,
json,
)
}
pub fn handle_encrypt(
ctx: CommandContext,
label: Option<String>,
user_pin: Option<String>,
key_label: String,
input: String,
output: String,
pin_stdin: bool,
) -> Result<()> {
let token_label = ctx.token_label(label)?;
let user_pin_value = get_user_pin(user_pin, pin_stdin)?;
rust_hsm_core::keys::encrypt(
&ctx.module_path,
&token_label,
&user_pin_value,
&key_label,
&input,
&output,
)
}
pub fn handle_decrypt(
ctx: CommandContext,
label: Option<String>,
user_pin: Option<String>,
key_label: String,
input: String,
output: String,
pin_stdin: bool,
) -> Result<()> {
let token_label = ctx.token_label(label)?;
let user_pin_value = get_user_pin(user_pin, pin_stdin)?;
rust_hsm_core::keys::decrypt(
&ctx.module_path,
&token_label,
&user_pin_value,
&key_label,
&input,
&output,
)
}