|
2 | 2 | #![cfg(all(feature = "derive", feature = "alloc", feature = "clarify"))]
|
3 | 3 |
|
4 | 4 | pub mod sequence {
|
5 |
| - use std::println; |
| 5 | + use std::{println, str::FromStr}; |
6 | 6 |
|
7 | 7 | use const_oid::ObjectIdentifier;
|
8 | 8 | use der::{
|
9 |
| - AnyRef, ClarifyFlavor, Decode, EncodeClarifyExt, Sequence, ValueOrd, |
| 9 | + AnyRef, ClarifyFlavor, Decode, EncodeClarifyExt, Sequence, TagNumber, ValueOrd, |
10 | 10 | asn1::{OctetString, SetOf},
|
11 | 11 | };
|
12 | 12 | use hex_literal::hex;
|
@@ -84,4 +84,68 @@ pub mod sequence {
|
84 | 84 | "\n\"04 11\" // tag: OCTET STRING len: 17 type: OctetString \n\t\"00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF \n\t01\"\n\"\" // end: OctetString "
|
85 | 85 | );
|
86 | 86 | }
|
| 87 | + #[test] |
| 88 | + fn clarify_one_assymetric_key_rusthex() { |
| 89 | + let obj = OneAsymmetricKey { |
| 90 | + version: 1, |
| 91 | + private_key_algorithm: AlgorithmIdentifier { |
| 92 | + algorithm: ObjectIdentifier::from_str("1.2.3.4.5.6.7.8").expect("valid oid"), |
| 93 | + parameters: Some( |
| 94 | + AnyRef::new( |
| 95 | + der::Tag::ContextSpecific { |
| 96 | + constructed: true, |
| 97 | + number: TagNumber(0), |
| 98 | + }, |
| 99 | + &[0xAA, 0xBB], |
| 100 | + ) |
| 101 | + .expect("valid length"), |
| 102 | + ), |
| 103 | + }, |
| 104 | + private_key: &[ |
| 105 | + 0x00, 0x11, 0x22, 0x33, 0x00, 0x11, 0x22, 0x33, 0x00, 0x11, 0x22, 0x33, 0x00, 0x11, |
| 106 | + 0x22, 0x33, 0x00, 0x11, 0x22, 0x33, 0x00, 0x11, 0x22, 0x33, 0x00, 0x11, 0x22, 0x33, |
| 107 | + ], |
| 108 | + attributes: None, |
| 109 | + public_key: Some(&[ |
| 110 | + 0x44, 0x55, 0x66, 0x77, 0x44, 0x55, 0x66, 0x77, 0x44, 0x55, 0x66, 0x77, 0x44, 0x55, |
| 111 | + 0x66, 0x77, 0x44, 0x55, 0x66, 0x77, 0x44, 0x55, 0x66, 0x77, 0x44, 0x55, 0x66, 0x77, |
| 112 | + ]), |
| 113 | + }; |
| 114 | + let clarified = obj |
| 115 | + .to_der_clarify(ClarifyFlavor::RustHex) |
| 116 | + .expect("encoded DER"); |
| 117 | + |
| 118 | + //println!("clarified: {clarified}"); |
| 119 | + |
| 120 | + assert!(clarified.contains("type: OneAsymmetricKey")); |
| 121 | + assert!(clarified.contains("tag: CONTEXT-SPECIFIC [0] (constructed)")); |
| 122 | + assert!(clarified.contains("tag: CONTEXT-SPECIFIC [1] (constructed)")); |
| 123 | + assert!(clarified.contains("type: AlgorithmIdentifier")); |
| 124 | + assert!(clarified.contains("tag: OBJECT IDENTIFIER")); |
| 125 | + assert!(clarified.contains("type: ObjectIdentifier")); |
| 126 | + assert!(clarified.contains("end: OneAsymmetricKey")); |
| 127 | + |
| 128 | + hex!( |
| 129 | + "30 51" // tag: SEQUENCE len: 81 type: OneAsymmetricKey |
| 130 | + "02 01" // tag: INTEGER type: u8 |
| 131 | + "01" |
| 132 | + "30 0D" // tag: SEQUENCE len: 13 type: AlgorithmIdentifier |
| 133 | + "06 07" // tag: OBJECT IDENTIFIER type: ObjectIdentifier |
| 134 | + "2A 03 04 05 06 07 08" |
| 135 | + "A0 02" // tag: CONTEXT-SPECIFIC [0] (constructed) type: AnyRef |
| 136 | + "AA BB" |
| 137 | + "04 1C" // tag: OCTET STRING len: 28 type: OctetStringRef |
| 138 | + "00 11 22 33 00 11 22 33 00 11 22 33 00 11 22 33 |
| 139 | + 00 11 22 33 00 11 22 33 00 11 22 33" |
| 140 | + "" // end: OctetStringRef |
| 141 | + "A1 1F" // tag: CONTEXT-SPECIFIC [1] (constructed) len: 31 type: ContextSpecificRef<BitStringRef> |
| 142 | + "03 1D" // tag: BIT STRING len: 29 type: BitStringRef |
| 143 | + "00" |
| 144 | + "44 55 66 77 44 55 66 77 44 55 66 77 44 55 66 77 |
| 145 | + 44 55 66 77 44 55 66 77 44 55 66 77" |
| 146 | + "" // end: BitStringRef |
| 147 | + "" // end: ContextSpecificRef<BitStringRef> |
| 148 | + "" // end: OneAsymmetricKey |
| 149 | + ); |
| 150 | + } |
87 | 151 | }
|
0 commit comments