Skip to content

Commit

Permalink
[opentitantool] Eliminate use of min_specialization
Browse files Browse the repository at this point in the history
Update serde_annotate to 0.0.12 and change all uses of `dyn Annotate`
to `dyn erased_serde::Serialize`.

Signed-off-by: Chris Frantz <cfrantz@google.com>
  • Loading branch information
cfrantz committed Jan 23, 2025
1 parent ddf9115 commit 46ddf12
Show file tree
Hide file tree
Showing 77 changed files with 185 additions and 240 deletions.
1 change: 1 addition & 0 deletions sw/host/hsmtool/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ rust_library(
"@crate_index//:der",
"@crate_index//:directories",
"@crate_index//:ecdsa",
"@crate_index//:erased-serde",
"@crate_index//:hex",
"@crate_index//:indexmap",
"@crate_index//:log",
Expand Down
3 changes: 1 addition & 2 deletions sw/host/hsmtool/src/commands/ecdsa/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use cryptoki::object::{Attribute, ObjectHandle};
use cryptoki::session::Session;
use p256::ecdsa::{SigningKey, VerifyingKey};
use serde::{Deserialize, Serialize};
use serde_annotate::Annotate;
use std::any::Any;
use std::path::PathBuf;

Expand Down Expand Up @@ -74,7 +73,7 @@ impl Dispatch for Export {
_context: &dyn Any,
_hsm: &Module,
session: Option<&Session>,
) -> Result<Box<dyn Annotate>> {
) -> Result<Box<dyn erased_serde::Serialize>> {
let session = session.ok_or(HsmError::SessionRequired)?;
let mut attrs = helper::search_spec(self.id.as_deref(), self.label.as_deref())?;
attrs.push(Attribute::KeyType(KeyType::Ec.try_into()?));
Expand Down
3 changes: 1 addition & 2 deletions sw/host/hsmtool/src/commands/ecdsa/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use cryptoki::session::Session;
use p256::elliptic_curve::pkcs8;
use p256::elliptic_curve::pkcs8::der::Encode;
use serde::{Deserialize, Serialize};
use serde_annotate::Annotate;
use std::any::Any;
use std::str::FromStr;

Expand Down Expand Up @@ -64,7 +63,7 @@ impl Dispatch for Generate {
_context: &dyn Any,
_hsm: &Module,
session: Option<&Session>,
) -> Result<Box<dyn Annotate>> {
) -> Result<Box<dyn erased_serde::Serialize>> {
let session = session.ok_or(HsmError::SessionRequired)?;
helper::no_object_exists(session, self.id.as_deref(), self.label.as_deref())?;
let id = AttrData::Str(self.id.as_ref().cloned().unwrap_or_else(helper::random_id));
Expand Down
3 changes: 1 addition & 2 deletions sw/host/hsmtool/src/commands/ecdsa/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use anyhow::{bail, Context, Result};
use cryptoki::object::Attribute;
use cryptoki::session::Session;
use serde::{Deserialize, Serialize};
use serde_annotate::Annotate;
use std::any::Any;
use std::path::PathBuf;
use std::str::FromStr;
Expand Down Expand Up @@ -76,7 +75,7 @@ impl Dispatch for Import {
_context: &dyn Any,
_hsm: &Module,
session: Option<&Session>,
) -> Result<Box<dyn Annotate>> {
) -> Result<Box<dyn erased_serde::Serialize>> {
let session = session.ok_or(HsmError::SessionRequired)?;
helper::no_object_exists(session, self.id.as_deref(), self.label.as_deref())?;
let mut public_attrs =
Expand Down
3 changes: 1 addition & 2 deletions sw/host/hsmtool/src/commands/ecdsa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use anyhow::Result;
use cryptoki::session::Session;
use serde::{Deserialize, Serialize};
use serde_annotate::Annotate;
use std::any::Any;

use crate::commands::Dispatch;
Expand Down Expand Up @@ -33,7 +32,7 @@ impl Dispatch for Ecdsa {
context: &dyn Any,
hsm: &Module,
session: Option<&Session>,
) -> Result<Box<dyn Annotate>> {
) -> Result<Box<dyn erased_serde::Serialize>> {
match self {
Ecdsa::Generate(x) => x.run(context, hsm, session),
Ecdsa::Export(x) => x.run(context, hsm, session),
Expand Down
3 changes: 1 addition & 2 deletions sw/host/hsmtool/src/commands/ecdsa/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use anyhow::{anyhow, Result};
use cryptoki::object::Attribute;
use cryptoki::session::Session;
use serde::{Deserialize, Serialize};
use serde_annotate::Annotate;
use std::any::Any;
use std::ops::Range;
use std::path::PathBuf;
Expand Down Expand Up @@ -44,7 +43,7 @@ impl Dispatch for Sign {
_context: &dyn Any,
_hsm: &Module,
session: Option<&Session>,
) -> Result<Box<dyn Annotate>> {
) -> Result<Box<dyn erased_serde::Serialize>> {
let session = session.ok_or(HsmError::SessionRequired)?;
let mut attrs = helper::search_spec(self.id.as_deref(), self.label.as_deref())?;
attrs.push(Attribute::KeyType(KeyType::Ec.try_into()?));
Expand Down
3 changes: 1 addition & 2 deletions sw/host/hsmtool/src/commands/ecdsa/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use anyhow::{anyhow, Result};
use cryptoki::object::Attribute;
use cryptoki::session::Session;
use serde::{Deserialize, Serialize};
use serde_annotate::Annotate;
use std::any::Any;
use std::ops::Range;
use std::path::PathBuf;
Expand Down Expand Up @@ -44,7 +43,7 @@ impl Dispatch for Verify {
_context: &dyn Any,
_hsm: &Module,
session: Option<&Session>,
) -> Result<Box<dyn Annotate>> {
) -> Result<Box<dyn erased_serde::Serialize>> {
let session = session.ok_or(HsmError::SessionRequired)?;
let mut attrs = helper::search_spec(self.id.as_deref(), self.label.as_deref())?;
attrs.push(Attribute::KeyType(KeyType::Ec.try_into()?));
Expand Down
8 changes: 4 additions & 4 deletions sw/host/hsmtool/src/commands/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use anyhow::Result;
use cryptoki::session::Session;
use serde::{Deserialize, Serialize};
use serde_annotate::{Annotate, Document};
use serde_annotate::Document;
use std::any::Any;
use std::path::PathBuf;
use thiserror::Error;
Expand All @@ -18,10 +18,10 @@ pub struct Exec {
file: PathBuf,
}

#[derive(Debug, Serialize)]
#[derive(Serialize)]
pub struct ExecResult {
pub command: String,
pub result: Box<dyn Annotate>,
pub result: Box<dyn erased_serde::Serialize>,
}

#[derive(Debug, Error)]
Expand All @@ -38,7 +38,7 @@ impl Dispatch for Exec {
context: &dyn Any,
hsm: &Module,
session: Option<&Session>,
) -> Result<Box<dyn Annotate>> {
) -> Result<Box<dyn erased_serde::Serialize>> {
let commands = std::fs::read_to_string(&self.file)?;
let commands = serde_annotate::from_str::<Vec<Box<dyn Dispatch>>>(&commands)?;

Expand Down
8 changes: 4 additions & 4 deletions sw/host/hsmtool/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub trait Dispatch {
context: &dyn Any,
hsm: &Module,
session: Option<&Session>,
) -> Result<Box<dyn Annotate>>;
) -> Result<Box<dyn erased_serde::Serialize>>;

fn leaf(&self) -> &dyn Dispatch
where
Expand Down Expand Up @@ -58,7 +58,7 @@ impl Dispatch for Commands {
context: &dyn Any,
hsm: &Module,
session: Option<&Session>,
) -> Result<Box<dyn Annotate>> {
) -> Result<Box<dyn erased_serde::Serialize>> {
match self {
Commands::Ecdsa(x) => x.run(context, hsm, session),
Commands::Exec(x) => x.run(context, hsm, session),
Expand Down Expand Up @@ -122,7 +122,7 @@ impl Default for BasicResult {
}

impl BasicResult {
pub fn from_error(e: &anyhow::Error) -> Box<dyn Annotate> {
pub fn from_error(e: &anyhow::Error) -> Box<dyn erased_serde::Serialize> {
Box::new(BasicResult {
success: false,
id: AttrData::None,
Expand All @@ -145,7 +145,7 @@ pub fn print_result(
format: Format,
color: Option<bool>,
quiet: bool,
result: Result<Box<dyn Annotate>>,
result: Result<Box<dyn erased_serde::Serialize>>,
) -> Result<()> {
let (doc, result) = match result {
Ok(value) => {
Expand Down
3 changes: 1 addition & 2 deletions sw/host/hsmtool/src/commands/object/destroy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use anyhow::Result;
use cryptoki::session::Session;
use serde::{Deserialize, Serialize};
use serde_annotate::Annotate;
use std::any::Any;

use crate::commands::{BasicResult, Dispatch};
Expand All @@ -28,7 +27,7 @@ impl Dispatch for Destroy {
_context: &dyn Any,
_hsm: &Module,
session: Option<&Session>,
) -> Result<Box<dyn Annotate>> {
) -> Result<Box<dyn erased_serde::Serialize>> {
let session = session.ok_or(HsmError::SessionRequired)?;
let attr = helper::search_spec(self.id.as_deref(), self.label.as_deref())?;
let objects = session.find_objects(&attr)?;
Expand Down
3 changes: 1 addition & 2 deletions sw/host/hsmtool/src/commands/object/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use anyhow::Result;
use cryptoki::session::Session;
use serde::{Deserialize, Serialize};
use serde_annotate::Annotate;
use std::any::Any;
use std::str::FromStr;

Expand Down Expand Up @@ -38,7 +37,7 @@ impl Dispatch for List {
_context: &dyn Any,
_hsm: &Module,
session: Option<&Session>,
) -> Result<Box<dyn Annotate>> {
) -> Result<Box<dyn erased_serde::Serialize>> {
let session = session.ok_or(HsmError::SessionRequired)?;
let search = self
.search
Expand Down
3 changes: 1 addition & 2 deletions sw/host/hsmtool/src/commands/object/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use anyhow::Result;
use cryptoki::session::Session;
use serde::{Deserialize, Serialize};
use serde_annotate::Annotate;
use std::any::Any;

use crate::commands::Dispatch;
Expand Down Expand Up @@ -35,7 +34,7 @@ impl Dispatch for Object {
context: &dyn Any,
hsm: &Module,
session: Option<&Session>,
) -> Result<Box<dyn Annotate>> {
) -> Result<Box<dyn erased_serde::Serialize>> {
match self {
Object::Destroy(x) => x.run(context, hsm, session),
Object::List(x) => x.run(context, hsm, session),
Expand Down
3 changes: 1 addition & 2 deletions sw/host/hsmtool/src/commands/object/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use anyhow::Result;
use cryptoki::session::Session;
use serde::{Deserialize, Serialize};
use serde_annotate::Annotate;
use std::any::Any;
use std::path::PathBuf;

Expand Down Expand Up @@ -35,7 +34,7 @@ impl Dispatch for Read {
_context: &dyn Any,
_hsm: &Module,
session: Option<&Session>,
) -> Result<Box<dyn Annotate>> {
) -> Result<Box<dyn erased_serde::Serialize>> {
let session = session.ok_or(HsmError::SessionRequired)?;
let attr = helper::search_spec_ex(
self.id.as_deref(),
Expand Down
3 changes: 1 addition & 2 deletions sw/host/hsmtool/src/commands/object/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use anyhow::Result;
use cryptoki::session::Session;
use serde::{Deserialize, Serialize};
use serde_annotate::Annotate;
use std::any::Any;
use std::collections::HashSet;

Expand Down Expand Up @@ -53,7 +52,7 @@ impl Dispatch for Show {
_context: &dyn Any,
_hsm: &Module,
session: Option<&Session>,
) -> Result<Box<dyn Annotate>> {
) -> Result<Box<dyn erased_serde::Serialize>> {
let session = session.ok_or(HsmError::SessionRequired)?;
let attr = helper::search_spec(self.id.as_deref(), self.label.as_deref())?;
let objects = session.find_objects(&attr)?;
Expand Down
3 changes: 1 addition & 2 deletions sw/host/hsmtool/src/commands/object/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use anyhow::{bail, Result};
use cryptoki::session::Session;
use serde::{Deserialize, Serialize};
use serde_annotate::Annotate;
use std::any::Any;

use crate::commands::Dispatch;
Expand All @@ -31,7 +30,7 @@ impl Dispatch for Update {
_context: &dyn Any,
_hsm: &Module,
session: Option<&Session>,
) -> Result<Box<dyn Annotate>> {
) -> Result<Box<dyn erased_serde::Serialize>> {
let session = session.ok_or(HsmError::SessionRequired)?;
let attr = helper::search_spec(self.id.as_deref(), self.label.as_deref())?;
let objects = session.find_objects(&attr)?;
Expand Down
3 changes: 1 addition & 2 deletions sw/host/hsmtool/src/commands/object/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use anyhow::Result;
use cryptoki::session::Session;
use serde::{Deserialize, Serialize};
use serde_annotate::Annotate;
use std::any::Any;
use std::path::PathBuf;

Expand Down Expand Up @@ -37,7 +36,7 @@ impl Dispatch for Write {
_context: &dyn Any,
_hsm: &Module,
session: Option<&Session>,
) -> Result<Box<dyn Annotate>> {
) -> Result<Box<dyn erased_serde::Serialize>> {
let session = session.ok_or(HsmError::SessionRequired)?;

let mut attr = AttributeMap::default();
Expand Down
3 changes: 1 addition & 2 deletions sw/host/hsmtool/src/commands/rsa/decrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use cryptoki::mechanism::Mechanism;
use cryptoki::object::Attribute;
use cryptoki::session::Session;
use serde::{Deserialize, Serialize};
use serde_annotate::Annotate;
use std::any::Any;
use std::path::PathBuf;

Expand Down Expand Up @@ -35,7 +34,7 @@ impl Dispatch for Decrypt {
_context: &dyn Any,
_hsm: &Module,
session: Option<&Session>,
) -> Result<Box<dyn Annotate>> {
) -> Result<Box<dyn erased_serde::Serialize>> {
let session = session.ok_or(HsmError::SessionRequired)?;
let mut attrs = helper::search_spec(self.id.as_deref(), self.label.as_deref())?;
attrs.push(Attribute::KeyType(KeyType::Rsa.try_into()?));
Expand Down
3 changes: 1 addition & 2 deletions sw/host/hsmtool/src/commands/rsa/encrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use cryptoki::mechanism::Mechanism;
use cryptoki::object::Attribute;
use cryptoki::session::Session;
use serde::{Deserialize, Serialize};
use serde_annotate::Annotate;
use std::any::Any;
use std::path::PathBuf;

Expand Down Expand Up @@ -35,7 +34,7 @@ impl Dispatch for Encrypt {
_context: &dyn Any,
_hsm: &Module,
session: Option<&Session>,
) -> Result<Box<dyn Annotate>> {
) -> Result<Box<dyn erased_serde::Serialize>> {
let session = session.ok_or(HsmError::SessionRequired)?;
let mut attrs = helper::search_spec(self.id.as_deref(), self.label.as_deref())?;
attrs.push(Attribute::KeyType(KeyType::Rsa.try_into()?));
Expand Down
3 changes: 1 addition & 2 deletions sw/host/hsmtool/src/commands/rsa/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use cryptoki::object::{Attribute, ObjectHandle};
use cryptoki::session::Session;
use rsa::{RsaPrivateKey, RsaPublicKey};
use serde::{Deserialize, Serialize};
use serde_annotate::Annotate;
use std::any::Any;
use std::path::PathBuf;

Expand Down Expand Up @@ -74,7 +73,7 @@ impl Dispatch for Export {
_context: &dyn Any,
_hsm: &Module,
session: Option<&Session>,
) -> Result<Box<dyn Annotate>> {
) -> Result<Box<dyn erased_serde::Serialize>> {
let session = session.ok_or(HsmError::SessionRequired)?;
let mut attrs = helper::search_spec(self.id.as_deref(), self.label.as_deref())?;
attrs.push(Attribute::KeyType(KeyType::Rsa.try_into()?));
Expand Down
3 changes: 1 addition & 2 deletions sw/host/hsmtool/src/commands/rsa/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use anyhow::Result;
use cryptoki::mechanism::Mechanism;
use cryptoki::session::Session;
use serde::{Deserialize, Serialize};
use serde_annotate::Annotate;
use std::any::Any;
use std::str::FromStr;

Expand Down Expand Up @@ -65,7 +64,7 @@ impl Dispatch for Generate {
_context: &dyn Any,
_hsm: &Module,
session: Option<&Session>,
) -> Result<Box<dyn Annotate>> {
) -> Result<Box<dyn erased_serde::Serialize>> {
let session = session.ok_or(HsmError::SessionRequired)?;
helper::no_object_exists(session, self.id.as_deref(), self.label.as_deref())?;
let id = AttrData::Str(self.id.as_ref().cloned().unwrap_or_else(helper::random_id));
Expand Down
3 changes: 1 addition & 2 deletions sw/host/hsmtool/src/commands/rsa/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use anyhow::{bail, Context, Result};
use cryptoki::object::Attribute;
use cryptoki::session::Session;
use serde::{Deserialize, Serialize};
use serde_annotate::Annotate;
use std::any::Any;
use std::path::PathBuf;
use std::str::FromStr;
Expand Down Expand Up @@ -78,7 +77,7 @@ impl Dispatch for Import {
_context: &dyn Any,
_hsm: &Module,
session: Option<&Session>,
) -> Result<Box<dyn Annotate>> {
) -> Result<Box<dyn erased_serde::Serialize>> {
let session = session.ok_or(HsmError::SessionRequired)?;
helper::no_object_exists(session, self.id.as_deref(), self.label.as_deref())?;
let mut public_attrs =
Expand Down
3 changes: 1 addition & 2 deletions sw/host/hsmtool/src/commands/rsa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use anyhow::Result;
use cryptoki::session::Session;
use serde::{Deserialize, Serialize};
use serde_annotate::Annotate;
use std::any::Any;

use crate::commands::Dispatch;
Expand Down Expand Up @@ -37,7 +36,7 @@ impl Dispatch for Rsa {
context: &dyn Any,
hsm: &Module,
session: Option<&Session>,
) -> Result<Box<dyn Annotate>> {
) -> Result<Box<dyn erased_serde::Serialize>> {
match self {
Rsa::Decrypt(x) => x.run(context, hsm, session),
Rsa::Encrypt(x) => x.run(context, hsm, session),
Expand Down
Loading

0 comments on commit 46ddf12

Please sign in to comment.