1 x690sample DEFINITIONS ::= BEGIN
3 -- This is taken from Appendix A of X.690. The same module is used by all
4 -- X.690 series specifications of ASN.1 Encoding Rules.
6 -- This doesn't exercise every feature, like OPTIONAL, not really DEFAULT, not
7 -- EXPLICIT tagging, extensibility markers, etc., but it exercises some hard
8 -- ones like SET and IMPLICIT tagging.
10 -- Because we don't yet have an option to add a namespace prefix to generated
11 -- symbols, to avoid conflicts with rfc2459's Name we're prefixing the type
12 -- names here manually.
14 -- WARNING: The encoding rules used for the sample encoding given in Appendix A
15 -- of X.690, and used in lib/asn1/check-gen.c, is not specified in
16 -- X.690! It seems very likely that it is neither CER nor DER but BER
17 -- because the tags in the X690SamplePersonnelRecord (a SET { ... })
18 -- are not in canonical order:
20 -- APPL CONS tag 0 = 133 bytes [0]
21 -- APPL CONS tag 1 = 16 bytes [1]
22 -- UNIV PRIM VisibleString = "John"
23 -- UNIV PRIM VisibleString = "P"
24 -- UNIV PRIM VisibleString = "Smith"
25 -- -> CONTEXT CONS tag 0 = 10 bytes [0]
26 -- UNIV PRIM VisibleString = "Director"
27 -- -> APPL PRIM tag 2 = 1 bytes [2] IMPLICIT content
30 -- The canonical ordering of members in SET { ... } types is by tag,
31 -- with UNIVERSAL tags before APPLICATION tags, those before CONTEXT,
32 -- and those before PRIVATE, and within each class from lowest to
33 -- highest numeric tag value. See X.680, section 8.6, which is
34 -- referenced from X.690, section 10.3.
36 -- Here we can see that the `title` member should come _after_ the
37 -- `number` member, but it does not.
39 -- Our test relies on our compiler producing the same test data when
40 -- encoding the structure that the given test data decodes to. That
41 -- works here only because our compiler does NOT sort SET { ... }
42 -- members as it should (since we always produce DER).
44 -- Sorting SET members in the compiler is hard currently because we
45 -- don't parse imported modules, so we don't know the tags of imported
46 -- types, so we can only sort at run-time, which we don't do.
48 -- There is an obvious workaround, however: sort the SET { ... }
49 -- definition manually!
51 X690SamplePersonnelRecord ::= [APPLICATION 0] IMPLICIT SET {
53 title [0] VisibleString,
54 number X690SampleEmployeeNumber,
55 dateOfHire [1] X690SampleDate,
56 nameOfSpouse [2] X690SampleName,
57 -- Heimdal's ASN.1 compiler doesn't handle DEFAULT values for types for
58 -- which it doesn't support literal values.
59 children [3] IMPLICIT SEQUENCE OF X690SampleChildInformation -- DEFAULT {}
62 X690SampleChildInformation ::= SET {
64 dateOfBirth [0] X690SampleDate
67 X690SampleName ::= [APPLICATION 1] IMPLICIT SEQUENCE {
68 givenName VisibleString,
69 initial VisibleString,
70 familyName VisibleString
73 -- Range added for test convenience.
74 X690SampleEmployeeNumber ::= [APPLICATION 2] IMPLICIT INTEGER (0..4294967295)
76 X690SampleDate::= [APPLICATION 3] IMPLICIT VisibleString --YYYYMMDD
78 -- The following is value syntax for the above, but Heimdal's ASN.1 compiler
79 -- does not yet support value syntax for anything other than OIDs, booleans,
80 -- integers, and UTF-8 strings:
82 -- { name { givenName "John", initial "P", familyName "Smith" },
85 -- dateOfHire "19710917",
86 -- nameOfSpouse {givenName "Mary", initial "T", familyName "Smith" },
88 -- {name {givenName "Ralph", initial "T", familyName "Smith" },
89 -- dateOfBirth "19571111"},
90 -- {name {givenName "Susan", initial "B", familyName "Jones" },
91 -- I dateOfBirth "19590717"}
95 -- The encoding of this value is supposed to be (all hex) (adapted from X.690
98 -- 60818561101A044A6F686E1A01501A05536D697468A00A1A084469726563746F
99 -- 72420133A10A43083139373130393137A21261101A044D6172791A01541A0553
100 -- 6D697468A342311F61111A0552616C70681A01541A05536D697468A00A430831
101 -- 39353731313131311F61111A05537573616E1A01421A05536D697468A00A4308
104 -- And a rough visualization of this is (adapted from X.690 Appendix A):
112 -- 1A 04 4A6F686E # 6
116 -- 1A 05 536D697468 # 7
118 -- T L T L "Director"
119 -- A0 0A 1A 08 4469726563746F72 #12
123 -- A1 0A 43 08 3139373130393137 #12
128 -- 1A 04 4D617279 # 6
130 -- 1A 05 536D697468 # 7
135 -- 61 11 1A 05 52616C7068 # 9
137 -- 1A 05 536D697468 # 7
139 -- A0 0A 43 08 3139353731313131 #12
141 -- 61 11 1A 05 537573616E # 9 bytes
142 -- 1A 01 42 # 3 bytes
143 -- 1A 05 536D697468 # 7 bytes
144 -- A0 0A 43 08 3139353930373137 #12 bytes
146 -- Our asn1_print program dumps this as follows, which looks correct:
148 -- APPL CONS tag 0 = 133 bytes [0]
149 -- APPL CONS tag 1 = 16 bytes [1]
150 -- UNIV PRIM VisibleString = "John"
151 -- UNIV PRIM VisibleString = "P"
152 -- UNIV PRIM VisibleString = "Smith"
153 -- CONTEXT CONS tag 0 = 10 bytes [0]
154 -- UNIV PRIM VisibleString = "Director"
155 -- APPL PRIM tag 2 = 1 bytes [2] IMPLICIT content
156 -- CONTEXT CONS tag 1 = 10 bytes [1]
157 -- APPL PRIM tag 3 = 8 bytes [3] IMPLICIT content
158 -- CONTEXT CONS tag 2 = 18 bytes [2]
159 -- APPL CONS tag 1 = 16 bytes [1]
160 -- UNIV PRIM VisibleString = "Mary"
161 -- UNIV PRIM VisibleString = "T"
162 -- UNIV PRIM VisibleString = "Smith"
163 -- CONTEXT CONS tag 3 = 66 bytes [3]
164 -- UNIV CONS Set = 31 bytes {
165 -- APPL CONS tag 1 = 17 bytes [1]
166 -- UNIV PRIM VisibleString = "Ralph"
167 -- UNIV PRIM VisibleString = "T"
168 -- UNIV PRIM VisibleString = "Smith"
169 -- CONTEXT CONS tag 0 = 10 bytes [0]
170 -- APPL PRIM tag 3 = 8 bytes [3] IMPLICIT content
172 -- UNIV CONS Set = 31 bytes {
173 -- APPL CONS tag 1 = 17 bytes [1]
174 -- UNIV PRIM VisibleString = "Susan"
175 -- UNIV PRIM VisibleString = "B"
176 -- UNIV PRIM VisibleString = "Smith"
177 -- CONTEXT CONS tag 0 = 10 bytes [0]
178 -- APPL PRIM tag 3 = 8 bytes [3] IMPLICIT content