xref: /inferno-os/module/asn1.m (revision 46439007cf417cbd9ac8049bb4122c890097a0fa)
1ASN1: module {
2	PATH: con "/dis/lib/asn1.dis";
3
4	# Tag classes
5	Universal : con 0;
6	Application : con 16r40;
7	Context : con 16r80;
8	Private : con 16rC0;
9
10	# Universal tags
11	BOOLEAN : con 1;
12	INTEGER : con 2;
13	BIT_STRING : con 3;
14	OCTET_STRING : con 4;
15	NULL : con 5;
16	OBJECT_ID: con 6;
17	ObjectDescriptor : con 7;
18	EXTERNAL : con 8;
19	REAL : con 9;
20	ENUMERATED : con 10;
21	EMBEDDED_PDV : con 11;
22	SEQUENCE : con 16;		# also SEQUENCE OF
23	SET : con 17;			# also SET  OF
24	NumericString : con 18;
25	PrintableString : con 19;
26	TeletexString : con 20;
27	VideotexString : con 21;
28	IA5String : con 22;
29	UTCTime : con 23;
30	GeneralizedTime : con 24;
31	GraphicString : con 25;
32	VisibleString : con 26;
33	GeneralString : con 27;
34	UniversalString : con 28;
35	BMPString : con 30;
36
37	Elem: adt {
38		tag: Tag;
39		val: ref Value;
40
41		is_seq: fn(e: self ref Elem) : (int, list of ref Elem);
42		is_set: fn(e: self ref Elem) : (int, list of ref Elem);
43		is_int: fn(e: self ref Elem) : (int, int);
44		is_bigint: fn(e: self ref Elem) : (int, array of byte);
45		is_bitstring: fn(e: self ref Elem) : (int, int, array of byte);
46		is_octetstring: fn(e: self ref Elem) : (int, array of byte);
47		is_oid: fn(e: self ref Elem) : (int, ref Oid);
48		is_string: fn(e: self ref Elem) : (int, string);
49		is_time: fn(e: self ref Elem) : (int, string);
50		tostring: fn(e: self ref Elem) : string;
51	};
52
53	Tag: adt {
54		class: int;
55		num: int;
56		constr: int;	# ignored by encode()
57
58		tostring: fn(t: self Tag) : string;
59	};
60
61	Value: adt {
62		pick {
63			Bool or Int =>
64				v: int;
65			Octets or BigInt or Real or Other =>
66				# BigInt: integer too big for limbo int
67				# Real: we don't care to decode these
68				#    since they are hardly ever used
69				bytes: array of byte;
70			BitString =>
71				# pack into bytes, with perhaps some
72				# unused bits in last byte
73				unusedbits: int;
74				bits: array of byte;
75			Null or EOC =>
76				dummy: int;
77			ObjId =>
78				id: ref Oid;
79			String =>
80				s: string;
81			Seq or Set =>
82				l: list of ref Elem;
83		}
84
85		tostring : fn(v: self ref Value) : string;
86	};
87
88	Oid: adt {
89		nums: array of int;
90
91		tostring: fn(o: self ref Oid) : string;
92	};
93
94	init: fn();
95	decode: fn(a: array of byte) : (string, ref Elem);
96	decode_seq: fn(a: array of byte) : (string, list of ref Elem);
97	decode_value: fn(a: array of byte, kind, constr: int) : (string, ref Value);
98	encode: fn(e: ref Elem) : (string, array of byte);
99	oid_lookup: fn(o: ref Oid, tab: array of Oid) : int;
100	print_elem: fn(e: ref Elem);
101};
102