@@ -787,6 +787,140 @@ mod decode_encode_value {
787787 }
788788}
789789
790+ #[ cfg( all( feature = "derive" , feature = "oid" ) ) ]
791+ mod custom_application {
792+ use const_oid:: ObjectIdentifier ;
793+ use der:: { Decode , DecodeValue , Encode , EncodeValue , FixedTag , Sequence , Tag , TagNumber } ;
794+ use hex_literal:: hex;
795+
796+ const TACHO_CERT_DER : & [ u8 ] = & hex ! (
797+ "7F 21 81 C8" // Application 33
798+
799+ "7F 4E 81 81" // Application 78
800+
801+ "5F 29" // Application 41
802+ "01 00"
803+ "42 08" // Application 2
804+ "FD 45 43 20 01 FF FF 01"
805+ "5F 4C 07" // Application 76
806+ "FF 53 4D 52 44 54 0E"
807+ "7F 49 4D" // Application 73
808+ "06 08 2A 86 48 CE 3D 03 01 07 86 41 04
809+ 30 E8 EE D8 05 1D FB 8F 05 BF 4E 34 90 B8 A0 1C
810+ 83 21 37 4E 99 41 67 70 64 28 23 A2 C9 E1 21 16
811+ D9 27 46 45 94 DD CB CC 79 42 B5 F3 EE 1A A3 AB
812+ A2 5C E1 6B 20 92 00 F0 09 70 D9 CF 83 0A 33 4B"
813+
814+
815+ "5F 20 08" // Application 32
816+ "17 47 52 20 02 FF FF 01"
817+ "5F 25 04" // Application 37
818+ "62 A3 B0 D0"
819+ "5F 24 04" // Application 36
820+ "6F F6 49 50"
821+ "5F 37 40" // Application 55
822+ "6D 3E FD 97
823+ BE 83 EC 65 5F 51 4D 8C 47 60 DB FD 9B A2 D1 5D
824+ 3C 1A 21 93 CE D7 EA F2 A2 0D 89 CC 4A 4F 0C 4B
825+ E5 3F A3 F9 0F 20 B5 74 67 26 DB 19 9E FF DE 0B
826+ D0 B9 2C B9 D1 5A E2 18 08 6C F0 E2"
827+ ) ;
828+
829+ /// EU Tachograph G2 certificate
830+ #[ derive( DecodeValue , EncodeValue ) ]
831+ #[ asn1( tag_mode = "IMPLICIT" ) ]
832+ pub struct TachographCertificate < ' a > {
833+ /// constructed
834+ #[ asn1( application = "78" ) ]
835+ pub body : TachographCertificateBody < ' a > ,
836+
837+ /// primitive
838+ #[ asn1( application = "55" , type = "OCTET STRING" ) ]
839+ pub signature : & ' a [ u8 ] ,
840+ }
841+
842+ impl FixedTag for TachographCertificate < ' _ > {
843+ const TAG : Tag = Tag :: Application {
844+ number : TagNumber ( 33 ) , // 7F 21
845+ constructed : true ,
846+ } ;
847+ }
848+
849+ /// EU Tachograph G2 certificate body
850+ #[ derive( Sequence ) ]
851+ #[ asn1( tag_mode = "IMPLICIT" ) ]
852+ pub struct TachographCertificateBody < ' a > {
853+ /// primitive
854+ #[ asn1( application = "41" , type = "OCTET STRING" ) ]
855+ pub profile_identifier : & ' a [ u8 ] ,
856+
857+ /// primitive
858+ #[ asn1( application = "2" , type = "OCTET STRING" ) ]
859+ pub authority_reference : & ' a [ u8 ] ,
860+
861+ /// primitive
862+ #[ asn1( application = "76" , type = "OCTET STRING" ) ]
863+ pub holder_authorisation : & ' a [ u8 ] ,
864+
865+ /// constructed
866+ #[ asn1( application = "73" ) ]
867+ pub public_key : CertificatePublicKey < ' a > ,
868+
869+ /// primitive
870+ #[ asn1( application = "32" , type = "OCTET STRING" ) ]
871+ pub holder_reference : & ' a [ u8 ] ,
872+
873+ /// primitive
874+ #[ asn1( application = "37" , type = "OCTET STRING" ) ]
875+ pub effective_date : & ' a [ u8 ] ,
876+
877+ /// primitive
878+ #[ asn1( application = "36" , type = "OCTET STRING" ) ]
879+ pub expiration_date : & ' a [ u8 ] ,
880+ }
881+
882+ /// EU Tachograph G2 certificate public key
883+ #[ derive( Sequence ) ]
884+ #[ asn1( tag_mode = "IMPLICIT" ) ]
885+ pub struct CertificatePublicKey < ' a > {
886+ pub domain_parameters : ObjectIdentifier ,
887+
888+ #[ asn1( context_specific = "6" , type = "OCTET STRING" ) ]
889+ pub public_point : & ' a [ u8 ] ,
890+ }
891+ #[ test]
892+ fn decode_tacho_application_tags ( ) {
893+ let tacho_cert = TachographCertificate :: from_der ( TACHO_CERT_DER ) . unwrap ( ) ;
894+
895+ let sig = tacho_cert. signature ;
896+ assert_eq ! ( & sig[ ..2 ] , hex!( "6D 3E" ) ) ;
897+ assert_eq ! ( tacho_cert. body. profile_identifier, & [ 0x00 ] ) ;
898+ assert_eq ! (
899+ tacho_cert. body. authority_reference,
900+ hex!( "FD 45 43 20 01 FF FF 01" )
901+ ) ;
902+ assert_eq ! (
903+ tacho_cert. body. holder_authorisation,
904+ hex!( "FF 53 4D 52 44 54 0E" )
905+ ) ;
906+ assert_eq ! (
907+ tacho_cert. body. public_key. domain_parameters,
908+ ObjectIdentifier :: new_unwrap( "1.2.840.10045.3.1.7" )
909+ ) ;
910+ assert_eq ! (
911+ & tacho_cert. body. public_key. public_point[ ..4 ] ,
912+ hex!( "04 30 E8 EE" )
913+ ) ;
914+ const GREECE : & [ u8 ] = b"GR " ;
915+ assert_eq ! ( & tacho_cert. body. holder_reference[ 1 ..4 ] , GREECE ) ;
916+
917+ // Re-encode
918+ let mut buf = [ 0u8 ; 256 ] ;
919+ let encoded = tacho_cert. encode_to_slice ( & mut buf) . unwrap ( ) ;
920+ assert_eq ! ( encoded, TACHO_CERT_DER ) ;
921+ }
922+ }
923+
790924/// Custom derive test cases for the `BitString` macro.
791925#[ cfg( feature = "std" ) ]
792926mod bitstring {
0 commit comments