1use std::convert::TryInto;
3use std::fmt;
4use std::str::FromStr;
5
6use enum_ordinalize::Ordinalize;
7
8use crate::ttlv::fast_scan::{FastScanError, FastScanner};
9use crate::ttlv::format::Formatter;
10use crate::ttlv::format::{FormatDone, FormatResult};
11use crate::ttlv::types::Tag;
12use crate::ttlv::{TagType, Type};
13use crate::types::request::{Name, RevocationReason};
14
15use super::impl_ttlv_serde;
16
17#[derive(Clone, Debug, PartialEq, Eq)]
19pub struct AttributeName(pub String);
20
21impl std::cmp::PartialEq<str> for AttributeName {
22 fn eq(&self, other: &str) -> bool {
23 self.0 == other
24 }
25}
26
27impl_ttlv_serde!(text AttributeName as 0x42000A);
28
29#[derive(Clone, Debug, PartialEq, Eq)]
31pub struct AttributeIndex(pub i32);
32
33impl std::cmp::PartialEq<i32> for AttributeIndex {
34 fn eq(&self, other: &i32) -> bool {
35 &self.0 == other
36 }
37}
38
39impl_ttlv_serde!(int AttributeIndex as 0x420009);
40
41#[derive(Clone, Debug, PartialEq, Eq)]
43#[non_exhaustive]
44pub enum AttributeValue {
45 UniqueIdentifier(UniqueIdentifier),
47
48 Name(Name),
50
51 ObjectType(ObjectType),
53
54 CryptographicAlgorithm(CryptographicAlgorithm),
56
57 CryptographicLength(CryptographicLength),
59
60 CryptographicParameters(CryptographicParameters),
62
63 CryptographicDomainParameters(CryptographicDomainParameters),
65
66 CertificateType(CertificateType),
68
69 CryptographicUsageMask(CryptographicUsageMask),
85
86 State(State),
93
94 InitialDate(i64),
96
97 ActivationDate(i64),
99
100 DeactivationDate(i64),
107
108 DestroyDate(i64),
110
111 RevocationReason(RevocationReason),
118
119 ObjectGroup(String),
123
124 Link(LinkType, LinkedObjectIdentifier),
126
127 ApplicationSpecificInformation(ApplicationNamespace, ApplicationData),
129
130 ContactInformation(String),
132 CustomAttribute,
136}
137
138impl AttributeValue {
139 pub const TAG: Tag = Tag::new(0x42000B);
140
141 pub fn fast_scan(scanner: &mut FastScanner<'_>, name: &AttributeName) -> Result<Self, FastScanError> {
142 match name.0.as_str() {
143 "Unique Identifier" => UniqueIdentifier::fast_scan_with(scanner, Self::TAG).map(Self::UniqueIdentifier),
144
145 "Name" => Name::fast_scan_with(scanner, Self::TAG).map(Self::Name),
146
147 "Object Type" => ObjectType::fast_scan_with(scanner, Self::TAG).map(Self::ObjectType),
148
149 "Cryptographic Algorithm" => {
150 CryptographicAlgorithm::fast_scan_with(scanner, Self::TAG).map(Self::CryptographicAlgorithm)
151 }
152
153 "Cryptographic Length" => {
154 CryptographicLength::fast_scan_with(scanner, Self::TAG).map(Self::CryptographicLength)
155 }
156
157 "Cryptographic Parameters" => {
158 CryptographicParameters::fast_scan_with(scanner, Self::TAG).map(Self::CryptographicParameters)
159 }
160
161 "Cryptographic Domain Parameters" => CryptographicDomainParameters::fast_scan_with(scanner, Self::TAG)
162 .map(Self::CryptographicDomainParameters),
163
164 "Cryptographic Usage Mask" => {
165 CryptographicUsageMask::fast_scan_with(scanner, Self::TAG).map(Self::CryptographicUsageMask)
166 }
167
168 "State" => State::fast_scan_with(scanner, Self::TAG).map(Self::State),
169
170 "Initial Date" => scanner.scan_date_time(Self::TAG).map(Self::InitialDate),
171
172 "Activation Date" => scanner.scan_date_time(Self::TAG).map(Self::ActivationDate),
173
174 "Deactivation Date" => scanner.scan_date_time(Self::TAG).map(Self::DeactivationDate),
175
176 "Destroy Date" => scanner.scan_date_time(Self::TAG).map(Self::DestroyDate),
177
178 "Revocation Reason" => RevocationReason::fast_scan_with(scanner, Self::TAG).map(Self::RevocationReason),
179
180 "Object Group" => scanner.scan_text(Self::TAG).map(|s| Self::ObjectGroup(s.into())),
181
182 "Link" => {
183 let mut scanner = scanner.scan_struct(Self::TAG)?;
184 let link_type = LinkType::fast_scan(&mut scanner)?;
185 let linked_object_identifier = LinkedObjectIdentifier::fast_scan(&mut scanner)?;
186 scanner.finish()?;
187 Ok(Self::Link(link_type, linked_object_identifier))
188 }
189
190 "Application Specific Information" => {
191 let mut scanner = scanner.scan_struct(Self::TAG)?;
192 let application_namespace = ApplicationNamespace::fast_scan(&mut scanner)?;
193 let application_data = ApplicationData::fast_scan(&mut scanner)?;
194 scanner.finish()?;
195 Ok(Self::ApplicationSpecificInformation(
196 application_namespace,
197 application_data,
198 ))
199 }
200
201 "Contact Information" => scanner.scan_text(Self::TAG).map(|s| Self::ContactInformation(s.into())),
202
203 custom_attr if custom_attr.starts_with("x-") || custom_attr.starts_with("y-") => {
204 let first_ttl = scanner.remaining()[0];
205 let tt = TagType::parse(first_ttl[0..4].try_into().unwrap());
206 match tt.r#type() {
207 Type::Structure => scanner.skip_struct(tt.tag())?,
208 Type::Integer => scanner.skip_int(tt.tag())?,
209 Type::LongInteger => scanner.skip_long_int(tt.tag())?,
210 Type::BigInteger => scanner.skip_big_int(tt.tag())?,
211 Type::Enumeration => scanner.skip_enum(tt.tag())?,
212 Type::Boolean => scanner.skip_bool(tt.tag())?,
213 Type::TextString => scanner.skip_text(tt.tag())?,
214 Type::ByteString => scanner.skip_bytes(tt.tag())?,
215 Type::DateTime => scanner.skip_date_time(tt.tag())?,
216 Type::Interval => scanner.skip_interval(tt.tag())?,
217 }
218 Ok(Self::CustomAttribute)
219 }
220
221 _ => Err(FastScanError::assert()),
222 }
223 }
224
225 pub fn format(&self, formatter: &mut Formatter<'_>) -> FormatResult {
226 match self {
227 AttributeValue::UniqueIdentifier(v) => v.format_with(formatter, Self::TAG),
228 AttributeValue::Name(v) => v.format_with(formatter, Self::TAG),
229 AttributeValue::ObjectType(v) => v.format_with(formatter, Self::TAG),
230 AttributeValue::CryptographicAlgorithm(v) => v.format_with(formatter, Self::TAG),
231 AttributeValue::CryptographicLength(v) => v.format_with(formatter, Self::TAG),
232 AttributeValue::CryptographicParameters(v) => v.format_with(formatter, Self::TAG),
233 AttributeValue::CryptographicDomainParameters(v) => v.format_with(formatter, Self::TAG),
234 AttributeValue::CertificateType(v) => v.format_with(formatter, Self::TAG),
235 AttributeValue::CryptographicUsageMask(v) => v.format_with(formatter, Self::TAG),
236 AttributeValue::State(v) => v.format_with(formatter, Self::TAG),
237 AttributeValue::InitialDate(v) => formatter.format_date_time(Self::TAG, *v),
238 AttributeValue::ActivationDate(v) => formatter.format_date_time(Self::TAG, *v),
239 AttributeValue::DeactivationDate(v) => formatter.format_date_time(Self::TAG, *v),
240 AttributeValue::DestroyDate(v) => formatter.format_date_time(Self::TAG, *v),
241 AttributeValue::RevocationReason(v) => v.format_with(formatter, Self::TAG),
242 AttributeValue::ObjectGroup(v) => formatter.format_text(Self::TAG, v),
243 AttributeValue::Link(link_type, linked_object_id) => {
244 let mut formatter = formatter.format_struct(Self::TAG)?;
245 link_type.format(&mut formatter)?;
246 linked_object_id.format(&mut formatter)?;
247 Ok(formatter.finish())
248 }
249 AttributeValue::ApplicationSpecificInformation(namespace, data) => {
250 let mut formatter = formatter.format_struct(Self::TAG)?;
251 namespace.format(&mut formatter)?;
252 data.format(&mut formatter)?;
253 Ok(formatter.finish())
254 }
255 AttributeValue::ContactInformation(v) => formatter.format_text(Self::TAG, v),
256 AttributeValue::CustomAttribute => Ok(FormatDone::assert()),
257 }
258 }
259}
260
261#[derive(Clone, Debug, PartialEq, Eq)]
263pub enum KeyMaterial {
264 Bytes(Vec<u8>),
265 TransparentSymmetricKey(TransparentSymmetricKey),
266 TransparentDSAPrivateKey(TransparentDSAPrivateKey),
267 TransparentDSAPublicKey(TransparentDSAPublicKey),
268 TransparentRSAPrivateKey(TransparentRSAPrivateKey),
269 TransparentRSAPublicKey(TransparentRSAPublicKey),
270 TransparentDHPrivateKey(TransparentDHPrivateKey),
271 TransparentDHPublicKey(TransparentDHPublicKey),
272 Structure(Vec<u8>), }
274
275impl fmt::Display for KeyMaterial {
276 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
277 match self {
278 KeyMaterial::Bytes(_) => write!(f, "Bytes"),
279 KeyMaterial::TransparentSymmetricKey(_) => write!(f, "TransparentSymmetricKey"),
280 KeyMaterial::TransparentDSAPrivateKey(_) => write!(f, "TransparentDSAPrivateKey"),
281 KeyMaterial::TransparentDSAPublicKey(_) => write!(f, "TransparentDSAPublicKey"),
282 KeyMaterial::TransparentRSAPrivateKey(_) => write!(f, "TransparentRSAPrivateKey"),
283 KeyMaterial::TransparentRSAPublicKey(_) => write!(f, "TransparentRSAPublicKey"),
284 KeyMaterial::TransparentDHPrivateKey(_) => write!(f, "TransparentDHPrivateKey"),
285 KeyMaterial::TransparentDHPublicKey(_) => write!(f, "TransparentDHPublicKey"),
286 KeyMaterial::Structure(_) => write!(f, "Structure"),
287 }
288 }
289}
290
291impl KeyMaterial {
292 pub const TAG: Tag = Tag::new(0x420043);
293
294 pub fn fast_scan(scanner: &mut FastScanner<'_>, format: &KeyFormatType) -> Result<Self, FastScanError> {
295 match format {
296 KeyFormatType::Raw
297 | KeyFormatType::Opaque
298 | KeyFormatType::PKCS1
299 | KeyFormatType::PKCS8
300 | KeyFormatType::X509
301 | KeyFormatType::ECPrivateKey => scanner.scan_bytes(Self::TAG).map(|s| Self::Bytes(s.into())),
302
303 KeyFormatType::TransparentSymmetricKey => {
304 TransparentSymmetricKey::fast_scan(scanner).map(Self::TransparentSymmetricKey)
305 }
306 KeyFormatType::TransparentDSAPrivateKey => {
307 TransparentDSAPrivateKey::fast_scan(scanner).map(Self::TransparentDSAPrivateKey)
308 }
309 KeyFormatType::TransparentDSAPublicKey => {
310 TransparentDSAPublicKey::fast_scan(scanner).map(Self::TransparentDSAPublicKey)
311 }
312 KeyFormatType::TransparentRSAPrivateKey => {
313 TransparentRSAPrivateKey::fast_scan(scanner).map(Self::TransparentRSAPrivateKey)
314 }
315 KeyFormatType::TransparentRSAPublicKey => {
316 TransparentRSAPublicKey::fast_scan(scanner).map(Self::TransparentRSAPublicKey)
317 }
318 KeyFormatType::TransparentDHPrivateKey => {
319 TransparentDHPrivateKey::fast_scan(scanner).map(Self::TransparentDHPrivateKey)
320 }
321 KeyFormatType::TransparentDHPublicKey => {
322 TransparentDHPublicKey::fast_scan(scanner).map(Self::TransparentDHPublicKey)
323 }
324 _ => {
326 scanner.skip_struct(Self::TAG)?;
327 Ok(Self::Structure(Vec::new()))
328 }
329 }
330 }
331
332 pub fn format(&self, formatter: &mut Formatter<'_>) -> FormatResult {
333 match self {
334 KeyMaterial::Bytes(v) => formatter.format_bytes(Self::TAG, v),
335
336 KeyMaterial::TransparentSymmetricKey(this) => this.format(formatter),
337 KeyMaterial::TransparentDSAPrivateKey(this) => this.format(formatter),
338 KeyMaterial::TransparentDSAPublicKey(this) => this.format(formatter),
339 KeyMaterial::TransparentRSAPrivateKey(this) => this.format(formatter),
340 KeyMaterial::TransparentRSAPublicKey(this) => this.format(formatter),
341 KeyMaterial::TransparentDHPrivateKey(this) => this.format(formatter),
342 KeyMaterial::TransparentDHPublicKey(this) => this.format(formatter),
343
344 KeyMaterial::Structure(_) => unimplemented!(),
345 }
346 }
347}
348
349#[derive(Clone, Debug, PartialEq, Eq)]
351pub struct TransparentSymmetricKey {
352 pub key: Vec<u8>,
353}
354
355impl TransparentSymmetricKey {
356 pub const TAG: Tag = Tag::new(0x420043);
357 pub const KEY_TAG: Tag = Tag::new(0x42003F);
358
359 pub fn fast_scan(scanner: &mut FastScanner<'_>) -> Result<Self, FastScanError> {
360 let mut scanner = scanner.scan_struct(Self::TAG)?;
361 let key = scanner.scan_bytes(Self::KEY_TAG)?.into();
362 scanner.finish()?;
363 Ok(Self { key })
364 }
365
366 pub fn format(&self, formatter: &mut Formatter<'_>) -> FormatResult {
367 let mut formatter = formatter.format_struct(Self::TAG)?;
368 formatter.format_bytes(Self::KEY_TAG, &self.key)?;
369 Ok(formatter.finish())
370 }
371}
372
373#[derive(Clone, Debug, PartialEq, Eq)]
375pub struct TransparentDSAPrivateKey {
376 pub p: Vec<u8>,
377 pub q: Vec<u8>,
378 pub g: Vec<u8>,
379 pub x: Vec<u8>,
380}
381
382impl TransparentDSAPrivateKey {
383 pub const TAG: Tag = Tag::new(0x420043);
384 pub const P_TAG: Tag = Tag::new(0x42005E);
385 pub const Q_TAG: Tag = Tag::new(0x420071);
386 pub const G_TAG: Tag = Tag::new(0x420037);
387 pub const X_TAG: Tag = Tag::new(0x42009F);
388
389 pub fn fast_scan(scanner: &mut FastScanner<'_>) -> Result<Self, FastScanError> {
390 let mut scanner = scanner.scan_struct(Self::TAG)?;
391 let p = scanner.scan_big_int(Self::P_TAG)?.into();
392 let q = scanner.scan_big_int(Self::Q_TAG)?.into();
393 let g = scanner.scan_big_int(Self::G_TAG)?.into();
394 let x = scanner.scan_big_int(Self::X_TAG)?.into();
395 scanner.finish()?;
396 Ok(Self { p, q, g, x })
397 }
398
399 pub fn format(&self, formatter: &mut Formatter<'_>) -> FormatResult {
400 let mut formatter = formatter.format_struct(Self::TAG)?;
401 formatter.format_big_int(Self::P_TAG, &self.p)?;
402 formatter.format_big_int(Self::Q_TAG, &self.q)?;
403 formatter.format_big_int(Self::G_TAG, &self.g)?;
404 formatter.format_big_int(Self::X_TAG, &self.x)?;
405 Ok(formatter.finish())
406 }
407}
408
409#[derive(Clone, Debug, PartialEq, Eq)]
411pub struct TransparentDSAPublicKey {
412 pub p: Vec<u8>,
413 pub q: Vec<u8>,
414 pub g: Vec<u8>,
415 pub x: Vec<u8>,
416}
417
418impl TransparentDSAPublicKey {
419 pub const TAG: Tag = Tag::new(0x420043);
420 pub const P_TAG: Tag = Tag::new(0x42005E);
421 pub const Q_TAG: Tag = Tag::new(0x420071);
422 pub const G_TAG: Tag = Tag::new(0x420037);
423 pub const X_TAG: Tag = Tag::new(0x42009F);
424
425 pub fn fast_scan(scanner: &mut FastScanner<'_>) -> Result<Self, FastScanError> {
426 let mut scanner = scanner.scan_struct(Self::TAG)?;
427 let p = scanner.scan_big_int(Self::P_TAG)?.into();
428 let q = scanner.scan_big_int(Self::Q_TAG)?.into();
429 let g = scanner.scan_big_int(Self::G_TAG)?.into();
430 let x = scanner.scan_big_int(Self::X_TAG)?.into();
431 scanner.finish()?;
432 Ok(Self { p, q, g, x })
433 }
434
435 pub fn format(&self, formatter: &mut Formatter<'_>) -> FormatResult {
436 let mut formatter = formatter.format_struct(Self::TAG)?;
437 formatter.format_big_int(Self::P_TAG, &self.p)?;
438 formatter.format_big_int(Self::Q_TAG, &self.q)?;
439 formatter.format_big_int(Self::G_TAG, &self.g)?;
440 formatter.format_big_int(Self::X_TAG, &self.x)?;
441 Ok(formatter.finish())
442 }
443}
444
445#[derive(Clone, Debug, PartialEq, Eq)]
447pub struct TransparentRSAPrivateKey {
448 pub modulus: Vec<u8>,
449 pub private_exponent: Option<Vec<u8>>,
450 pub public_exponent: Option<Vec<u8>>,
451 pub p: Option<Vec<u8>>,
452 pub q: Option<Vec<u8>>,
453 pub prime_exponent_p: Option<Vec<u8>>,
454 pub prime_exponent_q: Option<Vec<u8>>,
455 pub crt_coefficient: Option<Vec<u8>>,
456}
457
458impl TransparentRSAPrivateKey {
459 pub const TAG: Tag = Tag::new(0x420043);
460 pub const MODULUS_TAG: Tag = Tag::new(0x420052);
461 pub const PRIVATE_EXPONENT_TAG: Tag = Tag::new(0x420063);
462 pub const PUBLIC_EXPONENT_TAG: Tag = Tag::new(0x42006C);
463 pub const P_TAG: Tag = Tag::new(0x42005E);
464 pub const Q_TAG: Tag = Tag::new(0x420071);
465 pub const PRIME_EXPONENT_P_TAG: Tag = Tag::new(0x420060);
466 pub const PRIME_EXPONENT_Q_TAG: Tag = Tag::new(0x420061);
467 pub const CRT_COEFFICIENT_TAG: Tag = Tag::new(0x420027);
468
469 pub fn fast_scan(scanner: &mut FastScanner<'_>) -> Result<Self, FastScanError> {
470 let mut scanner = scanner.scan_struct(Self::TAG)?;
471 let modulus = scanner.scan_big_int(Self::MODULUS_TAG)?.into();
472 let private_exponent = scanner.scan_opt_big_int(Self::PRIVATE_EXPONENT_TAG)?.map(Into::into);
473 let public_exponent = scanner.scan_opt_big_int(Self::PUBLIC_EXPONENT_TAG)?.map(Into::into);
474 let p = scanner.scan_opt_big_int(Self::P_TAG)?.map(Into::into);
475 let q = scanner.scan_opt_big_int(Self::Q_TAG)?.map(Into::into);
476 let prime_exponent_p = scanner.scan_opt_big_int(Self::PRIME_EXPONENT_P_TAG)?.map(Into::into);
477 let prime_exponent_q = scanner.scan_opt_big_int(Self::PRIME_EXPONENT_Q_TAG)?.map(Into::into);
478 let crt_coefficient = scanner.scan_opt_big_int(Self::CRT_COEFFICIENT_TAG)?.map(Into::into);
479 scanner.finish()?;
480 Ok(Self {
481 modulus,
482 private_exponent,
483 public_exponent,
484 p,
485 q,
486 prime_exponent_p,
487 prime_exponent_q,
488 crt_coefficient,
489 })
490 }
491
492 pub fn format(&self, formatter: &mut Formatter<'_>) -> FormatResult {
493 let mut formatter = formatter.format_struct(Self::TAG)?;
494 formatter.format_big_int(Self::MODULUS_TAG, &self.modulus)?;
495 if let Some(private_exponent) = &self.private_exponent {
496 formatter.format_big_int(Self::PRIVATE_EXPONENT_TAG, private_exponent)?;
497 }
498 if let Some(public_exponent) = &self.public_exponent {
499 formatter.format_big_int(Self::PUBLIC_EXPONENT_TAG, public_exponent)?;
500 }
501 if let Some(p) = &self.p {
502 formatter.format_big_int(Self::P_TAG, p)?;
503 }
504 if let Some(q) = &self.q {
505 formatter.format_big_int(Self::Q_TAG, q)?;
506 }
507 if let Some(prime_exponent_p) = &self.prime_exponent_p {
508 formatter.format_big_int(Self::PRIME_EXPONENT_P_TAG, prime_exponent_p)?;
509 }
510 if let Some(prime_exponent_q) = &self.prime_exponent_q {
511 formatter.format_big_int(Self::PRIME_EXPONENT_Q_TAG, prime_exponent_q)?;
512 }
513 if let Some(crt_coefficient) = &self.crt_coefficient {
514 formatter.format_big_int(Self::CRT_COEFFICIENT_TAG, crt_coefficient)?;
515 }
516 Ok(formatter.finish())
517 }
518}
519
520#[derive(Clone, Debug, PartialEq, Eq)]
522pub struct TransparentRSAPublicKey {
523 pub modulus: Vec<u8>,
524 pub public_exponent: Vec<u8>,
525}
526
527impl TransparentRSAPublicKey {
528 pub const TAG: Tag = Tag::new(0x420043);
529 pub const MODULUS_TAG: Tag = Tag::new(0x420052);
530 pub const PUBLIC_EXPONENT_TAG: Tag = Tag::new(0x42006C);
531
532 pub fn fast_scan(scanner: &mut FastScanner<'_>) -> Result<Self, FastScanError> {
533 let mut scanner = scanner.scan_struct(Self::TAG)?;
534 let modulus = scanner.scan_big_int(Self::MODULUS_TAG)?.into();
535 let public_exponent = scanner.scan_big_int(Self::PUBLIC_EXPONENT_TAG)?.into();
536 scanner.finish()?;
537 Ok(Self {
538 modulus,
539 public_exponent,
540 })
541 }
542
543 pub fn format(&self, formatter: &mut Formatter<'_>) -> FormatResult {
544 let mut formatter = formatter.format_struct(Self::TAG)?;
545 formatter.format_big_int(Self::MODULUS_TAG, &self.modulus)?;
546 formatter.format_big_int(Self::PUBLIC_EXPONENT_TAG, &self.public_exponent)?;
547 Ok(formatter.finish())
548 }
549}
550
551#[derive(Clone, Debug, PartialEq, Eq)]
553pub struct TransparentDHPrivateKey {
554 pub p: Vec<u8>,
555 pub q: Option<Vec<u8>>,
556 pub g: Vec<u8>,
557 pub j: Option<Vec<u8>>,
558 pub x: Vec<u8>,
559}
560
561impl TransparentDHPrivateKey {
562 pub const TAG: Tag = Tag::new(0x420043);
563 pub const P_TAG: Tag = Tag::new(0x42005E);
564 pub const Q_TAG: Tag = Tag::new(0x420071);
565 pub const G_TAG: Tag = Tag::new(0x420037);
566 pub const J_TAG: Tag = Tag::new(0x42003E);
567 pub const X_TAG: Tag = Tag::new(0x42009F);
568
569 pub fn fast_scan(scanner: &mut FastScanner<'_>) -> Result<Self, FastScanError> {
570 let mut scanner = scanner.scan_struct(Self::TAG)?;
571 let p = scanner.scan_big_int(Self::P_TAG)?.into();
572 let q = scanner.scan_opt_big_int(Self::Q_TAG)?.map(Into::into);
573 let g = scanner.scan_big_int(Self::G_TAG)?.into();
574 let j = scanner.scan_opt_big_int(Self::J_TAG)?.map(Into::into);
575 let x = scanner.scan_big_int(Self::X_TAG)?.into();
576 scanner.finish()?;
577 Ok(Self { p, q, g, j, x })
578 }
579
580 pub fn format(&self, formatter: &mut Formatter<'_>) -> FormatResult {
581 let mut formatter = formatter.format_struct(Self::TAG)?;
582 formatter.format_big_int(Self::P_TAG, &self.p)?;
583 if let Some(q) = &self.q {
584 formatter.format_big_int(Self::Q_TAG, q)?;
585 }
586 formatter.format_big_int(Self::G_TAG, &self.g)?;
587 if let Some(j) = &self.j {
588 formatter.format_big_int(Self::J_TAG, j)?;
589 }
590 formatter.format_big_int(Self::X_TAG, &self.x)?;
591 Ok(formatter.finish())
592 }
593}
594
595#[derive(Clone, Debug, PartialEq, Eq)]
597pub struct TransparentDHPublicKey {
598 pub p: Vec<u8>,
599 pub q: Option<Vec<u8>>,
600 pub g: Vec<u8>,
601 pub j: Option<Vec<u8>>,
602 pub y: Vec<u8>,
603}
604
605impl TransparentDHPublicKey {
606 pub const TAG: Tag = Tag::new(0x420043);
607 pub const P_TAG: Tag = Tag::new(0x42005E);
608 pub const Q_TAG: Tag = Tag::new(0x420071);
609 pub const G_TAG: Tag = Tag::new(0x420037);
610 pub const J_TAG: Tag = Tag::new(0x42003E);
611 pub const Y_TAG: Tag = Tag::new(0x4200A0);
612
613 pub fn fast_scan(scanner: &mut FastScanner<'_>) -> Result<Self, FastScanError> {
614 let mut scanner = scanner.scan_struct(Self::TAG)?;
615 let p = scanner.scan_big_int(Self::P_TAG)?.into();
616 let q = scanner.scan_opt_big_int(Self::Q_TAG)?.map(Into::into);
617 let g = scanner.scan_big_int(Self::G_TAG)?.into();
618 let j = scanner.scan_opt_big_int(Self::J_TAG)?.map(Into::into);
619 let y = scanner.scan_big_int(Self::Y_TAG)?.into();
620 scanner.finish()?;
621 Ok(Self { p, q, g, j, y })
622 }
623
624 pub fn format(&self, formatter: &mut Formatter<'_>) -> FormatResult {
625 let mut formatter = formatter.format_struct(Self::TAG)?;
626 formatter.format_big_int(Self::P_TAG, &self.p)?;
627 if let Some(q) = &self.q {
628 formatter.format_big_int(Self::Q_TAG, q)?;
629 }
630 formatter.format_big_int(Self::G_TAG, &self.g)?;
631 if let Some(j) = &self.j {
632 formatter.format_big_int(Self::J_TAG, j)?;
633 }
634 formatter.format_big_int(Self::Y_TAG, &self.y)?;
635 Ok(formatter.finish())
636 }
637}
638
639#[derive(Clone, Debug, PartialEq, Eq)]
641pub struct Data(pub Vec<u8>);
642
643impl_ttlv_serde!(bytes Data as 0x4200C2);
644
645#[derive(Clone, Copy, Debug, PartialEq, Eq)]
647pub struct DataLength(pub i32);
648
649impl_ttlv_serde!(int DataLength as 0x4200C4);
650
651#[derive(Clone, Debug, PartialEq, Eq)]
653pub struct UniqueIdentifier(pub String);
654
655impl std::ops::Deref for UniqueIdentifier {
656 type Target = String;
657
658 fn deref(&self) -> &Self::Target {
659 &self.0
660 }
661}
662
663impl std::cmp::PartialEq<str> for UniqueIdentifier {
664 fn eq(&self, other: &str) -> bool {
665 self.0 == other
666 }
667}
668
669impl_ttlv_serde!(text UniqueIdentifier as 0x420094);
670
671#[derive(Clone, Debug, PartialEq, Eq)]
673pub struct NameValue(pub String);
674
675impl fmt::Display for NameValue {
676 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
677 f.write_str(&self.0)
678 }
679}
680
681impl FromStr for NameValue {
682 type Err = ();
683
684 fn from_str(s: &str) -> Result<Self, Self::Err> {
685 Ok(Self(s.to_string()))
686 }
687}
688
689impl_ttlv_serde!(text NameValue as 0x420055);
690
691#[derive(Clone, Copy, Debug, PartialEq, Eq, Ordinalize)]
693#[non_exhaustive]
694#[repr(u32)]
695pub enum ObjectType {
696 Certificate = 1,
698 SymmetricKey,
699 PublicKey,
700 PrivateKey,
701 SplitKey,
702 Template,
703 SecretData,
704 OpaqueObject,
705
706 PGPKey,
708}
709
710impl fmt::Display for ObjectType {
711 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
712 f.write_str(match self {
713 Self::Certificate => "Certificate",
714 Self::SymmetricKey => "SymmetricKey",
715 Self::PublicKey => "PublicKey",
716 Self::PrivateKey => "PrivateKey",
717 Self::SplitKey => "SplitKey",
718 Self::Template => "Template",
719 Self::SecretData => "SecretData",
720 Self::OpaqueObject => "OpaqueObject",
721 Self::PGPKey => "PGPKey",
722 })
723 }
724}
725
726impl_ttlv_serde!(enum ObjectType as 0x420057);
727
728#[derive(Clone, Copy, Debug, PartialEq, Eq, Ordinalize)]
730#[non_exhaustive]
731#[allow(non_camel_case_types)]
732#[repr(u32)]
733pub enum CryptographicAlgorithm {
734 DES = 1,
736 TRIPLE_DES,
737 AES,
738 RSA,
739 DSA,
740 ECDSA,
741 HMAC_SHA1,
742 HMAC_SHA224,
743 HMAC_SHA256,
744 HMAC_SHA384,
745 HMAC_SHA512,
746 HMAC_MD5,
747 DH,
748 ECDH,
749 ECMQV,
750 Blowfish,
751 Camellia,
752 CAST5,
753 IDEA,
754 MARS,
755 RC2,
756 RC4,
757 RC5,
758 SKIPJACK,
759 Twofish,
760
761 EC,
763
764 One_Time_Pad,
766
767 ChaCha20,
769 Poly1305,
770 ChaCha20Poly1305,
771 SHA3_224,
772 SHA3_256,
773 SHA3_384,
774 SHA3_512,
775 HMAC_SHA3_224,
776 HMAC_SHA3_256,
777 HMAC_SHA3_384,
778 HMAC_SHA3_512,
779 SHAKE_128,
780 SHAKE_256,
781
782 ARIA,
805 SEED,
806 SM2,
807 SM3,
808 SM4,
809 GOST_R_34_10_2012,
810 GOST_R_34_11_2012,
811 GOST_R_34_13_2015,
812 GOST_28147_89,
813 XMSS,
814 SPHINCS_256,
815 McEliece,
816 McEliece_6960119,
817 McEliece_8192128,
818 Ed25519,
819 Ed448,
820}
821
822impl_ttlv_serde!(enum CryptographicAlgorithm as 0x420028);
823
824impl fmt::Display for CryptographicAlgorithm {
825 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
826 f.write_str(match self {
827 Self::DES => "DES",
828 Self::TRIPLE_DES => "TRIPLE_DES",
829 Self::AES => "AES",
830 Self::RSA => "RSA",
831 Self::DSA => "DSA",
832 Self::ECDSA => "ECDSA",
833 Self::HMAC_SHA1 => "HMAC_SHA1",
834 Self::HMAC_SHA224 => "HMAC_SHA224",
835 Self::HMAC_SHA256 => "HMAC_SHA256",
836 Self::HMAC_SHA384 => "HMAC_SHA384",
837 Self::HMAC_SHA512 => "HMAC_SHA512",
838 Self::HMAC_MD5 => "HMAC_MD5",
839 Self::DH => "DH",
840 Self::ECDH => "ECDH",
841 Self::ECMQV => "ECMQV",
842 Self::Blowfish => "Blowfish",
843 Self::Camellia => "Camellia",
844 Self::CAST5 => "CAST5",
845 Self::IDEA => "IDEA",
846 Self::MARS => "MARS",
847 Self::RC2 => "RC2",
848 Self::RC4 => "RC4",
849 Self::RC5 => "RC5",
850 Self::SKIPJACK => "SKIPJACK",
851 Self::Twofish => "Twofish",
852 Self::EC => "EC",
853 Self::One_Time_Pad => "One_Time_Pad",
854 Self::ChaCha20 => "ChaCha20",
855 Self::Poly1305 => "Poly1305",
856 Self::ChaCha20Poly1305 => "ChaCha20Poly1305",
857 Self::SHA3_224 => "SHA3_224",
858 Self::SHA3_256 => "SHA3_256",
859 Self::SHA3_384 => "SHA3_384",
860 Self::SHA3_512 => "SHA3_512",
861 Self::HMAC_SHA3_224 => "HMAC_SHA3_224",
862 Self::HMAC_SHA3_256 => "HMAC_SHA3_256",
863 Self::HMAC_SHA3_384 => "HMAC_SHA3_384",
864 Self::HMAC_SHA3_512 => "HMAC_SHA3_512",
865 Self::SHAKE_128 => "SHAKE_128",
866 Self::SHAKE_256 => "SHAKE_256",
867 Self::ARIA => "ARIA",
868 Self::SEED => "SEED",
869 Self::SM2 => "SM2",
870 Self::SM3 => "SM3",
871 Self::SM4 => "SM4",
872 Self::GOST_R_34_10_2012 => "GOST_R_34_10_2012",
873 Self::GOST_R_34_11_2012 => "GOST_R_34_11_2012",
874 Self::GOST_R_34_13_2015 => "GOST_R_34_13_2015",
875 Self::GOST_28147_89 => "GOST_28147_89",
876 Self::XMSS => "XMSS",
877 Self::SPHINCS_256 => "SPHINCS_256",
878 Self::McEliece => "McEliece",
879 Self::McEliece_6960119 => "McEliece_6960119",
880 Self::McEliece_8192128 => "McEliece_8192128",
881 Self::Ed25519 => "Ed25519",
882 Self::Ed448 => "Ed448",
883 })
884 }
885}
886
887#[derive(Clone, Copy, Debug, PartialEq, Eq)]
889pub struct CryptographicLength(pub i32);
890
891impl_ttlv_serde!(int CryptographicLength as 0x42002A);
892
893#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
895#[rustfmt::skip]
896pub struct CryptographicParameters {
897 pub block_cipher_mode: Option<BlockCipherMode>,
898 pub padding_method: Option<PaddingMethod>,
899 pub hashing_algorithm: Option<HashingAlgorithm>,
900 pub key_role_type: Option<KeyRoleType>,
901 pub digital_signature_algorithm: Option<DigitalSignatureAlgorithm>, pub cryptographic_algorithm: Option<CryptographicAlgorithm>, pub random_iv: Option<RandomIV>, pub iv_length: Option<IVLength>, pub tag_length: Option<TagLength>, pub fixed_field_length: Option<FixedFieldLength>, pub invocation_field_length: Option<InvocationFieldLength>, pub counter_length: Option<CounterLength>, pub initial_counter_value: Option<InitialCounterValue>, }
911
912impl CryptographicParameters {
913 pub fn with_block_cipher_mode(self, value: BlockCipherMode) -> Self {
914 Self {
915 block_cipher_mode: Some(value),
916 ..self
917 }
918 }
919
920 pub fn with_padding_method(self, value: PaddingMethod) -> Self {
921 Self {
922 padding_method: Some(value),
923 ..self
924 }
925 }
926
927 pub fn with_hashing_algorithm(self, value: HashingAlgorithm) -> Self {
928 Self {
929 hashing_algorithm: Some(value),
930 ..self
931 }
932 }
933
934 pub fn with_key_role_type(self, value: KeyRoleType) -> Self {
935 Self {
936 key_role_type: Some(value),
937 ..self
938 }
939 }
940
941 pub fn with_digital_signature_algorithm(self, value: DigitalSignatureAlgorithm) -> Self {
942 Self {
943 digital_signature_algorithm: Some(value),
944 ..self
945 }
946 }
947
948 pub fn with_cryptographic_algorithm(self, value: CryptographicAlgorithm) -> Self {
949 Self {
950 cryptographic_algorithm: Some(value),
951 ..self
952 }
953 }
954
955 pub fn with_random_iv(self, value: RandomIV) -> Self {
956 Self {
957 random_iv: Some(value),
958 ..self
959 }
960 }
961
962 pub fn with_iv_length(self, value: IVLength) -> Self {
963 Self {
964 iv_length: Some(value),
965 ..self
966 }
967 }
968
969 pub fn with_tag_length(self, value: TagLength) -> Self {
970 Self {
971 tag_length: Some(value),
972 ..self
973 }
974 }
975
976 pub fn with_fixed_field_length(self, value: FixedFieldLength) -> Self {
977 Self {
978 fixed_field_length: Some(value),
979 ..self
980 }
981 }
982
983 pub fn with_invocation_field_length(self, value: InvocationFieldLength) -> Self {
984 Self {
985 invocation_field_length: Some(value),
986 ..self
987 }
988 }
989
990 pub fn with_counter_length(self, value: CounterLength) -> Self {
991 Self {
992 counter_length: Some(value),
993 ..self
994 }
995 }
996
997 pub fn with_initial_counter_value(self, value: InitialCounterValue) -> Self {
998 Self {
999 initial_counter_value: Some(value),
1000 ..self
1001 }
1002 }
1003}
1004
1005impl_ttlv_serde!(struct CryptographicParameters {
1006 #[option] block_cipher_mode: BlockCipherMode,
1007 #[option] padding_method: PaddingMethod,
1008 #[option] hashing_algorithm: HashingAlgorithm,
1009 #[option] key_role_type: KeyRoleType,
1010 #[option] digital_signature_algorithm: DigitalSignatureAlgorithm,
1011 #[option] cryptographic_algorithm: CryptographicAlgorithm,
1012 #[option] random_iv: RandomIV,
1013 #[option] iv_length: IVLength,
1014 #[option] tag_length: TagLength,
1015 #[option] fixed_field_length: FixedFieldLength,
1016 #[option] invocation_field_length: InvocationFieldLength,
1017 #[option] counter_length: CounterLength,
1018 #[option] initial_counter_value: InitialCounterValue,
1019} as 0x42002B);
1020
1021impl From<CryptographicParameters> for AttributeValue {
1022 fn from(params: CryptographicParameters) -> Self {
1023 AttributeValue::CryptographicParameters(params)
1024 }
1025}
1026
1027#[derive(Clone, Copy, Debug, PartialEq, Eq)]
1029pub struct RandomIV(pub bool);
1030
1031impl_ttlv_serde!(bool RandomIV as 0x4200C5);
1032
1033#[derive(Clone, Copy, Debug, PartialEq, Eq)]
1035pub struct IVLength(pub i32);
1036
1037impl_ttlv_serde!(int IVLength as 0x4200CD);
1038
1039#[derive(Clone, Copy, Debug, PartialEq, Eq)]
1041pub struct TagLength(pub i32);
1042
1043impl_ttlv_serde!(int TagLength as 0x4200CE);
1044
1045#[derive(Clone, Copy, Debug, PartialEq, Eq)]
1047pub struct FixedFieldLength(pub i32);
1048
1049impl_ttlv_serde!(int FixedFieldLength as 0x4200CF);
1050
1051#[derive(Clone, Copy, Debug, PartialEq, Eq)]
1053pub struct InvocationFieldLength(pub i32);
1054
1055impl_ttlv_serde!(int InvocationFieldLength as 0x4200D2);
1056
1057#[derive(Clone, Copy, Debug, PartialEq, Eq)]
1059pub struct CounterLength(pub i32);
1060
1061impl_ttlv_serde!(int CounterLength as 0x4200D0);
1062
1063#[derive(Clone, Copy, Debug, PartialEq, Eq)]
1065pub struct InitialCounterValue(pub i32);
1066
1067impl_ttlv_serde!(int InitialCounterValue as 0x4200D1);
1068
1069#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
1071#[rustfmt::skip]
1072pub struct CryptographicDomainParameters {
1073 pub q_length: Option<i32>,
1074 pub recommended_curve: Option<RecommendedCurve>,
1075}
1076
1077impl CryptographicDomainParameters {
1078 pub fn with_q_length(self, value: i32) -> Self {
1079 Self {
1080 q_length: Some(value),
1081 ..self
1082 }
1083 }
1084
1085 pub fn with_recommended_curve(self, value: RecommendedCurve) -> Self {
1086 Self {
1087 recommended_curve: Some(value),
1088 ..self
1089 }
1090 }
1091}
1092
1093impl CryptographicDomainParameters {
1094 pub const TAG: Tag = Tag::new(0x420029);
1095 pub const Q_LENGTH_TAG: Tag = Tag::new(0x420073);
1096
1097 pub fn fast_scan(scanner: &mut FastScanner<'_>) -> Result<Self, FastScanError> {
1098 Self::fast_scan_with(scanner, Self::TAG)
1099 }
1100
1101 pub fn fast_scan_with(scanner: &mut FastScanner<'_>, tag: Tag) -> Result<Self, FastScanError> {
1102 let mut scanner = scanner.scan_struct(tag)?;
1103 let q_length = scanner.scan_opt_int(Self::Q_LENGTH_TAG)?;
1104 let recommended_curve = RecommendedCurve::fast_scan_opt(&mut scanner)?;
1105 scanner.finish()?;
1106 Ok(Self {
1107 q_length,
1108 recommended_curve,
1109 })
1110 }
1111
1112 pub fn format(&self, formatter: &mut Formatter<'_>) -> FormatResult {
1113 self.format_with(formatter, Self::TAG)
1114 }
1115
1116 pub fn format_with(&self, formatter: &mut Formatter<'_>, tag: Tag) -> FormatResult {
1117 let mut formatter = formatter.format_struct(tag)?;
1118 if let Some(q_length) = self.q_length {
1119 formatter.format_int(Self::Q_LENGTH_TAG, q_length)?;
1120 }
1121 if let Some(recommended_curve) = &self.recommended_curve {
1122 recommended_curve.format(&mut formatter)?;
1123 }
1124 Ok(formatter.finish())
1125 }
1126}
1127
1128impl From<CryptographicDomainParameters> for AttributeValue {
1129 fn from(params: CryptographicDomainParameters) -> Self {
1130 AttributeValue::CryptographicDomainParameters(params)
1131 }
1132}
1133
1134bitflags::bitflags! {
1135 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
1137 pub struct CryptographicUsageMask: i32 {
1138 const Sign = 0x00000001;
1139 const Verify = 0x00000002;
1140 const Encrypt = 0x00000004;
1141 const Decrypt = 0x00000008;
1142 const WrapKey = 0x00000010;
1143 const UnwrapKey = 0x00000020;
1144 const Export = 0x00000040;
1145 const MacGenerate = 0x00000080;
1146 const MacVerify = 0x00000100;
1147 const DeriveKey = 0x00000200;
1148 const ContentCommitmentNonRepudiation = 0x00000400;
1149 const KeyAgreement = 0x00000800;
1150 const CertificateSign = 0x00001000;
1151 const CrlSign = 0x00002000;
1152 const GenerateCryptogram = 0x00004000;
1153 const ValidateCryptogram = 0x00008000;
1154 const TranslateEncrypt = 0x00010000;
1155 const TranslateDecrypt = 0x00020000;
1156 const TranslateWrap = 0x00040000;
1157 const TranslateUnwrap = 0x00080000;
1158
1159 const _ = !0;
1160 }
1161}
1162
1163impl CryptographicUsageMask {
1164 pub const TAG: Tag = Tag::new(0x42002C);
1165
1166 pub fn fast_scan(scanner: &mut FastScanner<'_>) -> Result<Self, FastScanError> {
1167 Self::fast_scan_with(scanner, Self::TAG)
1168 }
1169
1170 pub fn fast_scan_with(scanner: &mut FastScanner<'_>, tag: Tag) -> Result<Self, FastScanError> {
1171 scanner.scan_int(tag).map(Self::from_bits_retain)
1172 }
1173
1174 pub fn fast_scan_opt(scanner: &mut FastScanner<'_>) -> Result<Option<Self>, FastScanError> {
1175 Self::fast_scan_opt_with(scanner, Self::TAG)
1176 }
1177
1178 pub fn fast_scan_opt_with(scanner: &mut FastScanner<'_>, tag: Tag) -> Result<Option<Self>, FastScanError> {
1179 scanner.scan_opt_int(tag).map(|s| s.map(Self::from_bits_retain))
1180 }
1181
1182 pub fn format(&self, formatter: &mut Formatter<'_>) -> FormatResult {
1183 self.format_with(formatter, Self::TAG)
1184 }
1185
1186 pub fn format_with(&self, formatter: &mut Formatter<'_>, tag: Tag) -> FormatResult {
1187 formatter.format_int(tag, self.bits())
1188 }
1189}
1190
1191#[derive(Clone, Copy, Debug, PartialEq, Eq)]
1193pub struct CompromiseOccurrenceDate(pub u64);
1194
1195impl_ttlv_serde!(date_time CompromiseOccurrenceDate as 0x420021);
1196
1197#[derive(Clone, Debug, PartialEq, Eq)]
1199pub struct RevocationMessage(pub String);
1200
1201impl_ttlv_serde!(text RevocationMessage as 0x420080);
1202
1203#[derive(Clone, Debug, PartialEq, Eq)]
1205pub struct LinkedObjectIdentifier(pub String);
1206
1207impl_ttlv_serde!(text LinkedObjectIdentifier as 0x42004C);
1208
1209#[derive(Clone, Debug, PartialEq, Eq)]
1211pub struct ApplicationNamespace(pub String);
1212
1213impl_ttlv_serde!(text ApplicationNamespace as 0x420003);
1214
1215#[derive(Clone, Debug, PartialEq, Eq)]
1217pub struct ApplicationData(pub String);
1218
1219impl_ttlv_serde!(text ApplicationData as 0x420002);
1220
1221#[derive(Clone, Debug, PartialEq, Eq)]
1223pub struct UniqueBatchItemID(pub Vec<u8>);
1224
1225impl PartialEq<Vec<u8>> for &UniqueBatchItemID {
1226 fn eq(&self, other: &Vec<u8>) -> bool {
1227 &self.0 == other
1228 }
1229}
1230
1231impl_ttlv_serde!(bytes UniqueBatchItemID as 0x420093);
1232
1233#[derive(Clone, Copy, Debug, PartialEq, Eq, Ordinalize)]
1235#[non_exhaustive]
1236#[repr(u32)]
1237pub enum KeyCompressionType {
1238 ECPUblicKeyTypeUncompressed = 1,
1239 ECPUblicKeyTypeX962CompressedPrime,
1240 ECPUblicKeyTypeX962CompressedChar2,
1241 ECPUblicKeyTypeX962Hybrid,
1242}
1243
1244impl_ttlv_serde!(enum KeyCompressionType as 0x420041);
1245
1246impl fmt::Display for KeyCompressionType {
1247 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1248 f.write_str(match self {
1249 Self::ECPUblicKeyTypeUncompressed => "ECPUblicKeyTypeUncompressed",
1250 Self::ECPUblicKeyTypeX962CompressedPrime => "ECPUblicKeyTypeX962CompressedPrime",
1251 Self::ECPUblicKeyTypeX962CompressedChar2 => "ECPUblicKeyTypeX962CompressedChar2",
1252 Self::ECPUblicKeyTypeX962Hybrid => "ECPUblicKeyTypeX962Hybrid",
1253 })
1254 }
1255}
1256
1257#[derive(Clone, Copy, Debug, PartialEq, Eq, Ordinalize)]
1259#[non_exhaustive]
1260#[repr(u32)]
1261pub enum KeyFormatType {
1262 Raw = 1,
1263 Opaque,
1264 PKCS1,
1265 PKCS8,
1266 X509,
1267 ECPrivateKey,
1268 TransparentSymmetricKey,
1269 TransparentDSAPrivateKey,
1270 TransparentDSAPublicKey,
1271 TransparentRSAPrivateKey,
1272 TransparentRSAPublicKey,
1273 TransparentDHPrivateKey,
1274 TransparentDHPublicKey,
1275 TransparentECDSAPrivateKey,
1276 TransparentECDSAPublicKey,
1277 TransparentECHDPrivateKey,
1278 TransparentECDHPublicKey,
1279 TransparentECMQVPrivateKey,
1280 TransparentECMQVPublicKey,
1281}
1282
1283impl_ttlv_serde!(enum KeyFormatType as 0x420042);
1284
1285impl fmt::Display for KeyFormatType {
1286 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1287 f.write_str(match self {
1288 Self::Raw => "Raw",
1289 Self::Opaque => "Opaque",
1290 Self::PKCS1 => "PKCS1",
1291 Self::PKCS8 => "PKCS8",
1292 Self::X509 => "X509",
1293 Self::ECPrivateKey => "ECPrivateKey",
1294 Self::TransparentSymmetricKey => "TransparentSymmetricKey",
1295 Self::TransparentDSAPrivateKey => "TransparentDSAPrivateKey",
1296 Self::TransparentDSAPublicKey => "TransparentDSAPublicKey",
1297 Self::TransparentRSAPublicKey => "TransparentRSAPublicKey",
1298 Self::TransparentRSAPrivateKey => "TransparentRSAPrivateKey",
1299 Self::TransparentDHPrivateKey => "TransparentDHPrivateKey",
1300 Self::TransparentDHPublicKey => "TransparentDHPublicKey",
1301 Self::TransparentECDSAPrivateKey => "TransparentECDSAPrivateKey",
1302 Self::TransparentECDSAPublicKey => "TransparentECDSAPublicKey",
1303 Self::TransparentECHDPrivateKey => "TransparentECHDPrivateKey",
1304 Self::TransparentECDHPublicKey => "TransparentECDHPublicKey",
1305 Self::TransparentECMQVPrivateKey => "TransparentECMQVPrivateKey",
1306 Self::TransparentECMQVPublicKey => "TransparentECMQVPublicKey",
1307 })
1308 }
1309}
1310
1311#[derive(Clone, Copy, Debug, PartialEq, Eq, Ordinalize)]
1313#[non_exhaustive]
1314#[allow(non_camel_case_types)]
1315#[repr(u32)]
1316pub enum RecommendedCurve {
1317 P_192 = 1,
1318 K_163,
1319 B_163,
1320 P_224,
1321 K_233,
1322 B_233,
1323 P_256,
1324 K_283,
1325 B_283,
1326 P_384,
1327 K_409,
1328 B_409,
1329 P_521,
1330 K_571,
1331 B_571,
1332}
1333
1334impl_ttlv_serde!(enum RecommendedCurve as 0x420075);
1335
1336impl fmt::Display for RecommendedCurve {
1337 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1338 f.write_str(match self {
1339 Self::P_192 => "P_192",
1340 Self::K_163 => "K_163",
1341 Self::B_163 => "B_163",
1342 Self::P_224 => "P_224",
1343 Self::K_233 => "K_233",
1344 Self::B_233 => "B_233",
1345 Self::P_256 => "P_256",
1346 Self::K_283 => "K_283",
1347 Self::B_283 => "B_283",
1348 Self::P_384 => "P_384",
1349 Self::K_409 => "K_409",
1350 Self::B_409 => "B_409",
1351 Self::P_521 => "P_521",
1352 Self::K_571 => "K_571",
1353 Self::B_571 => "B_571",
1354 })
1355 }
1356}
1357
1358#[derive(Clone, Copy, Debug, PartialEq, Eq, Ordinalize)]
1360#[non_exhaustive]
1361#[repr(u32)]
1362pub enum CertificateType {
1363 X509 = 1,
1364 PGP,
1365}
1366
1367impl_ttlv_serde!(enum CertificateType as 0x42001D);
1368
1369impl fmt::Display for CertificateType {
1370 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1371 f.write_str(match self {
1372 Self::X509 => "X509",
1373 Self::PGP => "PGP",
1374 })
1375 }
1376}
1377
1378#[derive(Clone, Copy, Debug, PartialEq, Eq, Ordinalize)]
1380#[non_exhaustive]
1381#[allow(non_camel_case_types)]
1382#[repr(u32)]
1383pub enum DigitalSignatureAlgorithm {
1384 MD2WithRSAEncryption_PKCS1_v1_5 = 1,
1385 MD5WithRSAEncryption_PKCS1_v1_5,
1386 SHA1WithRSAEncryption_PKCS1_v1_5,
1387 SHA224WithRSAEncryption_PKCS1_v1_5,
1388 SHA256WithRSAEncryption_PKCS1_v1_5,
1389 SHA384WithRSAEncryption_PKCS1_v1_5,
1390 SHA512WithRSAEncryption_PKCS1_v1_5,
1391 RSASSA_PSS_PKCS1_v1_5,
1392 DSAWithSHA1,
1393 DSAWithSHA224,
1394 DSAWithSHA256,
1395 ECDSAWithSHA1,
1396 ECDSAWithSHA224,
1397 ECDSAWithSHA256,
1398 ECDSAWithSHA384,
1399 ECDSAWithSHA512,
1400}
1401
1402impl_ttlv_serde!(enum DigitalSignatureAlgorithm as 0x4200AE);
1403
1404impl fmt::Display for DigitalSignatureAlgorithm {
1405 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1406 f.write_str(match self {
1407 Self::MD2WithRSAEncryption_PKCS1_v1_5 => "MD2WithRSAEncryption_PKCS1_v1_5",
1408 Self::MD5WithRSAEncryption_PKCS1_v1_5 => "MD5WithRSAEncryption_PKCS1_v1_5",
1409 Self::SHA1WithRSAEncryption_PKCS1_v1_5 => "SHA1WithRSAEncryption_PKCS1_v1_5",
1410 Self::SHA224WithRSAEncryption_PKCS1_v1_5 => "SHA224WithRSAEncryption_PKCS1_v1_5",
1411 Self::SHA256WithRSAEncryption_PKCS1_v1_5 => "SHA256WithRSAEncryption_PKCS1_v1_5",
1412 Self::SHA384WithRSAEncryption_PKCS1_v1_5 => "SHA384WithRSAEncryption_PKCS1_v1_5",
1413 Self::SHA512WithRSAEncryption_PKCS1_v1_5 => "SHA512WithRSAEncryption_PKCS1_v1_5",
1414 Self::RSASSA_PSS_PKCS1_v1_5 => "RSASSA_PSS_PKCS1_v1_5",
1415 Self::DSAWithSHA1 => "DSAWithSHA1",
1416 Self::DSAWithSHA224 => "DSAWithSHA224",
1417 Self::DSAWithSHA256 => "DSAWithSHA256",
1418 Self::ECDSAWithSHA1 => "ECDSAWithSHA1",
1419 Self::ECDSAWithSHA224 => "ECDSAWithSHA224",
1420 Self::ECDSAWithSHA256 => "ECDSAWithSHA256",
1421 Self::ECDSAWithSHA384 => "ECDSAWithSHA384",
1422 Self::ECDSAWithSHA512 => "ECDSAWithSHA512",
1423 })
1424 }
1425}
1426
1427#[derive(Clone, Copy, Debug, PartialEq, Eq, Ordinalize)]
1429#[non_exhaustive]
1430#[repr(u32)]
1431pub enum NameType {
1432 UninterpretedTextString = 1,
1433 URI,
1434}
1435
1436impl_ttlv_serde!(enum NameType as 0x420054);
1437
1438impl fmt::Display for NameType {
1439 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1440 f.write_str(match self {
1441 Self::UninterpretedTextString => "UninterpretedTextString",
1442 Self::URI => "URI",
1443 })
1444 }
1445}
1446
1447#[derive(Clone, Copy, Debug, PartialEq, Eq, Ordinalize)]
1449#[non_exhaustive]
1450#[allow(non_camel_case_types)]
1451#[repr(u32)]
1452pub enum BlockCipherMode {
1453 CBC = 1,
1454 ECB,
1455 PCBC,
1456 CFB,
1457 OFB,
1458 CTR,
1459 CMAC,
1460 CCM,
1461 GCM,
1462 CBC_MAC,
1463 XTS,
1464 AESKeyWrapPadding,
1465 NISTKeyWrap,
1466 X9_102_AESKW,
1467 X9_102_TDKW,
1468 X9_102_AKW1,
1469 X9_102_AKW2,
1470}
1471
1472impl_ttlv_serde!(enum BlockCipherMode as 0x420011);
1473
1474impl fmt::Display for BlockCipherMode {
1475 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1476 f.write_str(match self {
1477 Self::CBC => "CBC",
1478 Self::ECB => "ECB",
1479 Self::PCBC => "PCBC",
1480 Self::CFB => "CFB",
1481 Self::OFB => "OFB",
1482 Self::CTR => "CTR",
1483 Self::CMAC => "CMAC",
1484 Self::CCM => "CCM",
1485 Self::GCM => "GCM",
1486 Self::CBC_MAC => "CBC_MAC",
1487 Self::XTS => "XTS",
1488 Self::AESKeyWrapPadding => "AESKeyWrapPadding",
1489 Self::NISTKeyWrap => "NISTKeyWrap",
1490 Self::X9_102_AESKW => "X9_102_AESKW",
1491 Self::X9_102_TDKW => "X9_102_TDKW",
1492 Self::X9_102_AKW1 => "X9_102_AKW1",
1493 Self::X9_102_AKW2 => "X9_102_AKW2",
1494 })
1495 }
1496}
1497
1498#[derive(Clone, Copy, Debug, PartialEq, Eq, Ordinalize)]
1500#[non_exhaustive]
1501#[allow(non_camel_case_types)]
1502#[repr(u32)]
1503pub enum PaddingMethod {
1504 None = 1,
1505 OAEP,
1506 PKCS5,
1507 SSL3,
1508 Zeros,
1509 ANSI_X9_23,
1510 ISO_10126,
1511 PKCS1_v1_5,
1512 X9_31,
1513 PSS,
1514}
1515
1516impl_ttlv_serde!(enum PaddingMethod as 0x42005F);
1517
1518impl fmt::Display for PaddingMethod {
1519 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1520 f.write_str(match self {
1521 Self::None => "None",
1522 Self::OAEP => "OAEP",
1523 Self::PKCS5 => "PKCS5",
1524 Self::SSL3 => "SSL3",
1525 Self::Zeros => "Zeros",
1526 Self::ANSI_X9_23 => "ANSI_X9_23",
1527 Self::ISO_10126 => "ISO_10126",
1528 Self::PKCS1_v1_5 => "PKCS1_v1_5",
1529 Self::X9_31 => "X9_31",
1530 Self::PSS => "PSS",
1531 })
1532 }
1533}
1534
1535#[derive(Clone, Copy, Debug, PartialEq, Eq, Ordinalize)]
1537#[non_exhaustive]
1538#[allow(non_camel_case_types)]
1539#[repr(u32)]
1540pub enum HashingAlgorithm {
1541 MD2 = 1,
1542 MD4,
1543 MD5,
1544 SHA1,
1545 SHA224,
1546 SHA256,
1547 SHA384,
1548 SHA512,
1549 RIPEMD160,
1550 Tiger,
1551 Whirlpool,
1552}
1553
1554impl_ttlv_serde!(enum HashingAlgorithm as 0x420038);
1555
1556impl fmt::Display for HashingAlgorithm {
1557 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1558 f.write_str(match self {
1559 Self::MD2 => "MD2",
1560 Self::MD4 => "MD4",
1561 Self::MD5 => "MD5",
1562 Self::SHA1 => "SHA1",
1563 Self::SHA224 => "SHA224",
1564 Self::SHA256 => "SHA256",
1565 Self::SHA384 => "SHA384",
1566 Self::SHA512 => "SHA512",
1567 Self::RIPEMD160 => "RIPEMD160",
1568 Self::Tiger => "Tiger",
1569 Self::Whirlpool => "Whirlpool",
1570 })
1571 }
1572}
1573
1574#[derive(Clone, Copy, Debug, PartialEq, Eq, Ordinalize)]
1576#[non_exhaustive]
1577#[allow(non_camel_case_types)]
1578#[repr(u32)]
1579pub enum KeyRoleType {
1580 BDK = 1,
1581 CVK,
1582 DEK,
1583 MKAC,
1584 MKSMC,
1585 MKSMI,
1586 MKDAC,
1587 MKDN,
1588 MKCP,
1589 MKOTH,
1590 KEK,
1591 MAC16609,
1592 MAC97971,
1593 MAC97972,
1594 MAC97973,
1595 MAC97974,
1596 MAC97975,
1597 ZPK,
1598 PVKIBM,
1599 PVKPVV,
1600 PVKOTH,
1601}
1602
1603impl_ttlv_serde!(enum KeyRoleType as 0x420083);
1604
1605impl fmt::Display for KeyRoleType {
1606 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1607 f.write_str(match self {
1608 Self::BDK => "BDK",
1609 Self::CVK => "CVK",
1610 Self::DEK => "DEK",
1611 Self::MKAC => "MKAC",
1612 Self::MKSMC => "MKSMC",
1613 Self::MKSMI => "MKSMI",
1614 Self::MKDAC => "MKDAC",
1615 Self::MKDN => "MKDN",
1616 Self::MKCP => "MKCP",
1617 Self::MKOTH => "MKOTH",
1618 Self::KEK => "KEK",
1619 Self::MAC16609 => "MAC16609",
1620 Self::MAC97971 => "MAC97971",
1621 Self::MAC97972 => "MAC97972",
1622 Self::MAC97973 => "MAC97973",
1623 Self::MAC97974 => "MAC97974",
1624 Self::MAC97975 => "MAC97975",
1625 Self::ZPK => "ZPK",
1626 Self::PVKIBM => "PVKIBM",
1627 Self::PVKPVV => "PVKPVV",
1628 Self::PVKOTH => "PVKOTH",
1629 })
1630 }
1631}
1632
1633#[derive(Clone, Copy, Debug, PartialEq, Eq, Ordinalize)]
1635#[non_exhaustive]
1636#[repr(u32)]
1637pub enum State {
1638 PreActive = 1,
1639 Active,
1640 Deactivated,
1641 Compromised,
1642 Destroyed,
1643 DestroyedCompromised,
1644}
1645
1646impl_ttlv_serde!(enum State as 0x42008D);
1647
1648impl fmt::Display for State {
1649 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1650 f.write_str(match self {
1651 Self::PreActive => "PreActive",
1652 Self::Active => "Active",
1653 Self::Deactivated => "Deactivated",
1654 Self::Compromised => "Compromised",
1655 Self::Destroyed => "Destroyed",
1656 Self::DestroyedCompromised => "DestroyedCompromised",
1657 })
1658 }
1659}
1660
1661#[derive(Clone, Copy, Debug, PartialEq, Eq, Ordinalize)]
1663#[non_exhaustive]
1664#[repr(u32)]
1665pub enum RevocationReasonCode {
1666 Unspecified = 1,
1667 KeyCompromise,
1668 CACompromise,
1669 AffiliationChanged,
1670 Superseded,
1671 CessationOfOperation,
1672 PrivilegeWithdrawn,
1673}
1674
1675impl_ttlv_serde!(enum RevocationReasonCode as 0x420082);
1676
1677impl fmt::Display for RevocationReasonCode {
1678 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1679 f.write_str(match self {
1680 Self::Unspecified => "Unspecified",
1681 Self::KeyCompromise => "KeyCompromise",
1682 Self::CACompromise => "CACompromise",
1683 Self::AffiliationChanged => "AffiliationChanged",
1684 Self::Superseded => "Superseded",
1685 Self::CessationOfOperation => "CessationOfOperation",
1686 Self::PrivilegeWithdrawn => "PrivilegeWithdrawn",
1687 })
1688 }
1689}
1690
1691#[derive(Clone, Copy, Debug, PartialEq, Eq, Ordinalize)]
1693#[non_exhaustive]
1694#[repr(u32)]
1695pub enum LinkType {
1696 CertificateLink = 0x101,
1697 PublicKeyLink,
1698 PrivateKeyLink,
1699 DerivationBaseObjectLink,
1700 DerivedKeyLink,
1701 ReplacementObjectLink,
1702 ReplacedObjectLink,
1703}
1704
1705impl_ttlv_serde!(enum LinkType as 0x42004B);
1706
1707impl fmt::Display for LinkType {
1708 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1709 f.write_str(match self {
1710 Self::CertificateLink => "CertificateLink",
1711 Self::PublicKeyLink => "PublicKeyLink",
1712 Self::PrivateKeyLink => "PrivateKeyLink",
1713 Self::DerivationBaseObjectLink => "DerivationBaseObjectLink",
1714 Self::DerivedKeyLink => "DerivedKeyLink",
1715 Self::ReplacementObjectLink => "ReplacementObjectLink",
1716 Self::ReplacedObjectLink => "ReplacedObjectLink",
1717 })
1718 }
1719}
1720
1721#[derive(Clone, Copy, Debug, PartialEq, Eq, Ordinalize)]
1723#[non_exhaustive]
1724#[repr(u32)]
1725pub enum Operation {
1726 Create = 1,
1728 CreateKeyPair,
1729 Register,
1730 Rekey,
1731 DeriveKey,
1732 Certify,
1733 Recertify,
1734 Locate,
1735 Check,
1736 Get,
1737 GetAttributes,
1738 GetAttributeList,
1739 AddAttribute,
1740 ModifyAttribute,
1741 DeleteAttribute,
1742 ObtainLease,
1743 GetUsageAllocation,
1744 Activate,
1745 Revoke,
1746 Destroy,
1747 Archive,
1748 Recover,
1749 Validate,
1750 Query,
1751 Cancel,
1752 Poll,
1753 Notify,
1754 Put,
1755
1756 RekeyKeyPair,
1758 DiscoverVersions,
1759
1760 Encrypt,
1762 Decrypt,
1763 Sign,
1764 SignatureVerify,
1765 MAC,
1766 MACVerify,
1767 RNGRetrieve,
1768 RNGSeed,
1769 Hash,
1770 CreateSplitKey,
1771 JoinSplitKey,
1772}
1773
1774impl_ttlv_serde!(enum Operation as 0x42005C);
1775
1776impl fmt::Display for Operation {
1777 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1778 f.write_str(match self {
1779 Self::Create => "Create",
1780 Self::CreateKeyPair => "CreateKeyPair",
1781 Self::Register => "Register",
1782 Self::Rekey => "Rekey",
1783 Self::DeriveKey => "DeriveKey",
1784 Self::Certify => "Certify",
1785 Self::Recertify => "Recertify",
1786 Self::Locate => "Locate",
1787 Self::Check => "Check",
1788 Self::Get => "Get",
1789 Self::GetAttributes => "GetAttributes",
1790 Self::GetAttributeList => "GetAttributeList",
1791 Self::AddAttribute => "AddAttribute",
1792 Self::ModifyAttribute => "ModifyAttribute",
1793 Self::DeleteAttribute => "DeleteAttribute",
1794 Self::ObtainLease => "ObtainLease",
1795 Self::GetUsageAllocation => "GetUsageAllocation",
1796 Self::Activate => "Activate",
1797 Self::Revoke => "Revoke",
1798 Self::Destroy => "Destroy",
1799 Self::Archive => "Archive",
1800 Self::Recover => "Recover",
1801 Self::Validate => "Validate",
1802 Self::Query => "Query",
1803 Self::Cancel => "Cancel",
1804 Self::Poll => "Poll",
1805 Self::Notify => "Notify",
1806 Self::Put => "Put",
1807 Self::RekeyKeyPair => "RekeyKeyPair",
1808 Self::DiscoverVersions => "DiscoverVersions",
1809 Self::Encrypt => "Encrypt",
1810 Self::Decrypt => "Decrypt",
1811 Self::Sign => "Sign",
1812 Self::SignatureVerify => "SignatureVerify",
1813 Self::MAC => "MAC",
1814 Self::MACVerify => "MACVerify",
1815 Self::RNGRetrieve => "RNGRetrieve",
1816 Self::RNGSeed => "RNGSeed",
1817 Self::Hash => "Hash",
1818 Self::CreateSplitKey => "CreateSplitKey",
1819 Self::JoinSplitKey => "JoinSplitKey",
1820 })
1821 }
1822}
1823
1824#[cfg(test)]
1825mod test {
1826 use super::Operation;
1827
1828 #[test]
1829 fn test_operation_display() {
1830 assert_ne!("WrongName", &format!("{}", Operation::Create));
1831 assert_eq!("Create", &format!("{}", Operation::Create));
1832 assert_eq!("CreateKeyPair", &format!("{}", Operation::CreateKeyPair));
1833 assert_eq!("Register", &format!("{}", Operation::Register));
1834 }
1835}