Skip to main content

nethsm/cli/command/
random.rs

1use std::path::PathBuf;
2
3use clap::Parser;
4use expression_format::ex_format;
5
6use crate::UserRole::Operator;
7
8/// The "nethsm random" command.
9#[derive(Debug, Parser)]
10#[command(
11    about = "Get random bytes from a device",
12    long_about = ex_format!("Get random bytes from a device
13
14Unless a specific output file is chosen, writes a given number of random bytes to stdout.
15
16Requires authentication of a user in the \"{Operator}\" role.")
17)]
18pub struct RandomCommand {
19    /// The number of random bytes to get.
20    #[arg(
21        env = "NETHSM_RANDOM_LENGTH",
22        help = "The number of random bytes to return"
23    )]
24    pub length: u32,
25
26    /// Whether to override the output file if it exists.
27    #[arg(
28        env = "NETHSM_FORCE",
29        help = "Write to output file even if it exists already",
30        long,
31        short
32    )]
33    pub force: bool,
34
35    /// The optional path to an output file.
36    #[arg(
37        env = "NETHSM_RANDOM_OUTPUT_FILE",
38        help = "The optional path to a specific output file",
39        long,
40        short
41    )]
42    pub output: Option<PathBuf>,
43}