Debian Codegraph @

addons/ooh323c/src/ooasn1.h

raw symbols SCIP
1 /*
2 * Copyright (C) 1997-2005 by Objective Systems, Inc.
3 *
4 * This software is furnished under an open source license and may be
5 * used and copied only in accordance with the terms of this license.
6 * The text of the license may generally be found in the root
7 * directory of this installation in the COPYING file. It
8 * can also be viewed online at the following URL:
9 *
10 * http://www.obj-sys.com/open/license.html
11 *
12 * Any redistributions of this file including modified versions must
13 * maintain this copyright notice.
14 *
15 *****************************************************************************/
16 /**
17 * @file ooasn1.h
18 * Common ASN.1 runtime constants, data structure definitions, and run-time
19 * functions to support ASN.1 PER encoding/decoding as defined in the
20 * ITU-T standards.
21 */
22 #ifndef _OOASN1_H_
23 #define _OOASN1_H_
24
25 #include "asterisk.h"
26 #include "asterisk/lock.h"
27
28 #include <limits.h>
29 #include <stdio.h>
30 #include <string.h>
31 #include <stddef.h>
32 #include "dlist.h"
33 #include "ootrace.h"
34 /**
35 * @defgroup cruntime C Runtime Common Functions
36 * @{
37 */
38
39 /* Error Code Constants */
40
41 #define ASN_OK 0 /* normal completion status */
42 #define ASN_OK_FRAG 2 /* message fragment detected */
43 #define ASN_E_BUFOVFLW -1 /* encode buffer overflow */
44 #define ASN_E_ENDOFBUF -2 /* unexpected end of buffer on decode */
45 #define ASN_E_IDNOTFOU -3 /* identifer not found */
46 #define ASN_E_INVOBJID -4 /* invalid object identifier */
47 #define ASN_E_INVLEN -5 /* invalid field length */
48 #define ASN_E_INVENUM -6 /* enumerated value not in defined set */
49 #define ASN_E_SETDUPL -7 /* duplicate element in set */
50 #define ASN_E_SETMISRQ -8 /* missing required element in set */
51 #define ASN_E_NOTINSET -9 /* element not part of set */
52 #define ASN_E_SEQOVFLW -10 /* sequence of field overflow */
53 #define ASN_E_INVOPT -11 /* invalid option encountered in choice */
54 #define ASN_E_NOMEM -12 /* no dynamic memory available */
55 #define ASN_E_INVHEXS -14 /* invalid hex string */
56 #define ASN_E_INVBINS -15 /* invalid binary string */
57 #define ASN_E_INVREAL -16 /* invalid real value */
58 #define ASN_E_STROVFLW -17 /* octet or bit string field overflow */
59 #define ASN_E_BADVALUE -18 /* invalid value specification */
60 #define ASN_E_UNDEFVAL -19 /* no def found for ref'd defined value */
61 #define ASN_E_UNDEFTYP -20 /* no def found for ref'd defined type */
62 #define ASN_E_BADTAG -21 /* invalid tag value */
63 #define ASN_E_TOODEEP -22 /* nesting level is too deep */
64 #define ASN_E_CONSVIO -23 /* value constraint violation */
65 #define ASN_E_RANGERR -24 /* invalid range (lower > upper) */
66 #define ASN_E_ENDOFFILE -25 /* end of file on file decode */
67 #define ASN_E_INVUTF8 -26 /* invalid UTF-8 encoding */
68 #define ASN_E_CONCMODF -27 /* Concurrent list modification */
69 #define ASN_E_ILLSTATE -28 /* Illegal state error */
70 #define ASN_E_OUTOFBND -29 /* out of bounds (of array, etc) */
71 #define ASN_E_INVPARAM -30 /* invalid parameter */
72 #define ASN_E_INVFORMAT -31 /* invalid time string format */
73 #define ASN_E_NOTINIT -32 /* not initialized */
74 #define ASN_E_TOOBIG -33 /* value is too big for given data type */
75 #define ASN_E_INVCHAR -34 /* invalid character (not in char set) */
76 #define ASN_E_XMLSTATE -35 /* XML state error */
77 #define ASN_E_XMLPARSE -36 /* XML parse error */
78 #define ASN_E_SEQORDER -37 /* SEQUENCE elements not in order */
79 #define ASN_E_INVINDEX -38 /* invalid index for TC id */
80 #define ASN_E_INVTCVAL -39 /* invalid value for TC field */
81 #define ASN_E_FILNOTFOU -40 /* file not found */
82 #define ASN_E_FILEREAD -41 /* error occurred reading file */
83 #define ASN_E_FILEWRITE -42 /* error occurred writing file */
84 #define ASN_E_INVBASE64 -43 /* invalid base64 encoding */
85 #define ASN_E_INVSOCKET -44 /* invalid socket operation */
86 #define ASN_E_XMLLIBNFOU -45 /* XML library is not found */
87 #define ASN_E_XMLLIBINV -46 /* XML library is invalid */
88 #define ASN_E_NOTSUPP -99 /* non-supported ASN construct */
89 #define ASN_K_INDEFLEN -9999 /* indefinite length message indicator */
90
91 /* universal built-in type ID code value constants */
92
93 #define ASN_ID_EOC 0 /* end of contents */
94 #define ASN_ID_BOOL 1 /* boolean */
95 #define ASN_ID_INT 2 /* integer */
96 #define ASN_ID_BITSTR 3 /* bit string */
97 #define ASN_ID_OCTSTR 4 /* byte (octet) string */
98 #define ASN_ID_NULL 5 /* null */
99 #define ASN_ID_OBJID 6 /* object ID */
100 #define ASN_ID_OBJDSC 7 /* object descriptor */
101 #define ASN_ID_EXTERN 8 /* external type */
102 #define ASN_ID_REAL 9 /* real */
103 #define ASN_ID_ENUM 10 /* enumerated value */
104 #define ASN_ID_EPDV 11 /* EmbeddedPDV type */
105 #define ASN_ID_RELOID 13 /* relative object ID */
106 #define ASN_ID_SEQ 16 /* sequence, sequence of */
107 #define ASN_ID_SET 17 /* set, set of */
108
109 #define ASN_SEQ_TAG 0x30 /* SEQUENCE universal tag byte */
110 #define ASN_SET_TAG 0x31 /* SET universal tag byte */
111
112 /* Restricted character string type ID's */
113
114 #define ASN_ID_NumericString 18
115 #define ASN_ID_PrintableString 19
116 #define ASN_ID_TeletexString 20
117 #define ASN_ID_T61String ASN_ID_TeletexString
118 #define ASN_ID_VideotexString 21
119 #define ASN_ID_IA5String 22
120 #define ASN_ID_UTCTime 23
121 #define ASN_ID_GeneralTime 24
122 #define ASN_ID_GraphicString 25
123 #define ASN_ID_VisibleString 26
124 #define ASN_ID_GeneralString 27
125 #define ASN_ID_UniversalString 28
126 #define ASN_ID_BMPString 30
127
128 /* flag mask values */
129
130 #define XM_SEEK 0x01 /* seek match until found or end-of-buf */
131 #define XM_ADVANCE 0x02 /* advance pointer to contents on match */
132 #define XM_DYNAMIC 0x04 /* alloc dyn mem for decoded variable */
133 #define XM_SKIP 0x08 /* skip to next field after parsing tag */
134
135 /* Sizing Constants */
136
137 #define ASN_K_MAXDEPTH 32 /* maximum nesting depth for messages */
138 #define ASN_K_MAXSUBIDS 128 /* maximum sub-id's in an object ID */
139 #define ASN_K_MAXENUM 100 /* maximum enum values in an enum type */
140 #define ASN_K_MAXERRP 5 /* maximum error parameters */
141 #define ASN_K_MAXERRSTK 8 /* maximum levels on error ctxt stack */
142 #define ASN_K_ENCBUFSIZ 2*1024 /* dynamic encode buffer extent size */
143 #define ASN_K_MEMBUFSEG 1024 /* memory buffer extent size */
144
145 /* Canonical character set definitions */
146
147 #define NUM_ABITS 4
148 #define NUM_UBITS 4
149 #define NUM_CANSET \
150 " 0123456789"
151
152 #define PRN_ABITS 8
153 #define PRN_UBITS 7
154 #define PRN_CANSET \
155 " '()+,-./0123456789:=?ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
156
157 #define VIS_ABITS 8
158 #define VIS_UBITS 7
159 #define VIS_CANSET \
160 " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]"\
161 "^_`abcdefghijklmnopqrstuvwxyz{|}~"
162
163 #define T61_ABITS 8
164 #define T61_UBITS 7
165 #define T61_CANSET \
166 " !\"%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]"\
167 "_abcdefghijklmnopqrstuvwxyz"
168
169 #define IA5_ABITS 8
170 #define IA5_UBITS 7
171 #define IA5_CANSET \
172 "\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017"\
173 "\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037"\
174 " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]"\
175 "^_`abcdefghijklmnopqrstuvwxyz{|}~"
176
177 #define IA5_RANGE1_LOWER 0
178 #define IA5_RANGE2_LOWER 0x5f
179
180 #define GEN_ABITS 8
181 #define GEN_UBITS 7
182 #define GEN_CANSET \
183 "\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017"\
184 "\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037"\
185 " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"\
186 "`abcdefghijklmnopqrstuvwxyz{|}~\177\200\201\202\203\204\205\206\207"\
187 "\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237"\
188 "\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257"\
189 "\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277"\
190 "\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317"\
191 "\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337"\
192 "\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357"\
193 "\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377"
194
195 #define BMP_ABITS 16
196 #define BMP_UBITS 16
197 #define BMP_FIRST 0
198 #define BMP_LAST 0xffff
199
200 #define UCS_ABITS 32
201 #define UCS_UBITS 32
202 #define UCS_FIRST 0
203 #define UCS_LAST 0xfffffffful
204
205 /* ASN.1 Primitive Type Definitions */
206
207 typedef char ASN1CHAR;
208 typedef unsigned char ASN1OCTET;
209 typedef ASN1OCTET ASN1BOOL;
210 typedef signed char ASN1INT8;
211 typedef unsigned char ASN1UINT8;
212 typedef int ASN1INT;
213 typedef unsigned int ASN1UINT;
214 typedef ASN1INT ASN1ENUM;
215 typedef double ASN1REAL;
216
217 typedef short ASN1SINT;
218 typedef unsigned short ASN1USINT;
219 typedef ASN1UINT ASN1TAG;
220 #define ASN1TAG_LSHIFT 24
221 typedef ASN1USINT ASN116BITCHAR;
222 typedef ASN1UINT ASN132BITCHAR;
223 typedef void* ASN1ANY;
224
225 #define ASN1UINT_MAX 4294967295U
226 #define ASN1INT_MAX ((ASN1INT)2147483647L)
227 #define ASN1INT_MIN ((ASN1INT)(-ASN1INT_MAX-1))
228
229 #define ASN1UINTCNT(val) val##u
230
231
232 #ifndef ASN1INT64
233
234 #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__) || \
235 defined(_WIN32)
236 #define ASN1INT64 __int64
237
238 #elif defined(__IBMC__) || defined(__GNUC__) || defined(__SUNPRO_C) || \
239 defined(__SUNPRO_CC) || defined(__CC_ARM) || \
240 defined(__HPUX_CC__) || defined(__HP_aCC)
241 #define ASN1INT64 long long
242
243 #else /* !MSC_VER && !__IBMC__ etc */
244 #define ASN1INT64 long
245
246 #endif
247 #endif /* ASN1INT64 */
248
249 #ifndef FALSE
250 #define FALSE 0
251 #define TRUE 1
252 #endif
253
254 typedef struct { /* object identifier */
255 ASN1UINT numids;
256 ASN1UINT subid[ASN_K_MAXSUBIDS];
257 } ASN1OBJID;
258
259 typedef struct { /* generic octet string structure */
260 ASN1UINT numocts;
261 ASN1OCTET data[1];
262 } ASN1OctStr;
263
264 typedef struct { /* generic octet string structure (dynamic) */
265 ASN1UINT numocts;
266 const ASN1OCTET* data;
267 } ASN1DynOctStr;
268
269 typedef struct { /* generic bit string structure (dynamic) */
270 ASN1UINT numbits;
271 const ASN1OCTET* data;
272 } ASN1DynBitStr;
273
274 typedef struct { /* generic sequence of structure */
275 ASN1UINT n;
276 void* elem;
277 } ASN1SeqOf;
278
279 typedef struct { /* sequence of OCTET STRING */
280 ASN1UINT n;
281 ASN1DynOctStr* elem;
282 } ASN1SeqOfOctStr;
283
284 typedef struct { /* generic open type data structure */
285 ASN1UINT numocts;
286 const ASN1OCTET* data;
287 } ASN1OpenType;
288
289 /* ASN.1 useful type definitions */
290
291 typedef struct {
292 ASN1UINT nchars;
293 ASN116BITCHAR* data;
294 } Asn116BitCharString;
295
296 typedef struct {
297 ASN1UINT nchars;
298 ASN132BITCHAR* data;
299 } Asn132BitCharString;
300
301 typedef const char* ASN1GeneralizedTime;
302 typedef const char* ASN1GeneralString;
303 typedef const char* ASN1GraphicString;
304 typedef const char* ASN1IA5String;
305 typedef const char* ASN1ISO646String;
306 typedef const char* ASN1NumericString;
307 typedef const char* ASN1ObjectDescriptor;
308 typedef const char* ASN1PrintableString;
309 typedef const char* ASN1TeletexString;
310 typedef const char* ASN1T61String;
311 typedef const char* ASN1UTCTime;
312 typedef const char* ASN1UTF8String;
313 typedef const char* ASN1VideotexString;
314 typedef const char* ASN1VisibleString;
315
316 typedef Asn116BitCharString ASN1BMPString;
317 typedef Asn132BitCharString ASN1UniversalString;
318
319 /* ASN.1 constrained string structures */
320
321 typedef struct {
322 int nchars;
323 char data[255];
324 } Asn1CharArray;
325
326 typedef struct {
327 Asn1CharArray charSet;
328 const char* canonicalSet;
329 int canonicalSetSize;
330 unsigned canonicalSetBits;
331 unsigned charSetUnalignedBits;
332 unsigned charSetAlignedBits;
333 } Asn1CharSet;
334
335 typedef struct {
336 Asn116BitCharString charSet;
337 ASN1USINT firstChar, lastChar;
338 unsigned unalignedBits;
339 unsigned alignedBits;
340 } Asn116BitCharSet;
341
342 /* ASN.1 size constraint structure */
343
344 typedef struct _Asn1SizeCnst {
345 ASN1BOOL extended;
346 ASN1UINT lower;
347 ASN1UINT upper;
348 struct _Asn1SizeCnst* next;
349 } Asn1SizeCnst;
350
351 /* ASN.1 encode/decode buffer info structure */
352
353 typedef struct {
354 ASN1OCTET* data; /* pointer to start of data buffer */
355 ASN1UINT byteIndex; /* byte index */
356 ASN1UINT size; /* current buffer size */
357 ASN1SINT bitOffset; /* current bit offset (8 - 1) */
358 ASN1BOOL dynamic; /* is buffer dynamic? */
359 } ASN1BUFFER;
360
361 /* This structure is used to save the current state of the buffer */
362
363 typedef struct {
364 ASN1UINT byteIndex; /* byte index */
365 ASN1SINT bitOffset; /* current bit offset (8 - 1) */
366 ASN1USINT flags; /* flag bits */
367 } ASN1BUFSAVE;
368
369 /* ASN.1 run-time error info structures */
370
371 typedef struct {
372 const char* module;
373 int lineno;
374 } ASN1ErrLocn;
375
376 typedef struct {
377 ASN1ErrLocn stack[ASN_K_MAXERRSTK];
378 int stkx;
379 int status;
380 int parmcnt;
381 const char* parms[ASN_K_MAXERRP];
382 } ASN1ErrInfo;
383
384 #define XM_K_MEMBLKSIZ (4*1024)
385
386 /* Flag mask constant values */
387
388 #define ASN1DYNCTXT 0x8000
389 #define ASN1INDEFLEN 0x4000
390 #define ASN1TRACE 0x2000
391 #define ASN1LASTEOC 0x1000
392 #define ASN1FASTCOPY 0x0800 /* turns on the "fast copy" mode */
393 #define ASN1CONSTAG 0x0400 /* form of last parsed tag */
394 #define ASN1CANXER 0x0200 /* canonical XER */
395 #define ASN1SAVEBUF 0x0100 /* do not free dynamic encode buffer */
396 #define ASN1OPENTYPE 0x0080 /* item is an open type field */
397
398 /* ASN.1 encode/decode context block structure */
399
400 struct EventHandler;
401
402 typedef struct OOCTXT { /* context block */
403 void* pMsgMemHeap; /* internal message memory heap */
404 void* pTypeMemHeap; /* memory heap */
405 ASN1BUFFER buffer; /* data buffer */
406 ASN1ErrInfo errInfo; /* run-time error info */
407 Asn1SizeCnst* pSizeConstraint; /* Size constraint list */
408 const char* pCharSet; /* String of permitted characters */
409 struct EventHandler* pEventHandler; /* event handler object */
410 ASN1USINT flags; /* flag bits */
411 ASN1OCTET spare[2];
412 ast_mutex_t pLock;
413 } OOCTXT;
414
415 /* macros and function prototypes */
416
417 #ifndef ASN1MAX
418 #define ASN1MAX(a,b) (((a)>(b))?(a):(b))
419 #endif
420
421 #ifndef ASN1MIN
422 #define ASN1MIN(a,b) (((a)<(b))?(a):(b))
423 #endif
424
425 /**
426 * @defgroup mem Memory Allocation Macros and Functions
427 * @ingroup cruntime
428 *
429 * Memory allocation functions and macros handle memory management for the
430 * ASN1C run-time. Special algorithms are used for allocation and deallocation
431 * of memory to improve the run-time performance. @{
432 */
433 /**
434 * Allocate a dynamic array. This macro allocates a dynamic array of records of
435 * the given type. This version of the macro will return the ASN_E_NOMEM error
436 * status if the memory request cannot be fulfilled.
437 *
438 * @param pctxt - Pointer to a context block
439 * @param pseqof - Pointer to a generated SEQUENCE OF array structure.
440 * The <i>n</i> member variable must be set to the number
441 * of records to allocate.
442 * @param type - Data type of an array record
443 */
444 #define ALLOC_ASN1ARRAY(pctxt,pseqof,type) do {\
445 if (sizeof(type)*(pseqof)->n < (pseqof)->n) return ASN_E_NOMEM; \
446 if (((pseqof)->elem = (type*) memHeapAlloc \
447 (&(pctxt)->pTypeMemHeap, sizeof(type)*(pseqof)->n)) == 0) return ASN_E_NOMEM; \
448 } while (0)
449
450 /**
451 * Allocate and zero an ASN.1 element. This macro allocates and zeros a single
452 * element of the given type.
453 *
454 * @param pctxt - Pointer to a context block
455 * @param type - Data type of record to allocate
456 */
457 #define ALLOC_ASN1ELEM(pctxt,type) \
458 (type*) memHeapAllocZ (&(pctxt)->pTypeMemHeap, sizeof(type))
459
460 /**
461 * Allocate memory. This macro allocates the given number of bytes. It is
462 * similar to the C \c malloc run-time function.
463 *
464 * @param pctxt - Pointer to a context block
465 * @param nbytes - Number of bytes of memory to allocate
466 * @return - Void pointer to allocated memory or NULL if
467 * insufficient memory was available to fulfill the
468 * request.
469 */
470 #define ASN1MALLOC(pctxt,nbytes) \
471 memHeapAlloc(&(pctxt)->pTypeMemHeap, nbytes)
472
473 /**
474 * Free memory associated with a context. This macro frees all memory held
475 * within a context. This is all memory allocated using the ASN1MALLOC (and
476 * similar macros) and the mem memory allocation functions using the given
477 * context variable.
478 *
479 * @param pctxt - Pointer to a context block
480 */
481 #define ASN1MEMFREE(pctxt) \
482 memHeapFreeAll(&(pctxt)->pTypeMemHeap)
483
484 /**
485 * Free memory pointer. This macro frees memory at the given pointer. The
486 * memory must have been allocated using the ASN1MALLOC (or similar) macros or
487 * the mem memory allocation functions. This macro is similar to the C \c
488 * free function.
489 *
490 * @param pctxt - Pointer to a context block
491 * @param pmem - Pointer to memory block to free. This must have been
492 * allocated using the ASN1MALLOC macro or the
493 * memHeapAlloc function.
494 */
495 #define ASN1MEMFREEPTR(pctxt,pmem) \
496 memHeapFreePtr(&(pctxt)->pTypeMemHeap, (void*)pmem)
497
498 /**
499 * @}
500 */
501 #define ASN1BUFCUR(cp) (cp)->buffer.data[(cp)->buffer.byteIndex]
502 #define ASN1BUFPTR(cp) &(cp)->buffer.data[(cp)->buffer.byteIndex]
503
504 #ifdef __cplusplus
505 extern "C" {
506 #endif
507
508 #ifndef EXTERN
509 #ifdef MAKE_DLL
510 #define EXTERN __declspec(dllexport)
511 #elif defined (USEASN1DLL)
512 #define EXTERN __declspec(dllimport)
513 #else
514 #define EXTERN
515 #endif /* MAKE_DLL */
516 #endif /* EXTERN */
517
518 #ifndef _NO_MALLOC
519 /*#define ASN1CRTMALLOC0(nbytes) malloc(nbytes)
520 #define ASN1CRTFREE0(ptr) free(ptr) */
521 #else
522
523 #ifdef _NO_THREADS
524 extern EXTERN OOCTXT g_ctxt;
525
526 #define ASN1CRTMALLOC0(nbytes) memAlloc(&g_ctxt,(nbytes))
527 #define ASN1CRTFREE0(ptr) memFreePtr(&g_ctxt,(ptr))
528 #else
529 #define ASN1CRTMALLOC0(nbytes) (void*)0
530 #define ASN1CRTFREE0(ptr) (void*)0
531
532 #endif /* _NO_THREADS */
533 #endif /* _NO_MALLOC */
534
535 #define ASN1CRTMALLOC memHeapAlloc
536 #define ASN1CRTFREE ASN1MEMFREEPTR
537
538 /* Function prototypes */
539
540 #define DE_INCRBITIDX(pctxt) \
541 ((--(pctxt)->buffer.bitOffset < 0) ? \
542 ((++(pctxt)->buffer.byteIndex >= (pctxt)->buffer.size) ? ASN_E_ENDOFBUF : \
543 ((pctxt)->buffer.bitOffset = 7, ASN_OK)) : ASN_OK)
544
545
546 #define DE_BIT(pctxt,pvalue) \
547 ((DE_INCRBITIDX (pctxt) != ASN_OK) ? ASN_E_ENDOFBUF : ( \
548 ((*(pvalue) = (((pctxt)->buffer.data[(pctxt)->buffer.byteIndex]) & \
549 (1 << (pctxt)->buffer.bitOffset)) != 0), ASN_OK) ))
550 /*
551 #define DE_BIT(pctxt,pvalue) \
552 ((DE_INCRBITIDX (pctxt) != ASN_OK) ? ASN_E_ENDOFBUF : ((pvalue) ? \
553 ((*(pvalue) = (((pctxt)->buffer.data[(pctxt)->buffer.byteIndex]) & \
554 (1 << (pctxt)->buffer.bitOffset)) != 0), ASN_OK) : ASN_OK ))
555 */
556
557
558 #define encodeIA5String(pctxt,value,permCharSet) \
559 encodeConstrainedStringEx (pctxt, value, permCharSet, 8, 7, 7)
560
561 #define encodeGeneralizedTime encodeIA5String
562
563 #define decodeIA5String(pctxt,pvalue,permCharSet) \
564 decodeConstrainedStringEx (pctxt, pvalue, permCharSet, 8, 7, 7)
565
566 #define decodeGeneralizedTime decodeIA5String
567
568 /* run-time error and diagnostic functions */
569
570 /* Context management functions */
571
572 /**
573 * @defgroup cmfun Context Management Functions
574 * @{
575 *
576 * Context initialization functions handle the allocation, initialization, and
577 * destruction of ASN.1 context variables (variables of type OOCTXT). These
578 * variables hold all of the working data used during the process of encoding
579 * or decoding a message. The context provides thread safe operation by
580 * isolating what would otherwise be global variables within this structure.
581 * The context variable is passed from function to function as a message is
582 * encoded or decoded and maintains state information on the encoding or
583 * decoding process.
584 */
585
586 /**
587 * This function assigns a buffer to a context block. The block should have
588 * been previously initialized by initContext.
589 *
590 * @param pctxt The pointer to the context structure variable to be
591 * initialized.
592 * @param bufaddr For encoding, the address of a memory buffer to receive
593 * and encode a message. For decoding the address of a
594 * buffer that contains the message data to be decoded.
595 * This address will be stored within the context
596 * structure. For encoding it might be zero, the dynamic
597 * buffer will be used in this case.
598 * @param bufsiz The size of the memory buffer. For encoding, it might be
599 * zero; the dynamic buffer will be used in this case.
600 * @return Completion status of operation:
601 * - 0 (ASN_OK) = success,
602 * - negative return value is error.
603 */
604 EXTERN int initContextBuffer
605 (OOCTXT* pctxt, const ASN1OCTET* bufaddr, ASN1UINT bufsiz);
606
607 /**
608 * This function initializes a context block. It makes sure that if the block
609 * was not previosly initialized, that all key working parameters are set to
610 * their correct initial state values (i.e. declared within a function as a
611 * normal working variable), it is required that they invoke this function
612 * before using it.
613 *
614 * @param pctxt The pointer to the context structure variable to be
615 * initialized.
616 * @return Completion status of operation:
617 * - 0 (ASN_OK) = success,
618 * - negative return value is error.
619 */
620 EXTERN int initContext (OOCTXT* pctxt);
621
622 /**
623 * This function frees all dynamic memory associated with a context. This
624 * includes all memory inside the block (in particular, the list of memory
625 * blocks used by the mem functions).
626 *
627 * @param pctxt A pointer to a context structure.
628 */
629 EXTERN void freeContext (OOCTXT* pctxt);
630
631 /**
632 * This function allocates a new OOCTXT block and initializes it. Although
633 * the block is allocated from the standard heap, it should not be freed using
634 * free. The freeContext function should be used because this frees items
635 * allocated within the block before freeing the block itself.
636 *
637 * @return Pointer to newly created context
638 */
639 EXTERN OOCTXT* newContext (void);
640
641 EXTERN void copyContext (OOCTXT* pdest, OOCTXT* psrc);
642 EXTERN int initSubContext (OOCTXT* pctxt, OOCTXT* psrc);
643 EXTERN void setCtxtFlag (OOCTXT* pctxt, ASN1USINT mask);
644 EXTERN void clearCtxtFlag (OOCTXT* pctxt, ASN1USINT mask);
645
646 EXTERN int setPERBuffer
647 (OOCTXT* pctxt, ASN1OCTET* bufaddr, ASN1UINT bufsiz, ASN1BOOL aligned);
648
649 EXTERN int setPERBufferUsingCtxt (OOCTXT* pTarget, OOCTXT* pSource);
650
651 #define ZEROCONTEXT(pctxt) memset(pctxt,0,sizeof(OOCTXT))
652 /**
653 * @} cmfun
654 */
655 /**
656 * @defgroup errfp Error Formatting and Print Functions
657 * @{
658 *
659 * Error formatting and print functions allow information about the
660 * encode/decode errors to be added to a context block structure and then
661 * printed out when the error is propagated to the top level.
662 */
663
664 /**
665 * This function adds an integer parameter to an error information structure.
666 * Parameter substitution is done in much the same way as it is done in C
667 * printf statements. The base error message specification that goes along with
668 * a particular status code may have variable fields built in using '%'
669 * modifiers. These would be replaced with actual parameter data.
670 *
671 * @param pErrInfo A pointer to a structure containing information on the
672 * error to be printed. Typically, the error info
673 * structure referred to is the one inside the OOCTXT
674 * structure. (i.e. &pctxt->errInfo).
675 * @param errParm The typed error parameter.
676 * @return The status of the operation.
677 */
678 EXTERN int errAddIntParm (ASN1ErrInfo* pErrInfo, int errParm);
679
680 /**
681 * This function adds an string parameter to an error information structure.
682 * Parameter substitution is done in much the same way as it is done in C
683 * printf statements. The base error message specification that goes along with
684 * a particular status code may have variable fields built in using '%'
685 * modifiers. These would be replaced with actual parameter data.
686 *
687 * @param pErrInfo A pointer to a structure containing information on the
688 * error to be printed. Typically, the error info
689 * structure referred to is the one inside the OOCTXT
690 * structure. (i.e. &pctxt->errInfo).
691 * @param errprm_p The typed error parameter.
692 * @return The status of the operation.
693 */
694 EXTERN int errAddStrParm (ASN1ErrInfo* pErrInfo,
695 const char* errprm_p);
696
697 /**
698 * This function adds an unsigned integer parameter to an error information
699 * structure. Parameter substitution is done in much the same way as it is done
700 * in C printf statements. The base error message specification that goes along
701 * with a particular status code may have variable fields built in using '%'
702 * modifiers. These would be replaced with actual parameter data.
703 *
704 * @param pErrInfo A pointer to a structure containing information on the
705 * error to be printed. Typically, the error info
706 * structure referred to is the one inside the OOCTXT
707 * structure. (i.e. &pctxt->errInfo).
708 * @param errParm The typed error parameter.
709 * @return The status of the operation.
710 */
711 EXTERN int errAddUIntParm (ASN1ErrInfo* pErrInfo, unsigned int errParm);
712
713
714 EXTERN int errCopyData (ASN1ErrInfo* pSrcErrInfo,
715 ASN1ErrInfo* pDestErrInfo);
716
717 /**
718 * This function frees memory associated with the storage of parameters
719 * associated with an error message. These parameters are maintained on an
720 * internal linked list maintained within the error information structure. The
721 * list memory must be freed when error processing is complete. This function
722 * is called from within errPrint after the error has been printed out. It is
723 * also called in the freeContext function.
724 *
725 * @param pErrInfo A pointer to a structure containing information on the
726 * error to be printed. Typically, the error info
727 * structure referred to is the one inside the OOCTXT
728 * structure. (i.e. &pctxt->errInfo).
729 */
730 EXTERN void errFreeParms (ASN1ErrInfo* pErrInfo);
731
732
733 EXTERN char* errFmtMsg (ASN1ErrInfo* pErrInfo, char* bufp);
734
735 /**
736 * This function gets the text of the error
737 *
738 * @param pctxt A pointer to a context structure.
739 */
740 EXTERN char* errGetText (OOCTXT* pctxt);
741
742 /**
743 * This function prints error information to the standard output device. The
744 * error information is stored in a structure of type ASN1ErrInfo. A structure
745 * of the this type is part f the OOCTXT structure. This is where error
746 * information is stored within the ASN1C generated and low-level encode/decode
747 * functions.
748 *
749 * @param pErrInfo A pointer to a structure containing information on the
750 * error to be printed. Typically, the error info
751 * structure referred to is the one inside the OOCTXT
752 * structure. (i.e. &pctxt->errInfo).
753 */
754 EXTERN void errPrint (ASN1ErrInfo* pErrInfo);
755
756 /**
757 * This function resets the error information in the error information
758 * sturcture.
759 *
760 * @param pErrInfo A pointer to a structure containing information on the
761 * error to be printed. Typically, the error info
762 * structure referred to is the one inside the OOCTXT
763 * structure. (i.e. &pctxt->errInfo).
764 */
765 EXTERN int errReset (ASN1ErrInfo* pErrInfo);
766
767 /**
768 * This function sets error information in an error information structure. The
769 * information set includes status code, module name, and line number. Location
770 * information (i.e. module name and line number) is pushed onto a stack within
771 * the error information structure to provide a complete stack trace when the
772 * information is printed out.
773 *
774 * @param pErrInfo A pointer to a structure containing information on the
775 * error to be printed. Typically, the error info
776 * structure referred to is the one inside the OOCTXT
777 * structure. (i.e. &pctxt->errInfo).
778 * @param status The error status code. This is one of the negative error
779 * status codes.
780 * @param module The name of the module (C or C++ source file) in which
781 * the module occurred. This is typically obtained by
782 * using the _FILE_ macro.
783 * @param lno The line number at which the error occurred. This is
784 * typically obtained by using the _LINE_ macro.
785 * @return The status value passed to the operation in the third
786 * argument. This makes it possible to set the error
787 * information and return the status value in one line of
788 * code.
789 */
790 EXTERN int errSetData (ASN1ErrInfo* pErrInfo, int status,
791 const char* module, int lno);
792
793 #ifndef _COMPACT
794 #define LOG_ASN1ERR(ctxt,stat) \
795 errSetData(&(ctxt)->errInfo,stat,__FILE__,__LINE__)
796 #else
797 #define LOG_ASN1ERR(ctxt,stat) \
798 ((ctxt)->errInfo.status = stat, stat)
799 #endif
800
801
802
803 #define LOG_ASN1ERR_AND_FREE(pctxt,stat,lctxt) \
804 freeContext ((lctxt)), LOG_ASN1ERR(pctxt, stat)
805 /**
806 * @}
807 */
808
809 #define RT_MH_DONTKEEPFREE 0x1
810
811 #define OSRTMH_PROPID_DEFBLKSIZE 1
812 #define OSRTMH_PROPID_SETFLAGS 2
813 #define OSRTMH_PROPID_CLEARFLAGS 3
814
815 #define OSRTMH_PROPID_USER 10
816
817 /**
818 * @addtogroup rtmem
819 * @{
820 */
821 /**
822 * Allocate memory. This macro allocates the given number of bytes. It is
823 * similar to the C \c malloc run-time function.
824 *
825 * @param pctxt - Pointer to a context block
826 * @param nbytes - Number of bytes of memory to allocate
827 * @return - Void pointer to allocated memory or NULL if insufficient memory
828 * was available to fulfill the request.
829 */
830 #define memAlloc(pctxt,nbytes) \
831 memHeapAlloc(&(pctxt)->pTypeMemHeap,nbytes)
832
833 /**
834 * Allocate and zero memory. This macro allocates the given number of bytes
835 * and then initializes the memory block to zero.
836 *
837 * @param pctxt - Pointer to a context block
838 * @param nbytes - Number of bytes of memory to allocate
839 * @return - Void pointer to allocated memory or NULL if insufficient memory
840 * was available to fulfill the request.
841 */
842 #define memAllocZ(pctxt,nbytes) \
843 memHeapAllocZ(&(pctxt)->pTypeMemHeap,nbytes)
844
845 /**
846 * Reallocate memory. This macro reallocates a memory block (either
847 * expands or contracts) to the given number of bytes. It is
848 * similar to the C \c realloc run-time function.
849 *
850 * @param pctxt - Pointer to a context block
851 * @param mem_p - Pointer to memory block to reallocate. This must have been
852 * allocated using the memHeapAlloc macro or the memHeapAlloc function.
853 * @param nbytes - Number of bytes of memory to which the block is to be
854 * resized.
855 * @return - Void pointer to allocated memory or NULL if insufficient memory
856 * was available to fulfill the request. This may be the same as the pmem
857 * pointer that was passed in if the block did not need to be relocated.
858 */
859 #define memRealloc(pctxt,mem_p,nbytes) \
860 memHeapRealloc(&(pctxt)->pTypeMemHeap, (void*)mem_p, nbytes)
861
862 /**
863 * Free memory pointer. This macro frees memory at the given pointer.
864 * The memory must have been allocated using the memHeapAlloc (or similar)
865 * macros or the mem memory allocation macros. This macro is
866 * similar to the C \c free function.
867 *
868 * @param pctxt - Pointer to a context block
869 * @param mem_p - Pointer to memory block to free. This must have
870 * been allocated using the memHeapAlloc or memAlloc macro or the
871 * memHeapAlloc function.
872 */
873 #define memFreePtr(pctxt,mem_p) \
874 if (memHeapCheckPtr (&(pctxt)->pTypeMemHeap, (void*)mem_p)) \
875 memHeapFreePtr(&(pctxt)->pTypeMemHeap, (void*)mem_p)
876
877 /**
878 * Free memory associated with a context. This macro frees all memory
879 * held within a context. This is all memory allocated using the
880 * memHeapAlloc (and similar macros) and the mem memory allocation
881 * functions using the given context variable.
882 *
883 * @param pctxt - Pointer to a context block
884 */
885 #define memFree(pctxt) \
886 memHeapFreeAll(&(pctxt)->pTypeMemHeap)
887
888 /**
889 * Reset memory associated with a context. This macro resets all memory
890 * held within a context. This is all memory allocated using the memHeapAlloc
891 * (and similar macros) and the mem memory allocation functions using the
892 * given context variable.
893 *
894 * <p>The difference between this and the ASN1MEMFREE macro is that the
895 * memory blocks held within the context are not actually freed. Internal
896 * pointers are reset so the existing blocks can be reused. This can
897 * provide a performace improvement for repetitive tasks such as decoding
898 * messages in a loop.
899 *
900 * @param pctxt - Pointer to a context block
901 */
902 #define memReset(pctxt) \
903 memHeapReset(&(pctxt)->pTypeMemHeap)
904
905 /* Alias for __cdecl modifier; if __cdecl keyword is not supported,
906 * redefine it as empty macro. */
907
908 #if !defined(OSCDECL)
909 #if defined(_MSC_VER) || defined(__BORLANDC__)
910 #define OSCDECL __cdecl
911 #else
912 #define OSCDECL
913 #endif
914 #endif /* OSCDECL */
915
916 /* Pointers to C Run-Time memory allocation functions *
917 * (See memSetAllocFuncs) */
918
919 typedef void *(OSCDECL *OSMallocFunc ) (size_t size);
920 typedef void *(OSCDECL *OSReallocFunc) (void *ptr, size_t size);
921 typedef void (OSCDECL *OSFreeFunc ) (void *ptr);
922
923 EXTERN void memHeapAddRef (void** ppvMemHeap);
924 EXTERN void* memHeapAlloc (void** ppvMemHeap, int nbytes);
925 EXTERN void* memHeapAllocZ (void** ppvMemHeap, int nbytes);
926 EXTERN int memHeapCheckPtr (void** ppvMemHeap, void* mem_p);
927 EXTERN int memHeapCreate (void** ppvMemHeap);
928 EXTERN void memHeapFreeAll (void** ppvMemHeap);
929 EXTERN void memHeapFreePtr (void** ppvMemHeap, void* mem_p);
930 EXTERN void* memHeapRealloc (void** ppvMemHeap, void* mem_p, int nbytes_);
931 EXTERN void memHeapRelease (void** ppvMemHeap);
932 EXTERN void memHeapReset (void** ppvMemHeap);
933
934 EXTERN void* memHeapMarkSaved
935 (void** ppvMemHeap, const void* mem_p, ASN1BOOL saved);
936
937 EXTERN void memHeapSetProperty
938 (void** ppvMemHeap, ASN1UINT propId, void* pProp);
939
940
941 /**
942 * This function sets the pointers to standard allocation functions. These
943 * functions are used to allocate/reallocate/free the memory blocks. By
944 * default, standard C functions - 'malloc', 'realloc' and 'free' - are used.
945 * But if some platforms do not support these functions (or some other reasons
946 * exist) they can be overloaded. The functions being overloaded should have
947 * the same prototypes as standard ones.
948 *
949 * @param malloc_func Pointer to the memory allocation function ('malloc' by
950 * default).
951 * @param realloc_func Pointer to the memory reallocation function ('realloc'
952 * by default).
953 * @param free_func Pointer to the memory deallocation function ('free' by
954 * default).
955 */
956 EXTERN void memSetAllocFuncs (OSMallocFunc malloc_func,
957 OSReallocFunc realloc_func,
958 OSFreeFunc free_func);
959
960 EXTERN void memFreeOpenSeqExt (OOCTXT* pctxt, DList *pElemList);
961
962 /*
963 * This function sets flags to a heap. May be used to control the heap's
964 * behavior.
965 *
966 * @param pctxt Pointer to a memory block structure that contains the
967 * list of dynamic memory block maintained by these
968 * functions.
969 * @param flags The flags.
970 */
971 EXTERN void memHeapSetFlags (OOCTXT* pctxt, ASN1UINT flags);
972
973 /*
974 * This function clears memory heap flags.
975 *
976 * @param pctxt Pointer to a memory block structure that contains the
977 * list of dynamic memory block maintained by these
978 * functions.
979 * @param flags The flags
980 */
981 EXTERN void memHeapClearFlags (OOCTXT* pctxt, ASN1UINT flags);
982
983 /**
984 * This function sets the pointer to standard allocation functions. These
985 * functions are used to allocate/reallocate/free the memory blocks. By
986 * default, standard C functions - malloc, realloc, and free - are used. But if
987 * some platforms do not support these functions or some other reasons exist)
988 * they can be overloaded. The functions being overloaded should have the same
989 * prototypes as standard ones.
990 *
991 * @param pctxt Pointer to a context block.
992 * @param blkSize The currently used minimum size and the granularity of
993 * memory blocks.
994 */
995
996 EXTERN void memHeapSetDefBlkSize (OOCTXT* pctxt, ASN1UINT blkSize);
997
998 /**
999 * This function returns the actual granularity of memory blocks.
1000 *
1001 * @param pctxt Pointer to a context block.
1002 */
1003 EXTERN ASN1UINT memHeapGetDefBlkSize (OOCTXT* pctxt);
1004
1005 #ifdef _STATIC_HEAP
1006 EXTERN void memSetStaticBuf (void* memHeapBuf, ASN1UINT blkSize);
1007 #endif
1008
1009 /* PER encode/decode related items */
1010
1011 #define INCRBITIDX(pctxt) \
1012 ((--(pctxt)->buffer.bitOffset < 0) ? \
1013 ((++(pctxt)->buffer.byteIndex >= (pctxt)->buffer.size) ? ASN_E_ENDOFBUF : \
1014 ((pctxt)->buffer.bitOffset = 7, ASN_OK)) : ASN_OK)
1015
1016 #define DECODEBIT(pctxt,pvalue) \
1017 ((INCRBITIDX (pctxt) != ASN_OK) ? ASN_E_ENDOFBUF : ( \
1018 ((*(pvalue) = (((pctxt)->buffer.data[(pctxt)->buffer.byteIndex]) & \
1019 (1 << (pctxt)->buffer.bitOffset)) != 0), ASN_OK) ))
1020 /*
1021 #define DECODEBIT(pctxt,pvalue) \
1022 ((INCRBITIDX (pctxt) != ASN_OK) ? ASN_E_ENDOFBUF : ((pvalue) ? \
1023 ((*(pvalue) = (((pctxt)->buffer.data[(pctxt)->buffer.byteIndex]) & \
1024 (1 << (pctxt)->buffer.bitOffset)) != 0), ASN_OK) : ASN_OK ))
1025 */
1026
1027 /*
1028 #define SETCHARSET(csetvar, canset, abits, ubits) \
1029 csetvar.charSet.nchars = 0; \
1030 csetvar.canonicalSet = canset; \
1031 csetvar.canonicalSetSize = sizeof(canset)-1; \
1032 csetvar.canonicalSetBits = getUIntBitCount(csetvar.canonicalSetSize); \
1033 csetvar.charSetUnalignedBits = ubits; \
1034 csetvar.charSetAlignedBits = abits;
1035 */
1036
1037 /**
1038 * This function will decode a series of multiple bits and place the results in
1039 * an unsigned integer variable.
1040 *
1041 * @param pctxt A pointer to a context structure. This provides a
1042 * storage area for the function to store all working
1043 * variables that must be maintained between function
1044 * calls.
1045 * @param pvalue A pointer to an unsigned integer variable to receive the
1046 * decoded result.
1047 * @param nbits The number of bits to decode.
1048 * @return Completion status of operation:
1049 * - 0 (ASN_OK) = success,
1050 * - negative return value is error.
1051 */
1052 EXTERN int decodeBits
1053 (OOCTXT* pctxt, ASN1UINT* pvalue, ASN1UINT nbits);
1054
1055 /**
1056 * This function will decode a value of the ASN.1 bit string type whose maximum
1057 * size is is known in advance. The ASN1C complier generates a call to this
1058 * function to decode bit string productions or elements that contain a size
1059 * constraint.
1060 *
1061 * @param pctxt A pointer to a context structure. This provides a
1062 * storage area for the function to store all working
1063 * variables that must be maintained between function
1064 * calls.
1065 * @param numbits_p Pointer to an unsigned integer variable to receive
1066 * decoded number of bits.
1067 * @param buffer Pointer to a fixed-size or pre-allocated array of bufsiz
1068 * octets to receive a decoded bit string.
1069 * @param bufsiz Length (in octets) of the buffer to receive the decoded
1070 * bit string.
1071 * @return Completion status of operation:
1072 * - 0 (ASN_OK) = success,
1073 * - negative return value is error.
1074 */
1075 EXTERN int decodeBitString
1076 (OOCTXT* pctxt, ASN1UINT* numbits_p, ASN1OCTET* buffer,
1077 ASN1UINT bufsiz);
1078
1079 /**
1080 * This function will decode a variable of the ASN.1 BMP character string. This
1081 * differs from the decode routines for the character strings previously
1082 * described in that the BMP string type is based on 16-bit characters. A
1083 * 16-bit character string is modeled using an array of unsigned short
1084 * integers.
1085 *
1086 * @param pctxt A pointer to a context structure. This provides a
1087 * storage area for the function to store all working
1088 * variables that must be maintained between function
1089 * calls.
1090 * @param pvalue Pointer to character string structure to receive the
1091 * decoded result The structure includes a count field
1092 * containing the number of characters and an array of
1093 * unsigned short integers to hold the 16-bit character
1094 * values.
1095 * @param permCharSet A pointer to the constraining character set. This
1096 * contains an array containing all valid characters in
1097 * the set as well as the aligned and unaligned bit
1098 * counts required to encode the characters.
1099 * @return Completion status of operation:
1100 * - 0 (ASN_OK) = success,
1101 * - negative return value is error.
1102 */
1103 EXTERN int decodeBMPString
1104 (OOCTXT* pctxt, ASN1BMPString* pvalue, Asn116BitCharSet* permCharSet);
1105
1106 /**
1107 * This function will position the decode bit cursor on the next byte boundary.
1108 *
1109 * @param pctxt A pointer to a context structure. This provides a
1110 * storage area for the function to store all working
1111 * variables that must be maintained between function
1112 * calls.
1113 * @return Completion status of operation:
1114 * - 0 (ASN_OK) = success,
1115 * - negative return value is error.
1116 */
1117 EXTERN int decodeByteAlign (OOCTXT* pctxt);
1118
1119 /**
1120 * This function will decode an integer constrained either by a value or value
1121 * range constraint.
1122 *
1123 * @param pctxt Pointer to context block structure.
1124 * @param pvalue Pointer to integer variable to receive decoded value.
1125 * @param lower Lower range value.
1126 * @param upper Upper range value.
1127 * @return Completion status of operation:
1128 * - 0 (ASN_OK) = success,
1129 * - negative return value is error.
1130 */
1131 EXTERN int decodeConsInteger
1132 (OOCTXT* pctxt, ASN1INT* pvalue, ASN1INT lower, ASN1INT upper);
1133
1134 /**
1135 * This function will decode an unsigned integer constrained either by a value
1136 * or value range constraint.
1137 *
1138 * @param pctxt Pointer to context block structure.
1139 * @param pvalue Pointer to unsigned integer variable to receive decoded
1140 * value.
1141 * @param lower Lower range value.
1142 * @param upper Upper range value.
1143 * @return Completion status of operation:
1144 * - 0 (ASN_OK) = success,
1145 * - negative return value is error.
1146 */
1147 EXTERN int decodeConsUnsigned
1148 (OOCTXT* pctxt, ASN1UINT* pvalue, ASN1UINT lower, ASN1UINT upper);
1149
1150 /**
1151 * This function will decode an 8-bit unsigned integer constrained either by a
1152 * value or value range constraint.
1153 *
1154 * @param pctxt Pointer to context block structure.
1155 * @param pvalue Pointer to 8-bit unsigned integer variable to receive
1156 * decoded value.
1157 * @param lower Lower range value.
1158 * @param upper Upper range value.
1159 * @return Completion status of operation:
1160 * - 0 (ASN_OK) = success,
1161 * - negative return value is error.
1162 */
1163 EXTERN int decodeConsUInt8 (OOCTXT* pctxt,
1164 ASN1UINT8* pvalue, ASN1UINT lower, ASN1UINT upper);
1165
1166 /**
1167 * This function will decode a 16-bit unsigned integer constrained either by a
1168 * value or value range constraint.
1169 *
1170 * @param pctxt Pointer to context block structure.
1171 * @param pvalue Pointer to 16-bit unsigned integer variable to receive
1172 * decoded value.
1173 * @param lower Lower range value.
1174 * @param upper Upper range value.
1175 * @return Completion status of operation:
1176 * - 0 (ASN_OK) = success,
1177 * - negative return value is error.
1178 */
1179 EXTERN int decodeConsUInt16
1180 (OOCTXT* pctxt, ASN1USINT* pvalue, ASN1UINT lower, ASN1UINT upper);
1181
1182 /**
1183 * This function decodes a constrained whole number as specified in Section
1184 * 10.5 of the X.691 standard.
1185 *
1186 * @param pctxt Pointer to context block structure.
1187 * @param padjusted_value Pointer to unsigned adjusted integer value to
1188 * receive decoded result. To get the final value,
1189 * this value is added to the lower boundary of the
1190 * range.
1191 * @param range_value Unsigned integer value specifying the total size
1192 * of the range. This is obtained by subtracting
1193 * the lower range value from the upper range
1194 * value.
1195 * @return Completion status of operation:
1196 * - 0 (ASN_OK) = success,
1197 * - negative return value is error.
1198 */
1199 EXTERN int decodeConsWholeNumber
1200 (OOCTXT* pctxt, ASN1UINT* padjusted_value, ASN1UINT range_value);
1201
1202 /**
1203 * This function decodes a constrained string value. This version of the
1204 * function allows all of the required permitted alphabet constraint parameters
1205 * to be passed in as arguments.
1206 *
1207 * @param pctxt Pointer to context block structure.
1208 * @param string Pointer to const char* to receive decoded string. Memory
1209 * will be allocated for this variable using internal
1210 * memory management functions.
1211 * @param charSet String containing permitted alphabet character set. Can
1212 * be null if no character set was specified.
1213 * @param abits Number of bits in a character set character (aligned).
1214 * @param ubits Number of bits in a character set character (unaligned).
1215 * @param canSetBits Number of bits in a character from the canonical set
1216 * representing this string.
1217 * @return Completion status of operation:
1218 * - 0 (ASN_OK) = success,
1219 * - negative return value is error.
1220 */
1221 EXTERN int decodeConstrainedStringEx
1222 (OOCTXT* pctxt, const char** string, const char* charSet,
1223 ASN1UINT abits, ASN1UINT ubits, ASN1UINT canSetBits);
1224
1225 /**
1226 * This function will decode a variable of thr ASN.1 BIT STRING type. This
1227 * function allocates dynamic memory t store the decoded result. The ASN1C
1228 * complier generates a call to this function to decode an unconstrained bit
1229 * string production or element.
1230 *
1231 * @param pctxt A pointer to a context structure. This provides a
1232 * storage area for the function to store all working
1233 * variables that must be maintained between function
1234 * calls.
1235 * @param pBitStr Pointer to a dynamic bit string structure to receive the
1236 * decoded result. This structure contains a field to
1237 * hold the number of decoded bits and a pointer to an
1238 * octet string to hold the decoded data. Memory is
1239 * allocated by the decoder using the memAlloc
1240 * function. This memory is tracked within the context
1241 * and released when the freeContext function is
1242 * invoked.
1243 * @return Completion status of operation:
1244 * - 0 (ASN_OK) = success,
1245 * - negative return value is error.
1246 */
1247 EXTERN int decodeDynBitString (OOCTXT* pctxt, ASN1DynBitStr* pBitStr);
1248
1249 /**
1250 * This function will decode a value of the ASN.1 octet string type whose
1251 * maximum size is known in advance. The ASN1C complier generates a call to
1252 * this function to decode octet string productions or elements that contain a
1253 * size constraint.
1254 *
1255 * @param pctxt A pointer to a context structure. This provides a
1256 * storage area for the function to store all working
1257 * variables that must be maintained between function
1258 * calls.
1259 * @param pOctStr A pointer to a dynamic octet string to receive the
1260 * decoded result.
1261 * @return Completion status of operation:
1262 * - 0 (ASN_OK) = success,
1263 * - negative return value is error.
1264 */
1265 EXTERN int decodeDynOctetString
1266 (OOCTXT* pctxt, ASN1DynOctStr* pOctStr);
1267
1268 /**
1269 * This function will decode a length determinant value.
1270 *
1271 * @param pctxt A pointer to a context structure. This provides a
1272 * storage area for the function to store all working
1273 * variables that must be maintained between function
1274 * calls.
1275 * @param pvalue A pointer to an unsigned integer variable to receive the
1276 * decoded length value.
1277 * @return Completion status of operation:
1278 * - 0 (ASN_OK) = success,
1279 * - negative return value is error.
1280 */
1281 EXTERN int decodeLength (OOCTXT* pctxt, ASN1UINT* pvalue);
1282
1283 /**
1284 * @param pctxt A pointer to a context structure. This provides a
1285 * storage area for the function to store all working
1286 * variables that must be maintained between function
1287 * calls.
1288 * @param bitOffset The bit offset inside the message buffer.
1289 */
1290 EXTERN int moveBitCursor (OOCTXT* pctxt, int bitOffset);
1291
1292 /**
1293 * This function decodes a value of the ASN.1 object identifier type.
1294 *
1295 * @param pctxt Pointer to context block structure.
1296 * @param pvalue Pointer to value to receive decoded result. The
1297 * ASN1OBJID structure contains an integer to hold the
1298 * number of subidentifiers and an array to hold the
1299 * subidentifier values.
1300 * @return Completion status of operation:
1301 * - 0 (ASN_OK) = success,
1302 * - negative return value is error.
1303 */
1304 EXTERN int decodeObjectIdentifier (OOCTXT* pctxt, ASN1OBJID* pvalue);
1305
1306 /**
1307 * This function will decode a value of the ASN.1 octet string type whose
1308 * maximun size is known in advance. The ASN1C compiler generates a call to
1309 * this function to decode octet string productions or elements that contain a
1310 * size constraint.
1311 *
1312 * @param pctxt Pointer to a context structure. This provides a storage
1313 * area for the function to store all working variables
1314 * that must be maintained between function calls.
1315 * @param numocts_p A pointer to an unsigned buffer of bufsiz octets to
1316 * receive decoded data.
1317 * @param buffer A pointer to a pre-allocated buffer of size octets to
1318 * receive the decoded data.
1319 * @param bufsiz The size of the buffer to receive the decoded result.
1320 * @return Completion status of operation:
1321 * - 0 (ASN_OK) = success,
1322 * - negative return value is error.
1323 */
1324 EXTERN int decodeOctetString
1325 (OOCTXT* pctxt, ASN1UINT* numocts_p, ASN1OCTET* buffer,
1326 ASN1UINT bufsiz);
1327
1328 /**
1329 * This function will decode an ASN.1 open type. This used to be the ASN.1 ANY
1330 * type, but now is used in a variety of applications requiring an encoding
1331 * that can be interpreted by a decoder without prior knowledge of the type
1332 * of the variable.
1333 *
1334 * @param pctxt Pointer to a context structure. This provides a storage
1335 * area for the function to store all working variables
1336 * that must be maintained between function calls.
1337 * @param numocts_p A pointer to an unsigned buffer of bufsiz octets to
1338 * receive decoded data.
1339 * @param object_p2 A pointer to an open type variable to receive the
1340 * decoded data.
1341 * @return Completion status of operation:
1342 * - 0 (ASN_OK) = success,
1343 * - negative return value is error.
1344 */
1345 EXTERN int decodeOpenType
1346 (OOCTXT* pctxt, const ASN1OCTET** object_p2, ASN1UINT* numocts_p);
1347
1348 /**
1349 * This function will decode a small non-negative whole number as specified in
1350 * Section 10.6 of the X.691 standard. This is a number that is expected to be
1351 * small, but whose size is potentially unlimited due to the presence of an
1352 * extension maker.
1353 *
1354 * @param pctxt Pointer to a context structure. This provides a storage
1355 * area for the function to store all workings variables
1356 * that must be maintained between function calls.
1357 * @param pvalue Pointer to an unsigned integer value t receive decoded
1358 * results.
1359 * @return Completion status of operation:
1360 * - 0 (ASN_OK) = success,
1361 * - negative return value is error.
1362 */
1363 EXTERN int decodeSmallNonNegWholeNumber
1364 (OOCTXT* pctxt, ASN1UINT* pvalue);
1365
1366 /**
1367 * This function will decode a semi-constrained integer.
1368 *
1369 * @param pctxt Pointer to context block structure.
1370 * @param pvalue Pointer to integer variable to receive decoded value.
1371 * @param lower Lower range value, represented as signed
1372 * integer.
1373 * @return Completion status of operation:
1374 * - 0 (ASN_OK) = success,
1375 * - negative return value is error.
1376 */
1377 EXTERN int decodeSemiConsInteger
1378 (OOCTXT* pctxt, ASN1INT* pvalue, ASN1INT lower);
1379
1380 /**
1381 * This function will decode a semi-constrained unsigned integer.
1382 *
1383 * @param pctxt Pointer to context block structure.
1384 * @param pvalue Pointer to unsigned integer variable to receive decoded
1385 * value.
1386 * @param lower Lower range value, represented as unsigned
1387 * integer.
1388 * @return Completion status of operation:
1389 * - 0 (ASN_OK) = success,
1390 * - negative return value is error.
1391 */
1392 EXTERN int decodeSemiConsUnsigned
1393 (OOCTXT* pctxt, ASN1UINT* pvalue, ASN1UINT lower);
1394
1395 /**
1396 * This function will decode an unconstrained integer.
1397 *
1398 * @param pctxt Pointer to context block structure.
1399 * @param pvalue Pointer to integer variable to receive decoded value.
1400 * @return Completion status of operation:
1401 * - 0 (ASN_OK) = success,
1402 * - negative return value is error.
1403 */
1404 #define decodeUnconsInteger(pctxt,pvalue) \
1405 decodeSemiConsInteger(pctxt, pvalue, ASN1INT_MIN)
1406
1407 /**
1408 * This function will decode an unconstrained unsigned integer.
1409 *
1410 * @param pctxt Pointer to context block structure.
1411 * @param pvalue Pointer to unsigned integer variable to receive decoded
1412 * value.
1413 * @return Completion status of operation:
1414 * - 0 (ASN_OK) = success,
1415 * - negative return value is error.
1416 */
1417 #define decodeUnconsUnsigned(pctxt,pvalue) \
1418 decodeSemiConsUnsigned(pctxt, pvalue, 0U)
1419
1420 EXTERN int decodeVarWidthCharString (OOCTXT* pctxt, const char** pvalue);
1421
1422 /**
1423 * This function will encode a variable of the ASN.1 BOOLEAN type in
1424 * a single bit.
1425 *
1426 * @param pctxt Pointer to a context structure. This provides a storage
1427 * area for the function to store all working variables
1428 * that must be maintained between function calls.
1429 * @param value The BOOLEAN value to be encoded.
1430 */
1431 EXTERN int encodeBit (OOCTXT* pctxt, ASN1BOOL value);
1432
1433 /**
1434 * This function encodes multiple bits.
1435 *
1436 * @param pctxt Pointer to context block structure.
1437 * @param value Unsigned integer containing the bits to be encoded.
1438 * @param nbits Number of bits in value to encode.
1439 * @return Completion status of operation:
1440 * - 0 (ASN_OK) = success,
1441 * - negative return value is error.
1442 */
1443 EXTERN int encodeBits
1444 (OOCTXT* pctxt, ASN1UINT value, ASN1UINT nbits);
1445
1446 /**
1447 * This function will encode a value of the ASN.1 bit string type.
1448 *
1449 * @param pctxt A pointer to a context structure. This provides a
1450 * storage area for the function to store all working
1451 * variables that must be maintained between function
1452 * calls.
1453 * @param numocts The number of bits n the string to be encoded.
1454 * @param data Pointer to the bit string data to be encoded.
1455 * @return Completion status of operation:
1456 * - 0 (ASN_OK) = success,
1457 * - negative return value is error.
1458 */
1459 EXTERN int encodeBitString
1460 (OOCTXT* pctxt, ASN1UINT numocts, const ASN1OCTET* data);
1461
1462 /**
1463 * This function will encode a variable of the ASN.1 BMP character string. This
1464 * differs from the encode routines for the character strings previously
1465 * described in that the BMP string type is based on 16-bit characters. A
1466 * 16-bit character string is modeled using an array of unsigned short
1467 * integers.
1468 *
1469 * @param pctxt A pointer to a context structure. This provides a
1470 * storage area for the function to store all working
1471 * variables that must be maintained between function
1472 * calls.
1473 * @param value Character string to be encoded. This structure includes
1474 * a count field containing the number of characters to
1475 * encode and an array of unsigned short integers to hold
1476 * the 16-bit characters to be encoded.
1477 * @param permCharSet Pointer to the constraining character set. This contains
1478 * an array containing all valid characters in the set as
1479 * well as the aligned and unaligned bit counts required
1480 * to encode the characters.
1481 * @return Completion status of operation:
1482 * - 0 (ASN_OK) = success,
1483 * - negative return value is error.
1484 */
1485 EXTERN int encodeBMPString
1486 (OOCTXT* pctxt, ASN1BMPString value, Asn116BitCharSet* permCharSet);
1487
1488 /**
1489 * This function will position the encode bit cursor on the next byte boundry.
1490 *
1491 * @param pctxt A pointer to a context structure. This provides a
1492 * storage area for the function to store all working
1493 * variables that must be maintained between function
1494 * calls.
1495 * @return Completion status of operation:
1496 * - 0 (ASN_OK) = success,
1497 * - negative return value is error.
1498 */
1499 EXTERN int encodeByteAlign (OOCTXT* pctxt);
1500
1501 /**
1502 * This function will determine if the given number of bytes will fit in the
1503 * encode buffer. If not, either the buffer is expanded (if it is a dynamic
1504 * buffer) or an error is signaled.
1505 *
1506 * @param pctxt A pointer to a context structure. This provides a
1507 * storage area for the function to store all working
1508 * variables that must be maintained between function
1509 * calls.
1510 * @param nbytes Number of bytes of space required to hold the variable
1511 * to be encoded.
1512 * @return Completion status of operation:
1513 * - 0 (ASN_OK) = success,
1514 * - negative return value is error.
1515 */
1516 EXTERN int encodeCheckBuffer (OOCTXT* pctxt, ASN1UINT nbytes);
1517
1518 /**
1519 * This function encodes a constrained string value. This version of the
1520 * function allows all of the required permitted alphabet constraint parameters
1521 * to be passed in as arguments.
1522 *
1523 * @param pctxt Pointer to context block structure.
1524 * @param string Pointer to string to be encoded.
1525 * @param charSet String containing permitted alphabet character set. Can
1526 * be null if no character set was specified.
1527 * @param abits Number of bits in a character set character (aligned).
1528 * @param ubits Number of bits in a character set character (unaligned).
1529 * @param canSetBits Number of bits in a character from the canonical set
1530 * representing this string.
1531 * @return Completion status of operation:
1532 * - 0 (ASN_OK) = success,
1533 * - negative return value is error.
1534 */
1535 EXTERN int encodeConstrainedStringEx
1536 (OOCTXT* pctxt, const char* string, const char* charSet,
1537 ASN1UINT abits, ASN1UINT ubits, ASN1UINT canSetBits);
1538
1539 /**
1540 * This function encodes an integer constrained either by a value or value
1541 * range constraint.
1542 *
1543 * @param pctxt Pointer to context block structure.
1544 * @param value Value to be encoded.
1545 * @param lower Lower range value.
1546 * @param upper Upper range value.
1547 * @return Completion status of operation:
1548 * - 0 (ASN_OK) = success,
1549 * - negative return value is error.
1550 */
1551 EXTERN int encodeConsInteger
1552 (OOCTXT* pctxt, ASN1INT value, ASN1INT lower, ASN1INT upper);
1553
1554 /**
1555 * This function encodes an unsigned integer constrained either by a value or
1556 * value range constraint. The constrained unsigned integer option is used if:
1557 *
1558 * 1. The lower value of the range is >= 0, and 2. The upper value of the range
1559 * is >= MAXINT
1560 *
1561 * @param pctxt Pointer to context block structure.
1562 * @param value Value to be encoded.
1563 * @param lower Lower range value.
1564 * @param upper Upper range value.
1565 * @return Completion status of operation:
1566 * - 0 (ASN_OK) = success,
1567 * - negative return value is error.
1568 */
1569 EXTERN int encodeConsUnsigned
1570 (OOCTXT* pctxt, ASN1UINT value, ASN1UINT lower, ASN1UINT upper);
1571
1572 /**
1573 * This function encodes a constrained whole number as specified in Section
1574 * 10.5 of the X.691 standard.
1575 *
1576 * @param pctxt Pointer to context block structure.
1577 * @param adjusted_value Unsigned adjusted integer value to be encoded. The
1578 * adjustment is done by subtracting the lower value
1579 * of the range from the value to be encoded.
1580 * @param range_value Unsigned integer value specifying the total size of
1581 * the range. This is obtained by subtracting the
1582 * lower range value from the upper range value.
1583 * @return Completion status of operation:
1584 * - 0 (ASN_OK) = success,
1585 * - negative return value is error.
1586 */
1587 EXTERN int encodeConsWholeNumber
1588 (OOCTXT* pctxt, ASN1UINT adjusted_value, ASN1UINT range_value);
1589
1590 /**
1591 * This function will expand the buffer to hold the given number of bytes.
1592 *
1593 * @param pctxt Pointer to a context structure. This provides a storage
1594 * area for the function to store all working variables
1595 * that must be maintained between function calls.
1596 * @param nbytes The number of bytes the buffer is to be expanded by.
1597 * Note that the buffer will be expanded by
1598 * ASN_K_ENCBIFXIZ or nbytes (whichever is larger.
1599 * @return Completion status of operation:
1600 * - 0 (ASN_OK) = success,
1601 * - negative return value is error.
1602 */
1603 EXTERN int encodeExpandBuffer (OOCTXT* pctxt, ASN1UINT nbytes);
1604
1605 /**
1606 * This function will return the message pointer and length of an encoded
1607 * message. This function is called after a complier generated encode function
1608 * to get the pointer and length of the message. It is normally used when
1609 * dynamic encoding is specified because the message pointer is not known until
1610 * encoding is complete. If static encoding is used, the message starts at the
1611 * beginning of the specified buffer adn the encodeGetMsgLen function can be
1612 * used to obtain the lenght of the message.
1613 *
1614 * @param pctxt Pointer to a context structure. This provides a storage
1615 * area for the function to store all working variables
1616 * that must be maintained between function calls.
1617 * @param pLength Pointer to variable to receive length of the encoded
1618 * message.
1619 * @return Completion status of operation:
1620 * - 0 (ASN_OK) = success,
1621 * - negative return value is error.
1622 */
1623 EXTERN ASN1OCTET* encodeGetMsgPtr (OOCTXT* pctxt, int* pLength);
1624
1625 /**
1626 * This function will encode a length determinant value.
1627 *
1628 * @param pctxt Pointer to a context structure. This provides a storage
1629 * area for the function to store all working variables
1630 * that must be maintained between function calls.
1631 * @param value Length value to be encoded.
1632 * @return Completion status of operation:
1633 * - 0 (ASN_OK) = success,
1634 * - negative return value is error.
1635 */
1636 EXTERN int encodeLength (OOCTXT* pctxt, ASN1UINT value);
1637
1638 /**
1639 * This function encodes a value of the ASN.1 object identifier type.
1640 *
1641 * @param pctxt Pointer to context block structure.
1642 * @param pvalue Pointer to value to be encoded. The ASN1OBJID structure
1643 * contains a numids fields to hold the number of
1644 * subidentifiers and an array to hold the subidentifier
1645 * values.
1646 * @return Completion status of operation:
1647 * - 0 (ASN_OK) = success,
1648 * - negative return value is error.
1649 */
1650 EXTERN int encodeObjectIdentifier (OOCTXT* pctxt, ASN1OBJID* pvalue);
1651
1652
1653 /**
1654 *
1655 * This function encodes bits from a given octet to the output buffer.
1656 *
1657 * @param pctxt Pointer to ASN.1 PER context structure
1658 * @param value Value of bits to be encoded
1659 * @param nbits Number of bits to be encoded
1660 *
1661 * @return Status of operation
1662 */
1663 EXTERN int encodebitsFromOctet (OOCTXT* pctxt, ASN1OCTET value, ASN1UINT nbits);
1664
1665 /**
1666 * This fuction will encode an array of octets. The Octets will be encoded
1667 * unaligned starting at the current bit offset within the encode buffer.
1668 *
1669 * @param pctxt A pointer to a context structure. The provides a storage
1670 * area for the function to store all working variables
1671 * that must be maintained between function calls.
1672 * @param pvalue A pointer to an array of octets to encode
1673 * @param nbits The number of Octets to encode
1674 * @return Completion status of operation:
1675 * - 0 (ASN_OK) = success,
1676 * - negative return value is error.
1677 */
1678 EXTERN int encodeOctets
1679 (OOCTXT* pctxt, const ASN1OCTET* pvalue, ASN1UINT nbits);
1680
1681 /**
1682 * This function will encode a value of the ASN.1 octet string type.
1683 *
1684 * @param pctxt A pointer to a context structure. The provides a storage
1685 * area for the function to store all working variables
1686 * that must be maintained between function calls.
1687 * @param numocts Number of octets in the string to be encoded.
1688 * @param data Pointer to octet string data to be encoded.
1689 * @return Completion status of operation:
1690 * - 0 (ASN_OK) = success,
1691 * - negative return value is error.
1692 */
1693 EXTERN int encodeOctetString
1694 (OOCTXT* pctxt, ASN1UINT numocts, const ASN1OCTET* data);
1695
1696 /**
1697 * This function will encode an ASN.1 open type. This used to be the ANY type,
1698 * but now is used in a variety of applications requiring an encoding that can
1699 * be interpreted by a decoder without a prior knowledge of the type of the
1700 * variable.
1701 *
1702 * @param pctxt A pointer to a context structure. The provides a storage
1703 * area for the function to store all working variables
1704 * that must be maintained between function calls.
1705 * @param numocts Number of octets in the string to be encoded.
1706 * @param data Pointer to octet string data to be encoded.
1707 * @return Completion status of operation:
1708 * - 0 (ASN_OK) = success,
1709 * - negative return value is error.
1710 */
1711 EXTERN int encodeOpenType
1712 (OOCTXT* pctxt, ASN1UINT numocts, const ASN1OCTET* data);
1713
1714 /**
1715 * This function will encode an ASN.1 open type extension. An open type
1716 * extension field is the data that potentially resides after the ... marker in
1717 * a version-1 message. The open type structure contains a complete encoded bit
1718 * set including option element bits or choice index, length, and data.
1719 * Typically, this data is populated when a version-1 system decodes a
1720 * version-2 message. The extension fields are retained and can then be
1721 * re-encoded if a new message is to be sent out (for example, in a store and
1722 * forward system).
1723 *
1724 * @param pctxt A pointer to a context structure. The provides a storage
1725 * area for the function to store all working variables
1726 * that must be maintained between function calls.
1727 * @param pElemList A pointer to the open type to be encoded.
1728 * @return Completion status of operation:
1729 * - 0 (ASN_OK) = success,
1730 * - negative return value is error.
1731 */
1732 EXTERN int encodeOpenTypeExt
1733 (OOCTXT* pctxt, DList* pElemList);
1734
1735 EXTERN int encodeOpenTypeExtBits
1736 (OOCTXT* pctxt, DList* pElemList);
1737
1738 /**
1739 * This function will endcode a small, non-negative whole number as specified
1740 * in Section 10.6 of the X.691 standard. This is a number that is expected to
1741 * be small, but whose size is potentially unlimited due to the presence of an
1742 * extension marker.
1743 *
1744 * @param pctxt A pointer to a context structure. The provides a storage
1745 * area for the function to store all working variables
1746 * that must be maintained between function calls.
1747 * @param value An unsigned integer value to be encoded.
1748 * @return Completion status of operation:
1749 * - 0 (ASN_OK) = success,
1750 * - negative return value is error.
1751 */
1752 EXTERN int encodeSmallNonNegWholeNumber (OOCTXT* pctxt, ASN1UINT value);
1753
1754 /**
1755 * This function encodes a semi-constrained integer.
1756 *
1757 * @param pctxt Pointer to context block structure.
1758 * @param value Value to be encoded.
1759 * @param lower Lower range value, represented as signed
1760 * integer.
1761 * @return Completion status of operation:
1762 * - 0 (ASN_OK) = success,
1763 * - negative return value is error.
1764 */
1765 EXTERN int encodeSemiConsInteger
1766 (OOCTXT* pctxt, ASN1INT value, ASN1INT lower);
1767
1768 /**
1769 * This function encodes an semi-constrained unsigned integer.
1770 *
1771 * @param pctxt Pointer to context block structure.
1772 * @param value Value to be encoded.
1773 * @param lower Lower range value, represented as unsigned
1774 * integer.
1775 * @return Completion status of operation:
1776 * - 0 (ASN_OK) = success,
1777 * - negative return value is error.
1778 */
1779 EXTERN int encodeSemiConsUnsigned
1780 (OOCTXT* pctxt, ASN1UINT value, ASN1UINT lower);
1781
1782 /**
1783 * This function encodes an unconstrained integer.
1784 *
1785 * @param pctxt Pointer to context block structure.
1786 * @param value Value to be encoded.
1787 * @return Completion status of operation:
1788 * - 0 (ASN_OK) = success,
1789 * - negative return value is error.
1790 */
1791 #define encodeUnconsInteger(pctxt,value) \
1792 encodeSemiConsInteger(pctxt,value,ASN1INT_MIN)
1793
1794 EXTERN int encodeVarWidthCharString (OOCTXT* pctxt, const char* value);
1795
1796 EXTERN int addSizeConstraint (OOCTXT* pctxt, Asn1SizeCnst* pSize);
1797
1798 EXTERN ASN1BOOL alignCharStr
1799 (OOCTXT* pctxt, ASN1UINT len, ASN1UINT nbits, Asn1SizeCnst* pSize);
1800
1801 EXTERN int bitAndOctetStringAlignmentTest
1802 (Asn1SizeCnst* pSizeList, ASN1UINT itemCount,
1803 ASN1BOOL bitStrFlag, ASN1BOOL* pAlignFlag);
1804
1805 EXTERN int getPERMsgLen (OOCTXT* pctxt);
1806
1807 EXTERN int addSizeConstraint (OOCTXT* pctxt, Asn1SizeCnst* pSize);
1808
1809 EXTERN Asn1SizeCnst* getSizeConstraint (OOCTXT* pctxt, ASN1BOOL extbit);
1810
1811 EXTERN int checkSizeConstraint(OOCTXT* pctxt, int size);
1812 EXTERN ASN1UINT getUIntBitCount (ASN1UINT value);
1813
1814 EXTERN Asn1SizeCnst* checkSize
1815 (Asn1SizeCnst* pSizeList, ASN1UINT value, ASN1BOOL* pExtendable);
1816
1817 EXTERN void init16BitCharSet
1818 (Asn116BitCharSet* pCharSet, ASN116BITCHAR first,
1819 ASN116BITCHAR last, ASN1UINT abits, ASN1UINT ubits);
1820
1821 EXTERN ASN1BOOL isExtendableSize (Asn1SizeCnst* pSizeList);
1822
1823 EXTERN void set16BitCharSet
1824 (OOCTXT* pctxt, Asn116BitCharSet* pCharSet, Asn116BitCharSet* pAlphabet);
1825
1826 #ifdef __cplusplus
1827 }
1828 #endif
1829
1830 #endif