tss_esapi/abstraction/
mod.rs1pub mod ak;
5pub mod cipher;
6pub mod ek;
7pub mod no_tpm;
8pub mod nv;
9pub mod pcr;
10pub mod public;
11pub mod transient;
12
13mod hashing;
14mod signatures;
15mod signer;
16pub use hashing::AssociatedHashingAlgorithm;
17pub use signer::EcSigner;
18#[cfg(feature = "rsa")]
19pub use signer::{RsaPkcsSigner, RsaPssSigner};
20
21use std::convert::TryFrom;
22
23use crate::{
24 attributes::ObjectAttributesBuilder,
25 interface_types::{algorithm::AsymmetricAlgorithm, ecc::EccCurve, key_bits::RsaKeyBits},
26 structures::PublicBuilder,
27 Error, WrapperErrorKind,
28};
29
30pub trait KeyCustomization {
32 fn attributes(&self, attributes_builder: ObjectAttributesBuilder) -> ObjectAttributesBuilder {
34 attributes_builder
35 }
36
37 fn template(&self, template_builder: PublicBuilder) -> PublicBuilder {
39 template_builder
40 }
41}
42
43pub trait IntoKeyCustomization {
45 type T: KeyCustomization;
46
47 fn into_key_customization(self) -> Option<Self::T>;
48}
49
50impl<T: KeyCustomization> IntoKeyCustomization for T {
51 type T = T;
52
53 fn into_key_customization(self) -> Option<Self::T> {
54 Some(self)
55 }
56}
57
58#[derive(Debug, Copy, Clone)]
59pub struct DefaultKey;
60#[derive(Debug, Copy, Clone)]
61pub struct DefaultKeyImpl;
62impl KeyCustomization for DefaultKeyImpl {}
63
64impl IntoKeyCustomization for DefaultKey {
65 type T = DefaultKeyImpl;
66
67 fn into_key_customization(self) -> Option<Self::T> {
68 None
69 }
70}
71
72impl IntoKeyCustomization for Option<DefaultKey> {
73 type T = DefaultKeyImpl;
74
75 fn into_key_customization(self) -> Option<Self::T> {
76 None
77 }
78}
79
80#[derive(Copy, Clone, Debug, PartialEq, Eq)]
85pub enum AsymmetricAlgorithmSelection {
86 Rsa(RsaKeyBits),
87 Ecc(EccCurve),
88}
89
90impl TryFrom<AsymmetricAlgorithm> for AsymmetricAlgorithmSelection {
93 type Error = Error;
94
95 fn try_from(value: AsymmetricAlgorithm) -> Result<Self, Self::Error> {
96 match value {
97 AsymmetricAlgorithm::Rsa => Ok(AsymmetricAlgorithmSelection::Rsa(RsaKeyBits::Rsa2048)),
98 AsymmetricAlgorithm::Ecc => Ok(AsymmetricAlgorithmSelection::Ecc(EccCurve::NistP256)),
99 AsymmetricAlgorithm::Null => {
100 Err(Error::local_error(WrapperErrorKind::UnsupportedParam))
101 }
102 }
103 }
104}