@@ -183,21 +183,45 @@ mod choice {
183183
184184 mod generic_implicit {
185185 use der:: {
186- Choice , Decode , Encode , SliceWriter ,
186+ Choice , Decode , DecodeValue , Encode , EncodeValue , FixedTag , IsConstructed , Sequence ,
187+ SliceWriter , Tagged ,
187188 asn1:: { BitStringRef , GeneralizedTime } ,
188189 } ;
190+
189191 use hex_literal:: hex;
190192
191193 /// 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+ /// ```
192217 #[ derive( Choice , Clone , Debug , Eq , PartialEq ) ]
193218 pub enum ObjectValue < T >
194219 where
195- for < ' a > T : Encode + Decode < ' a > + EncodeValue + Tagged ,
220+ for < ' a > T : Encode + Decode < ' a > + EncodeValue + DecodeValue < ' a > + FixedTag ,
196221 {
197- #[ asn1( tag_mode = "EXPLICIT" ) ]
198- Indirect ( ReferencedValue ) ,
222+ Indirect ( Path ) ,
199223
200- #[ asn1( context_specific = "0" , tag_mode = "EXPLICIT " ) ]
224+ #[ asn1( context_specific = "0" , tag_mode = "IMPLICIT " ) ]
201225 Direct ( T ) ,
202226 }
203227
@@ -209,26 +233,37 @@ mod choice {
209233 /// }
210234 /// ```
211235 #[ derive( Choice , Clone , Debug , Eq , PartialEq ) ]
212- #[ serde( deny_unknown_fields) ]
213236 pub enum RSAPublicKeyChoice {
214237 /// `raw RSAPublicKey`
215238 Raw ( RSAPublicKey ) ,
239+
240+ /// `spki [1] SubjectPublicKeyInfo`
241+ #[ asn1( context_specific = "0" , tag_mode = "IMPLICIT" ) ]
242+ Spki ( ( ) ) ,
216243 }
244+ #[ derive( Sequence , Clone , Debug , Eq , PartialEq ) ]
217245
218- // TODO
219- pub type ReferencedValue = ReferencedValueChoice ;
246+ pub struct RSAPublicKey {
247+ rsa_key_field : u8 ,
248+ }
220249
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) ;
232267 }
233268 }
234269}
0 commit comments