Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions sw/host/hsmtool/src/commands/aes/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

use anyhow::Result;
use anyhow::{Result, anyhow};
use cryptoki::session::Session;
use serde::{Deserialize, Serialize};
use std::any::Any;
Expand All @@ -25,7 +25,7 @@ pub struct Export {
#[arg(long)]
wrap: Option<String>,
#[arg(long, default_value = "rsa-pkcs")]
wrap_mechanism: Wrap,
wrap_mechanism: Option<Wrap>,
#[arg(short, long)]
output: Option<PathBuf>,
}
Expand All @@ -44,7 +44,14 @@ impl Dispatch for Export {

let secret = Secret::Aes;
let key = if self.wrap.is_some() {
secret.wrap_key(session, object, self.wrap.as_deref(), &self.wrap_mechanism)?
secret.wrap_key(
session,
object,
self.wrap.as_deref(),
self.wrap_mechanism
.as_ref()
.ok_or(anyhow!("wrap_mechanism is required when wrap is specified"))?,
)?
} else {
secret.export(session, object)?
};
Expand Down
8 changes: 5 additions & 3 deletions sw/host/hsmtool/src/commands/aes/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

use anyhow::Result;
use anyhow::{Context, Result};
use cryptoki::session::Session;
use serde::{Deserialize, Serialize};
use std::any::Any;
Expand All @@ -28,7 +28,7 @@ pub struct Import {
#[arg(long)]
unwrap: Option<String>,
#[arg(long, default_value = "rsa-pkcs")]
unwrap_mechanism: Wrap,
unwrap_mechanism: Option<Wrap>,
filename: PathBuf,
}

Expand Down Expand Up @@ -61,7 +61,9 @@ impl Dispatch for Import {
key,
self.template.clone(),
self.unwrap.as_deref(),
&self.unwrap_mechanism,
self.unwrap_mechanism
.as_ref()
.context("unwrap_mechanism is required when unwrap is specified")?,
)?;
} else {
let _object = secret.import(
Expand Down
13 changes: 10 additions & 3 deletions sw/host/hsmtool/src/commands/kdf/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::any::Any;
use std::fs;
use std::path::PathBuf;

use anyhow::Result;
use anyhow::{Result, anyhow};
use cryptoki::session::Session;
use serde::{Deserialize, Serialize};

Expand All @@ -27,7 +27,7 @@ pub struct Export {
#[arg(long)]
wrap: Option<String>,
#[arg(long, default_value = "rsa-pkcs")]
wrap_mechanism: Wrap,
wrap_mechanism: Option<Wrap>,
#[arg(short, long)]
output: Option<PathBuf>,
}
Expand All @@ -46,7 +46,14 @@ impl Dispatch for Export {

let secret = Secret::GenericSecret;
let key = if self.wrap.is_some() {
secret.wrap_key(session, object, self.wrap.as_deref(), &self.wrap_mechanism)?
secret.wrap_key(
session,
object,
self.wrap.as_deref(),
self.wrap_mechanism
.as_ref()
.ok_or(anyhow!("wrap_mechanism is required when wrap is specified"))?,
)?
} else {
secret.export(session, object)?
};
Expand Down
8 changes: 5 additions & 3 deletions sw/host/hsmtool/src/commands/kdf/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::any::Any;
use std::fs;
use std::path::PathBuf;

use anyhow::Result;
use anyhow::{Result, anyhow};
use cryptoki::session::Session;
use serde::{Deserialize, Serialize};

Expand All @@ -30,7 +30,7 @@ pub struct Import {
#[arg(long)]
unwrap: Option<String>,
#[arg(long, default_value = "rsa-pkcs")]
unwrap_mechanism: Wrap,
unwrap_mechanism: Option<Wrap>,
filename: PathBuf,
}

Expand Down Expand Up @@ -63,7 +63,9 @@ impl Dispatch for Import {
key,
self.template.clone(),
self.unwrap.as_deref(),
&self.unwrap_mechanism,
self.unwrap_mechanism.as_ref().ok_or(anyhow!(
"unwrap_mechanism is required when unwrap is specified"
))?,
)?;
} else {
let _object = secret.import(
Expand Down
Loading