signstar_yubihsm2/object/
key.rs

1//! YubiHSM2 key metadata.
2
3use serde::{Deserialize, Serialize};
4use serde_repr::{Deserialize_repr, Serialize_repr};
5
6use crate::object::Capabilities;
7
8/// YubiHSM2 object domain.
9///
10/// Objects can belong to one or many domains on the YubiHSM2.
11/// See [Core Concepts - Domains](https://docs.yubico.com/hardware/yubihsm-2/hsm-2-user-guide/hsm2-core-concepts.html#domains) for more details.
12#[derive(Clone, Copy, Debug, Deserialize_repr, PartialEq, Serialize_repr)]
13#[repr(u8)]
14pub enum Domain {
15    /// First domain.
16    One = 1,
17    /// Second domain.
18    Two = 2,
19    /// Third domain.
20    Three = 3,
21    /// Fourth domain.
22    Four = 4,
23    /// Fifth domain.
24    Five = 5,
25    /// Sixth domain.
26    Six = 6,
27    /// Seventh domain.
28    Seven = 7,
29    /// Eighth domain.
30    Eight = 8,
31    /// Ninth domain.
32    Nine = 9,
33    /// Tenth domain.
34    Ten = 10,
35    /// Eleventh domain.
36    Eleven = 11,
37    /// Twelfth domain.
38    Twelve = 12,
39    /// Thirteenth domain.
40    Thirteen = 13,
41    /// Fourteenth domain.
42    Fourteen = 14,
43    /// Fifteenth domain.
44    Fifteen = 15,
45    /// Sixteenth domain.
46    Sixteen = 16,
47}
48
49impl From<Domain> for yubihsm::Domain {
50    fn from(value: Domain) -> Self {
51        match value {
52            Domain::One => Self::DOM1,
53            Domain::Two => Self::DOM2,
54            Domain::Three => Self::DOM3,
55            Domain::Four => Self::DOM4,
56            Domain::Five => Self::DOM5,
57            Domain::Six => Self::DOM6,
58            Domain::Seven => Self::DOM7,
59            Domain::Eight => Self::DOM8,
60            Domain::Nine => Self::DOM9,
61            Domain::Ten => Self::DOM10,
62            Domain::Eleven => Self::DOM11,
63            Domain::Twelve => Self::DOM12,
64            Domain::Thirteen => Self::DOM13,
65            Domain::Fourteen => Self::DOM14,
66            Domain::Fifteen => Self::DOM15,
67            Domain::Sixteen => Self::DOM16,
68        }
69    }
70}
71
72/// Metadata about a key stored on a YubiHSM2.
73///
74/// This struct stores common parameters of keys regardless of their usage may describe
75/// authentication, wrapping and signing keys.
76#[derive(Debug, Deserialize, Serialize)]
77pub struct KeyInfo {
78    /// Inner identifier used to track the key on the YubiHSM2.
79    pub key_id: u16,
80
81    /// Key domain.
82    ///
83    /// Must be in range `1..16`.
84    /// See [Core Concepts - Domains](https://docs.yubico.com/hardware/yubihsm-2/hsm-2-user-guide/hsm2-core-concepts.html#domains).
85    pub domain: Domain,
86
87    /// Capabilities of this key.
88    pub caps: Capabilities,
89}