1asn(n)                         ASN.1 processing                         asn(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       asn - ASN.1 BER encoder/decoder
9

SYNOPSIS

11       package require Tcl  8.4
12
13       package require asn  ?0.7?
14
15       ::asn::asnSequence evalue...
16
17       ::asn::asnSequenceFromList elist
18
19       ::asn::asnSet evalue...
20
21       ::asn::asnSet elist
22
23       ::asn::asnApplicationConstr appNumber evalue...
24
25       ::asn::asnApplication appNumber data
26
27       ::asn::asnChoice appNumber evalue...
28
29       ::asn::asnChoiceConstr appNumber evalue...
30
31       ::asn::asnInteger number
32
33       ::asn::asnEnumeration number
34
35       ::asn::asnBoolean bool
36
37       ::asn::asnOctetString string
38
39       ::asn::asnNumericString string
40
41       ::asn::asnPrintableString string
42
43       ::asn::asnIA5String string
44
45       ::asn::asnBMPString string
46
47       ::asn::asnUTF8String string
48
49       ::asn::asnString string
50
51       ::asn::defaultStringType ?type?
52
53       ::asn::asnPeekByte data_var byte_var
54
55       ::asn::asnRetag data_var newTag
56
57       ::asn::asnGetLength data_var length_var
58
59       ::asn::asnGetResponse chan data_var
60
61       ::asn::asnGetInteger data_var int_var
62
63       ::asn::asnGetEnumeration data_var enum_var
64
65       ::asn::asnGetOctetString data_var string_var
66
67       ::asn::asnGetString data_var string_var ?type_var?
68
69       ::asn::asnGetNumericString data_var string_var
70
71       ::asn::asnGetPrintableString data_var string_var
72
73       ::asn::asnGetIA5String data_var string_var
74
75       ::asn::asnGetBMPString data_var string_var
76
77       ::asn::asnGetUTF8String data_var string_var
78
79       ::asn::asnGetUTCTime data_var utc_var
80
81       ::asn::asnGetBitString data_var bits_var
82
83       ::asn::asnGetObjectIdentifier data_var oid_var
84
85       ::asn::asnGetBoolean data_var bool_var
86
87       ::asn::asnGetNull data_var
88
89       ::asn::asnGetSequence data_var sequence_var
90
91       ::asn::asnGetSet data_var set_var
92
93       ::asn::asnGetApplication data_var appNumber_var ?content_var?
94
95       ::asn::asnGetContext data_var contextNumber_var ?content_var?
96
97_________________________________________________________________
98

DESCRIPTION

100       The  asn  package  provides  partial  de-  and encoder commands for BER
101       encoded ASN.1 data.
102
103       ASN.1 is a standard Abstract Syntax Notation, and  BER  are  its  Basic
104       Encoding Rules.
105
106       See  http://asn1.elibel.tm.fr/en/standards/index.htm  for more informa‐
107       tion about the standard.
108
109       Also see http://luca.ntop.org/Teaching/Appunti/asn1.html for A Layman's
110       Guide to a Subset of ASN.1, BER, and DER, an RSA Laboratories Technical
111       Note by Burton S. Kaliski Jr. (Revised November 1, 1993). A  text  ver‐
112       sion  of  this note is part of the module sources and should be read by
113       any implementor.
114

PUBLIC API

116   ENCODER
117       ::asn::asnSequence evalue...
118              Takes zero or more  encoded  values,  packs  them  into  an  ASN
119              sequence and returns its encoded binary form.
120
121       ::asn::asnSequenceFromList elist
122              Takes  a list of encoded values, packs them into an ASN sequence
123              and returns its encoded binary form.
124
125       ::asn::asnSet evalue...
126              Takes zero or more encoded values, packs them into  an  ASN  set
127              and returns its encoded binary form.
128
129       ::asn::asnSet elist
130              Takes  a  list of encoded values, packs them into an ASN set and
131              returns its encoded binary form.
132
133       ::asn::asnApplicationConstr appNumber evalue...
134              Takes zero or more encoded values, packs them into an ASN appli‐
135              cation construct and returns its encoded binary form.
136
137       ::asn::asnApplication appNumber data
138              Takes a single encoded value data, packs it into an ASN applica‐
139              tion construct and returns its encoded binary form.
140
141       ::asn::asnChoice appNumber evalue...
142              Takes zero or more encoded values, packs them into an ASN choice
143              construct and returns its encoded binary form.
144
145       ::asn::asnChoiceConstr appNumber evalue...
146              Takes zero or more encoded values, packs them into an ASN choice
147              construct and returns its encoded binary form.
148
149       ::asn::asnInteger number
150              Returns the encoded form of the specified integer number.
151
152       ::asn::asnEnumeration number
153              Returns the encoded form of the specified enumeration id number.
154
155       ::asn::asnBoolean bool
156              Returns the encoded form of the specified boolean value bool.
157
158       ::asn::asnOctetString string
159              Returns the encoded form of the specified string.
160
161       ::asn::asnNumericString string
162              Returns the string encoded as  ASN.1  NumericString.  Raises  an
163              error  if the string contains characters other than decimal num‐
164              bers and space.
165
166       ::asn::asnPrintableString string
167              Returns the string encoding as ASN.1 PrintableString. Raises  an
168              error if the string contains characters which are not allowed by
169              the Printable String datatype. The allowed characters  are  A-Z,
170              a-z,  0-9,  space,  apostrophe, colon, parentheses, plus, minus,
171              comma, period, forward slash,  question  mark,  and  the  equals
172              sign.
173
174       ::asn::asnIA5String string
175              Returns  the  string encoded as ASN.1 IA5String. Raises an error
176              if the string contains any characters outside  of  the  US-ASCII
177              range.
178
179       ::asn::asnBMPString string
180              Returns  the  string  encoded  as ASN.1 Basic Multilingual Plane
181              string (Which is essentialy big-endian UCS2).
182
183       ::asn::asnUTF8String string
184              Returns the string encoded as UTF8 String. Note that some legacy
185              applications such as Windows CryptoAPI do not like UTF8 strings.
186              Use BMPStrings if you are not sure.
187
188       ::asn::asnString string
189              Returns an encoded form of string, choosing the most  restricted
190              ASN.1  string  type  possible.  If the string contains non-ASCII
191              characters, then there is more than one string type which can be
192              used. See ::asn::defaultStringType.
193
194       ::asn::defaultStringType ?type?
195              Selects  the  string  type  to use for the encoding of non-ASCII
196              strings. Returns current default when called  without  argument.
197              If  the  argument  type is supplied, it should be either UTF8 or
198              BMP to choose UTF8String or BMPString respectively.
199
200   DECODER
201       General notes:
202
203       [1]    Nearly decoder commands take two arguments. These arguments  are
204              variable  names,  except  for  ::asn::asnGetResponse.  The first
205              variable contains the encoded ASN value to decode at the  begin‐
206              ning,  and  more,  and the second variable is where the value is
207              stored to. The remainder of the input after the decoded value is
208              stored back into the datavariable.
209
210       [2]    After  extraction  the  data  variable is always modified first,
211              before by writing the extracted  value  to  its  variable.  This
212              means that if both arguments refer to the same variable, it will
213              always contain the extracted value after the call, and  not  the
214              remainder of the input.
215
216       ::asn::asnPeekByte data_var byte_var
217              Retrieve  the first byte of the data, without modifing data_var.
218              This can be used to check for implicit tags.
219
220       ::asn::asnRetag data_var newTag
221              Replace the tag in front of the data with newTag. Use to  handle
222              implicitely tagged data before further decoding.
223
224       ::asn::asnGetLength data_var length_var
225              Decode  the  length information for a block of BER data. The tag
226              has already to be removed from the data.
227
228       ::asn::asnGetResponse chan data_var
229              Reads an encoded ASN sequence from the channel chan  and  stores
230              it into the variable named by data_var.
231
232       ::asn::asnGetInteger data_var int_var
233              Assumes  that  an  encoded  integer value is at the front of the
234              data stored in the variable named data_var, extracts and  stores
235              it  into the variable named by int_var. Additionally removes all
236              bytes associated with the value from the data for  further  pro‐
237              cessing by the following decoder commands.
238
239       ::asn::asnGetEnumeration data_var enum_var
240              Assumes  that  an  enumeration  id  is  at the front of the data
241              stored in the variable named data_var, and stores  it  into  the
242              variable named by enum_var. Additionally removes all bytes asso‐
243              ciated with the value from the data for  further  processing  by
244              the following decoder commands.
245
246       ::asn::asnGetOctetString data_var string_var
247              Assumes  that a string is at the front of the data stored in the
248              variable named data_var, and stores it into the  variable  named
249              by  string_var.  Additionally  removes all bytes associated with
250              the value from the data for further processing by the  following
251              decoder commands.
252
253       ::asn::asnGetString data_var string_var ?type_var?
254              Decodes  a  user-readable string. This is a convenience function
255              which is able to automatically distinguish all  supported  ASN.1
256              string  types  and  convert  the input value appropriately.  See
257              ::asn::asnGetPrintableString, ::asnGetIA5String, etc.  below for
258              the type-specific conversion commands.
259
260              If  the  optional  third argument type_var is supplied, then the
261              type of the incoming string is stored in the variable  named  by
262              it.
263
264              The  function throws the error "Invalid command name asnGetSome‐
265              UnsupportedString" if the unsupported string type Unsupported is
266              encountered.   You   can   create   the   appropriate   function
267              "asn::asnGetSomeUnsupportedString" in your application  if  nec‐
268              cessary.
269
270       ::asn::asnGetNumericString data_var string_var
271              Assumes  that a numeric string value is at the front of the data
272              stored in the variable named data_var, and stores  it  into  the
273              variable  named  by  string_var.  Additionally removes all bytes
274              associated with the value from the data for  further  processing
275              by the following decoder commands.
276
277       ::asn::asnGetPrintableString data_var string_var
278              Assumes  that  a  printable  string value is at the front of the
279              data stored in the variable named data_var, and stores  it  into
280              the variable named by string_var. Additionally removes all bytes
281              associated with the value from the data for  further  processing
282              by the following decoder commands.
283
284       ::asn::asnGetIA5String data_var string_var
285              Assumes  that  a IA5 (ASCII) string value is at the front of the
286              data stored in the variable named data_var, and stores  it  into
287              the variable named by string_var. Additionally removes all bytes
288              associated with the value from the data for  further  processing
289              by the following decoder commands.
290
291       ::asn::asnGetBMPString data_var string_var
292              Assumes  that  a  BMP  (two-byte unicode) string value is at the
293              front of the data stored in the  variable  named  data_var,  and
294              stores  it  into the variable named by string_var, converting it
295              into a proper Tcl string. Additionally removes all bytes associ‐
296              ated  with the value from the data for further processing by the
297              following decoder commands.
298
299       ::asn::asnGetUTF8String data_var string_var
300              Assumes that a UTF8 string value is at the  front  of  the  data
301              stored  in  the  variable named data_var, and stores it into the
302              variable named by string_var, converting it into  a  proper  Tcl
303              string.   Additionally  removes  all  bytes  associated with the
304              value from the data for  further  processing  by  the  following
305              decoder commands.
306
307       ::asn::asnGetUTCTime data_var utc_var
308              Assumes that a UTC time value is at the front of the data stored
309              in the variable named data_var, and stores it into the  variable
310              named  by  utc_var.  The  UTC  time value is stored as a string,
311              which has to be decoded with  the  usual  clock  scan  commands.
312              Additionally  removes  all  bytes associated with the value from
313              the data for further processing by the  following  decoder  com‐
314              mands.
315
316       ::asn::asnGetBitString data_var bits_var
317              Assumes  that  a  bit  string  value is at the front of the data
318              stored in the variable named data_var, and stores  it  into  the
319              variable  named by bits_var as a string containing only 0 and 1.
320              Additionally removes all bytes associated with  the  value  from
321              the  data  for  further processing by the following decoder com‐
322              mands.
323
324       ::asn::asnGetObjectIdentifier data_var oid_var
325              Assumes that a object identifier (OID) value is at the front  of
326              the  data  stored  in the variable named data_var, and stores it
327              into the variable named by oid_var as a list of integers.  Addi‐
328              tionally  removes  all  bytes associated with the value from the
329              data for further processing by the following decoder commands.
330
331       ::asn::asnGetBoolean data_var bool_var
332              Assumes that a boolean value is at the front of the data  stored
333              in  the variable named data_var, and stores it into the variable
334              named by bool_var. Additionally  removes  all  bytes  associated
335              with  the value from the data for further processing by the fol‐
336              lowing decoder commands.
337
338       ::asn::asnGetNull data_var
339              Assumes that a NULL value is at the front of the data stored  in
340              the variable named data_var and removes the bytes used to encode
341              it from the data.
342
343       ::asn::asnGetSequence data_var sequence_var
344              Assumes that an ASN sequence is at the front of the data  stored
345              in  the variable named data_var, and stores it into the variable
346              named by sequence_var. Additionally removes all bytes associated
347              with  the value from the data for further processing by the fol‐
348              lowing decoder commands.
349
350              The data in sequence_var is encoded binary and has to be further
351              decoded  according  to the definition of the sequence, using the
352              decoder commands here.
353
354       ::asn::asnGetSet data_var set_var
355              Assumes that an ASN set is at the front of the  data  stored  in
356              the  variable  named  data_var,  and stores it into the variable
357              named by set_var. Additionally removes all bytes associated with
358              the  value from the data for further processing by the following
359              decoder commands.
360
361              The data in set_var is encoded binary  and  has  to  be  further
362              decoded  according  to  the  definition  of  the  set, using the
363              decoder commands here.
364
365       ::asn::asnGetApplication data_var appNumber_var ?content_var?
366              Assumes that an ASN application construct is at the front of the
367              data  stored  in  the variable named data_var, and stores its id
368              into the variable named by appNumber_var.  Additionally  removes
369              all  bytes  associated  with the value from the data for further
370              processing by the following decoder commands.  If a  content_var
371              is  specified,  then the command places all data associated with
372              it into the named variable, in the binary form which can be pro‐
373              cessed using the decoder commands of this package.
374
375              Otherwise  it  is the responsibility of the caller to decode the
376              remainder of the application construct based on the id retrieved
377              by this command, using the decoder commands of this package.
378
379       ::asn::asnGetContext data_var contextNumber_var ?content_var?
380              Assumes that an ASN context tag construct is at the front of the
381              data stored in the variable named data_var, and  stores  its  id
382              into  the  variable  named  by  contextNumber_var.  Additionally
383              removes all bytes associated with the value from  the  data  for
384              further processing by the following decoder commands.  If a con‐
385              tent_var is specified, then the command places all data  associ‐
386              ated  with  it into the named variable, in the binary form which
387              can be processed using the decoder commands of this package.
388
389              Otherwise it is the responsibility of the caller to  decode  the
390              remainder  of  the  construct  based on the id retrieved by this
391              command, using the decoder commands of this package.
392

EXAMPLES

394       Examples for the usage of this package can be found in the  implementa‐
395       tion of package ldap.
396

KEYWORDS

398       asn, ber, cer, der, internet, protocol, x.208, x.209
399
401       Copyright (c) 2004 Andreas Kupries <andreas_kupries@users.sourceforge.net>
402       Copyright (c) 2004 Jochen Loewer <loewerj@web.de>
403       Copyright (c) 2004-2006 Michael Schlenker <mic42@users.sourceforge.net>
404
405
406
407
408asn                                   0.7                               asn(n)
Impressum