-
-
Notifications
You must be signed in to change notification settings - Fork 73
Open
Description
in X.690 section 8.14 example, BER encoding of tagged type is illustrated as follows:
With ASN.1 type definitions (in an explicit tagging environment) of:
Type1 ::= VisibleString
Type2 ::= [APPLICATION 3] IMPLICIT Type1
Type3 ::= [2] Type2
Type4 ::= [APPLICATION 7] IMPLICIT Type3
Type5 ::= [2] IMPLICIT Type2
a value of "Jones" is encoded as follows:
Type1: 1A 05 4A6F6E6573
Type2: 43 05 4A6F6E6573
Type3: A2 07 43 05 4A6F6E6573
Type4: 67 07 43 05 4A6F6E6573
Type5: 82 05 4A6F6E6573
However, Type4 is not encoded as shown in this example.
It is encoded as A2 07 43 05 4A6F6E6573 instead.
Code to reproduce:
#[test]
fn test_ber_encoding_of_tagged_type() {
use rasn::prelude::*;
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, Eq, Hash)]
#[rasn(delegate)]
pub struct Type1(pub VisibleString);
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, Eq, Hash)]
#[rasn(delegate, tag(application, 3))]
pub struct Type2(pub Type1);
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, Eq, Hash)]
#[rasn(delegate, tag(explicit(context, 2)))]
pub struct Type3(pub Type2);
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, Eq, Hash)]
#[rasn(delegate, tag(application, 7))]
pub struct Type4(pub Type3);
#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq, Eq, Hash)]
#[rasn(delegate, tag(context, 2))]
pub struct Type5(pub Type2);
let type1 = Type1(VisibleString::from_iso646_bytes(b"Jones").unwrap());
let type2 = Type2(type1.clone());
let type3 = Type3(type2.clone());
let type4 = Type4(type3.clone());
let type5 = Type5(type2.clone());
let type1_ber = rasn::ber::encode(&type1).unwrap();
let type2_ber = rasn::ber::encode(&type2).unwrap();
let type3_ber = rasn::ber::encode(&type3).unwrap();
let type4_ber = rasn::ber::encode(&type4).unwrap();
let type5_ber = rasn::ber::encode(&type5).unwrap();
assert_eq!(type1_ber, vec![0x1A, 0x05, 0x4A, 0x6F, 0x6E, 0x65, 0x73_u8]);
assert_eq!(type2_ber, vec![0x43, 0x05, 0x4A, 0x6F, 0x6E, 0x65, 0x73_u8]);
assert_eq!(type3_ber, vec![0xa2, 0x07, 0x43, 0x05, 0x4A, 0x6F, 0x6E, 0x65, 0x73_u8]);
assert_eq!(type4_ber, vec![0x67, 0x07, 0x43, 0x05, 0x4A, 0x6F, 0x6E, 0x65, 0x73_u8]);
assert_eq!(type5_ber, vec![0x82, 0x05, 0x4A, 0x6F, 0x6E, 0x65, 0x73_u8]);
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels