@@ -183,21 +183,45 @@ mod choice {
183
183
184
184
mod generic_implicit {
185
185
use der:: {
186
- Choice , Decode , Encode , SliceWriter ,
186
+ Choice , Decode , DecodeValue , Encode , EncodeValue , FixedTag , IsConstructed , Sequence ,
187
+ SliceWriter , Tagged ,
187
188
asn1:: { BitStringRef , GeneralizedTime } ,
188
189
} ;
190
+
189
191
use hex_literal:: hex;
190
192
191
193
/// PKCS#15 ObjectValue
194
+ /// ```asn1
195
+ /// ObjectValue { Type } ::= CHOICE {
196
+ /// indirect Path,
197
+ /// direct [0] Type,
198
+ /// }
199
+ /// ```
200
+ ///
201
+ /// Example:
202
+ /// ```txt
203
+ ///
204
+ /// 30 06
205
+ /// 30 04
206
+ /// 04 02 43 32
207
+ /// ```
208
+ ///
209
+ /// ```txt
210
+ /// value ObjectValue CHOICE
211
+ /// indirect ReferencedValue CHOICE
212
+ /// path Path SEQUENCE: tag = [UNIVERSAL 16] constructed; length = 4
213
+ /// efidOrPath OCTET STRING: tag = [UNIVERSAL 4] primitive; length = 2
214
+ /// 0x4332
215
+ ///
216
+ /// ```
192
217
#[ derive( Choice , Clone , Debug , Eq , PartialEq ) ]
193
218
pub enum ObjectValue < T >
194
219
where
195
- for < ' a > T : Encode + Decode < ' a > + EncodeValue + Tagged ,
220
+ for < ' a > T : Encode + Decode < ' a > + EncodeValue + DecodeValue < ' a > + FixedTag ,
196
221
{
197
- #[ asn1( tag_mode = "EXPLICIT" ) ]
198
- Indirect ( ReferencedValue ) ,
222
+ Indirect ( Path ) ,
199
223
200
- #[ asn1( context_specific = "0" , tag_mode = "EXPLICIT " ) ]
224
+ #[ asn1( context_specific = "0" , tag_mode = "IMPLICIT " ) ]
201
225
Direct ( T ) ,
202
226
}
203
227
@@ -209,26 +233,37 @@ mod choice {
209
233
/// }
210
234
/// ```
211
235
#[ derive( Choice , Clone , Debug , Eq , PartialEq ) ]
212
- #[ serde( deny_unknown_fields) ]
213
236
pub enum RSAPublicKeyChoice {
214
237
/// `raw RSAPublicKey`
215
238
Raw ( RSAPublicKey ) ,
239
+
240
+ /// `spki [1] SubjectPublicKeyInfo`
241
+ #[ asn1( context_specific = "0" , tag_mode = "IMPLICIT" ) ]
242
+ Spki ( ( ) ) ,
216
243
}
244
+ #[ derive( Sequence , Clone , Debug , Eq , PartialEq ) ]
217
245
218
- // TODO
219
- pub type ReferencedValue = ReferencedValueChoice ;
246
+ pub struct RSAPublicKey {
247
+ rsa_key_field : u8 ,
248
+ }
220
249
221
- /// ```asn1
222
- /// ReferencedValue {Type} ::= CHOICE {
223
- /// path Path,
224
- /// url URL
225
- /// } (CONSTRAINED BY {-- 'path' or 'url' shall point to an object of type -- Type})
226
- /// ```
227
- #[ derive( Clone , Debug , Eq , PartialEq , Choice , Serialize , Deserialize ) ]
228
- pub enum ReferencedValueChoice {
229
- Path ( Path ) ,
230
- // todo
231
- URL ( Url ) ,
250
+ // pub type ReferencedValue = Path;
251
+
252
+ #[ derive( Sequence , Clone , Debug , Eq , PartialEq ) ]
253
+ pub struct Path {
254
+ path_field : u8 ,
255
+ }
256
+
257
+ #[ test]
258
+ fn test_roundtrip_objectvalue_rsa ( ) {
259
+ let rsa_key = RSAPublicKey { rsa_key_field : 1 } ;
260
+ let rsa_choice = RSAPublicKeyChoice :: Raw ( rsa_key) ;
261
+ let object_value = ObjectValue :: Direct ( rsa_choice) ;
262
+
263
+ let obj_der = object_value. to_der ( ) . unwrap ( ) ;
264
+
265
+ let dec_object_value = ObjectValue :: < RSAPublicKeyChoice > :: from_der ( obj_der) . unwrap ( ) ;
266
+ assert_eq ! ( dec_object_value, object_value) ;
232
267
}
233
268
}
234
269
}
0 commit comments