hsmtool/util/attribute/
mod.rs

1// Copyright lowRISC contributors (OpenTitan project).
2// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3// SPDX-License-Identifier: Apache-2.0
4
5//! The `util::attribute` module provides helpers for working with PKCS11
6//! structs and identifiers as text (e.g. either in a CLI or as serialized
7//! forms like json).
8//!
9//! The following enums & structs are equivalent to their corresponding
10//! enums/structs in `cryptoki`:
11//! - AttributeType
12//! - CertificateType
13//! - Date
14//! - KeyType
15//! - MechanismType
16//! - ObjectClass
17//!
18//! They implement `From` for converting from their corresponding `cryptoki`
19//! types and `TryFrom` (and `TryInto`) for converting back to the
20//! `cryptoki` types.
21//!
22//! The `hsmtool` versions of these types provide integer conversion
23//! to/from the cryptoki_sys types, and `serde::{Serialize, Deserialize}`.
24//! They can also optionally provide `FromStr` and `Display` and can
25//! support conversions from nicer names than the formal PKCS11 names
26//! (like `CKK_RSA`).
27//!
28//! Just as the `cryptoki` types are thin wrappers around the PKCS11
29//! C types, using their underlying C types inside the wrapper, the
30//! `hsmtool` versions of these types are also wrappers around the
31//! same underlying C types and use the same internal representation.
32//!
33//! The `cryptoki` APIs typically use `&[Attribute]` when passing
34//! attributes to its functions.  For the purpose of building and
35//! (de)serializing an Attribute list, a map is more convenient
36//! structure and `AttributeMap` and `AttrData` fill that role.
37
38mod attr;
39mod data;
40mod date;
41mod error;
42
43mod attribute_type {
44    include!(env!("ATTRIBUTE_TYPE"));
45}
46mod certificate_type {
47    include!(env!("CERTIFICATE_TYPE"));
48}
49mod key_type {
50    include!(env!("KEY_TYPE"));
51}
52mod mechanism_type {
53    include!(env!("MECHANISM_TYPE"));
54}
55mod object_class {
56    include!(env!("OBJECT_CLASS"));
57}
58
59pub use attr::AttributeMap;
60pub use data::{AttrData, Redacted};
61pub use error::AttributeError;
62
63pub use attribute_type::AttributeType;
64pub use certificate_type::CertificateType;
65pub use date::Date;
66pub use key_type::KeyType;
67pub use mechanism_type::MechanismType;
68pub use object_class::ObjectClass;