Objective Systems, Inc.  
Home
About ASN.1
Products
Free Software
Documents
Services
Resources
Resellers
Customers
Careers
About Us
Contact Us
 

Google


Objective Systems, Inc.

asn1type.h

Go to the documentation of this file.
00001 /* 00002 * Copyright (C) 1997-2004 by Objective Systems, Inc. 00003 * 00004 * This software is furnished under a license and may be used and copied 00005 * only in accordance with the terms of such license and with the 00006 * inclusion of the above copyright notice. This software or any other 00007 * copies thereof may not be provided or otherwise made available to any 00008 * other person. No title to and ownership of the software is hereby 00009 * transferred. 00010 * 00011 * The information in this software is subject to change without notice 00012 * and should not be construed as a commitment by Objective Systems, Inc. 00013 * 00014 * PROPRIETARY NOTICE 00015 * 00016 * This software is an unpublished work subject to a confidentiality agreement 00017 * and is protected by copyright and trade secret law. Unauthorized copying, 00018 * redistribution or other use of this work is prohibited. 00019 * 00020 * The above notice of copyright on this source code product does not indicate 00021 * any actual or intended publication of such source code. 00022 * 00023 *****************************************************************************/ 00024 /* 00025 // CHANGE LOG 00026 // Date Init Description 00027 // 04/24/02 ED Added ASN_E_INVCHAR & ASN_E_XMLSTATE error codes 00028 // 04/24/02 ED Move XD_ macros to asn1intl.h 00029 // 04/24/02 ED Remove #include of asn1intl.h 00030 // 05/03/02 AB Remove all BER-related prototypes 00031 // 05/06/02 AB More only-BER things moved 00032 // 05/08/02 AB Sync with 5.32 00033 // 05/15/02 AB Removed Print functions prototypes 00034 // 05/27/02 AB rtUTF8Len & rtUTF8CharSize added 00035 // 06/02/02 AB rtMemRealloc, rtMemFreePtr, rtDListFreeNodes, 00036 // rtDListFreeAll, rtFreeBigInt added 00037 // 06/05/02 AB rtAddOID added 00038 // 06/15/02 AB ASN1UINT64 added, ASN1OID64 subid type changed 00039 // to ASN1UINT64 00040 // 06/18/02 AB MemBuf functions added 00041 // 07/09/02 AB rtCompareBigIntStr added 00042 // 08/05/02 AB some BigInt funcs are renamed 00043 // 09/16/02 AB ALLOC_ASN1ELEMNODE, rtDListAppendNode added 00044 // 10/05/02 ED Added rtFileReadBinary function 00045 // 10/13/02 AB Some more rtMem* funcs added 00046 // 10/23/02 AP Added ASN_ID_EPDV tag for EmbeddedPDV type 00047 // 10/27/02 AB ASN1I64CONST/ASN1UI64CONST macros are added 00048 // 10/29/03 CZ Added text for main page. 00049 // 11/12/03 CZ Removed end tags from some doxygen groups 00050 // 06/02/04 VP Added functionality to support print stream 00052 */ 00053 00054 /*The following is the text for the main C/C++ Runtime index page.*/ 00132 #ifndef _ASN1TYPE_H_ 00133 #define _ASN1TYPE_H_ 00134 00135 #include <limits.h> 00136 #include <stdio.h> 00137 #include <string.h> 00138 #include <stddef.h> 00139 #include <setjmp.h> 00140 00141 #ifdef _NUCLEUS 00142 #ifndef NUCLEUS 00143 #include <nucleus.h> 00144 #endif /* NUCLEUS */ 00145 #else 00146 00147 #if !defined(_MSC_VER) && !defined(__GNUC__) 00148 #include <wchar.h> 00149 #endif 00150 00151 #endif /* _NUCLEUS */ 00152 00158 /* Set this #define to use an internal tag type of 32 bits instead */ 00159 /* of 16 bits. This will allow ID codes up to 2 ^ 29 (536870912) */ 00160 /* instead of the default representation of 2 ^ 13 (8192). */ 00161 00162 #define ASN1C_EXPANDED_TAGS 00163 00164 /* Tagging Value and Mask Constants */ 00165 00166 /* tag class value constants */ 00167 00168 #define TV_UNIV 0 /* universal */ 00169 #define TV_APPL 1 /* application-wide */ 00170 #define TV_CTXT 2 /* context-specific */ 00171 #define TV_PRIV 3 /* private-use */ 00172 00173 /* tag form value constants */ 00174 00175 #define TV_PRIM 0 /* primitive */ 00176 #define TV_CONS 1 /* constructor */ 00177 00178 /* tag mask values - these can be logically or'd together to */ 00179 /* form tags compatible with the ASNTAG structure.. */ 00180 00181 #ifdef ASN1C_EXPANDED_TAGS 00182 00183 #define TM_UNIV 0x00000000 /* universal class */ 00184 #define TM_APPL 0x40000000 /* application-wide class */ 00185 #define TM_CTXT 0x80000000 /* context-specific class */ 00186 #define TM_PRIV 0xC0000000 /* private-use class */ 00187 00188 #define TM_PRIM 0x00000000 /* primitive form */ 00189 #define TM_CONS 0x20000000 /* constructor form */ 00190 #define TM_IDCODE 0x1FFFFFFF /* ID code mask */ 00191 00192 #define ASN_K_BADTAG 0xFFFFFFFF /* invalid tag code */ 00193 #define ASN_K_NOTAG 0xFFFFFFFF /* no tag input parameter */ 00194 00195 #else 00196 00197 #define TM_UNIV 0x0000 /* universal class */ 00198 #define TM_APPL 0x4000 /* application-wide class */ 00199 #define TM_CTXT 0x8000 /* context-specific class */ 00200 #define TM_PRIV 0xC000 /* private-use class */ 00201 00202 #define TM_PRIM 0x0000 /* primitive form */ 00203 #define TM_CONS 0x2000 /* constructor form */ 00204 #define TM_IDCODE 0x1FFF /* ID code mask */ 00205 00206 #define ASN_K_BADTAG 0xFFFF /* invalid tag code */ 00207 #define ASN_K_NOTAG 0xFFFF /* no tag input parameter */ 00208 00209 #endif 00210 00211 #define TM_CLASS 0xC0 /* class mask */ 00212 #define TM_FORM 0x20 /* form mask */ 00213 #define TM_CLASS_FORM 0xE0 /* class/form mask */ 00214 #define TM_B_IDCODE 0x1F /* id code mask (byte) */ 00215 00216 #ifndef FALSE 00217 #define FALSE 0 00218 #define TRUE 1 00219 #endif 00220 00221 #define MINMSGLEN 8 /* minimum message length */ 00222 00223 /* Error Code Constants */ 00224 00225 #define ASN_OK 0 /* normal completion status */ 00226 #define ASN_OK_FRAG 2 /* message fragment detected */ 00227 #define ASN_E_BUFOVFLW -1 /* encode buffer overflow */ 00228 #define ASN_E_ENDOFBUF -2 /* unexpected end of buffer on decode */ 00229 #define ASN_E_IDNOTFOU -3 /* identifer not found */ 00230 #define ASN_E_INVOBJID -4 /* invalid object identifier */ 00231 #define ASN_E_INVLEN -5 /* invalid field length */ 00232 #define ASN_E_INVENUM -6 /* enumerated value not in defined set */ 00233 #define ASN_E_SETDUPL -7 /* duplicate element in set */ 00234 #define ASN_E_SETMISRQ -8 /* missing required element in set */ 00235 #define ASN_E_NOTINSET -9 /* element not part of set */ 00236 #define ASN_E_SEQOVFLW -10 /* sequence of field overflow */ 00237 #define ASN_E_INVOPT -11 /* invalid option encountered in choice */ 00238 #define ASN_E_NOMEM -12 /* no dynamic memory available */ 00239 #define ASN_E_INVHEXS -14 /* invalid hex string */ 00240 #define ASN_E_INVBINS -15 /* invalid binary string */ 00241 #define ASN_E_INVREAL -16 /* invalid real value */ 00242 #define ASN_E_STROVFLW -17 /* octet or bit string field overflow */ 00243 #define ASN_E_BADVALUE -18 /* invalid value specification */ 00244 #define ASN_E_UNDEFVAL -19 /* no def found for ref'd defined value */ 00245 #define ASN_E_UNDEFTYP -20 /* no def found for ref'd defined type */ 00246 #define ASN_E_BADTAG -21 /* invalid tag value */ 00247 #define ASN_E_TOODEEP -22 /* nesting level is too deep */ 00248 #define ASN_E_CONSVIO -23 /* value constraint violation */ 00249 #define ASN_E_RANGERR -24 /* invalid range (lower > upper) */ 00250 #define ASN_E_ENDOFFILE -25 /* end of file on file decode */ 00251 #define ASN_E_INVUTF8 -26 /* invalid UTF-8 encoding */ 00252 #define ASN_E_CONCMODF -27 /* Concurrent list modification */ 00253 #define ASN_E_ILLSTATE -28 /* Illegal state error */ 00254 #define ASN_E_OUTOFBND -29 /* out of bounds (of array, etc) */ 00255 #define ASN_E_INVPARAM -30 /* invalid parameter */ 00256 #define ASN_E_INVFORMAT -31 /* invalid time string format */ 00257 #define ASN_E_NOTINIT -32 /* not initialized */ 00258 #define ASN_E_TOOBIG -33 /* value is too big for given data type */ 00259 #define ASN_E_INVCHAR -34 /* invalid character (not in char set) */ 00260 #define ASN_E_XMLSTATE -35 /* XML state error */ 00261 #define ASN_E_XMLPARSE -36 /* XML parse error */ 00262 #define ASN_E_SEQORDER -37 /* SEQUENCE elements not in order */ 00263 #define ASN_E_INVINDEX -38 /* invalid index for TC id */ 00264 #define ASN_E_INVTCVAL -39 /* invalid value for TC field */ 00265 #define ASN_E_FILNOTFOU -40 /* file not found */ 00266 #define ASN_E_READERR -41 /* error occurred reading source */ 00267 #define ASN_E_WRITEERR -42 /* error occurred writing target */ 00268 #define ASN_E_INVBASE64 -43 /* invalid base64 encoding */ 00269 #define ASN_E_INVSOCKET -44 /* invalid socket operation */ 00270 #define ASN_E_HSTUNAVAIL -45 /* Local host info is unavailable */ 00271 #define ASN_E_CANTOPEN -46 /* can't open file */ 00272 #define ASN_E_ARRAYSIZE -47 /* message violates the config option */ 00273 #define ASN_E_NOTSUPP -99 /* non-supported ASN construct */ 00274 #define ASN_K_INDEFLEN -9999 /* indefinite length message indicator */ 00275 00276 /* for compatibility */ 00277 #define ASN_E_FILEREAD ASN_E_READERR /* error occurred reading file */ 00278 #define ASN_E_FILEWRITE ASN_E_WRITEERR /* error occurred writing file */ 00279 #define ASN_E_XMLLIBNFOU ASN_E_NOTSUPP /* XML library is not found */ 00280 #define ASN_E_XMLLIBINV ASN_E_NOTSUPP /* XML library is invalid */ 00281 00282 /* universal built-in type ID code value constants */ 00283 00284 #define ASN_ID_EOC 0 /* end of contents */ 00285 #define ASN_ID_BOOL 1 /* boolean */ 00286 #define ASN_ID_INT 2 /* integer */ 00287 #define ASN_ID_BITSTR 3 /* bit string */ 00288 #define ASN_ID_OCTSTR 4 /* byte (octet) string */ 00289 #define ASN_ID_NULL 5 /* null */ 00290 #define ASN_ID_OBJID 6 /* object ID */ 00291 #define ASN_ID_OBJDSC 7 /* object descriptor */ 00292 #define ASN_ID_EXTERN 8 /* external type */ 00293 #define ASN_ID_REAL 9 /* real */ 00294 #define ASN_ID_ENUM 10 /* enumerated value */ 00295 #define ASN_ID_EPDV 11 /* EmbeddedPDV type */ 00296 #define ASN_ID_RELOID 13 /* relative object ID */ 00297 #define ASN_ID_SEQ 16 /* sequence, sequence of */ 00298 #define ASN_ID_SET 17 /* set, set of */ 00299 00300 #define ASN_SEQ_TAG 0x30 /* SEQUENCE universal tag byte */ 00301 #define ASN_SET_TAG 0x31 /* SET universal tag byte */ 00302 00303 /* Restricted character string type ID's */ 00304 00305 #define ASN_ID_NumericString 18 00306 #define ASN_ID_PrintableString 19 00307 #define ASN_ID_TeletexString 20 00308 #define ASN_ID_T61String ASN_ID_TeletexString 00309 #define ASN_ID_VideotexString 21 00310 #define ASN_ID_IA5String 22 00311 #define ASN_ID_UTCTime 23 00312 #define ASN_ID_GeneralTime 24 00313 #define ASN_ID_GraphicString 25 00314 #define ASN_ID_VisibleString 26 00315 #define ASN_ID_GeneralString 27 00316 #define ASN_ID_UniversalString 28 00317 #define ASN_ID_BMPString 30 00318 00319 /* flag mask values */ 00320 00321 #define XM_SEEK 0x01 /* seek match until found or end-of-buf */ 00322 #define XM_ADVANCE 0x02 /* advance pointer to contents on match */ 00323 #define XM_DYNAMIC 0x04 /* alloc dyn mem for decoded variable */ 00324 #define XM_SKIP 0x08 /* skip to next field after parsing tag */ 00325 00326 /* Sizing Constants */ 00327 00328 #define ASN_K_MAXDEPTH 32 /* maximum nesting depth for messages */ 00329 #define ASN_K_MAXSUBIDS 128 /* maximum sub-id's in an object ID */ 00330 #define ASN_K_MAXENUM 100 /* maximum enum values in an enum type */ 00331 #define ASN_K_MAXERRP 5 /* maximum error parameters */ 00332 #define ASN_K_MAXERRSTK 8 /* maximum levels on error ctxt stack */ 00333 00334 #ifndef ASN_K_ENCBUFSIZ 00335 #define ASN_K_ENCBUFSIZ 16*1024 /* dynamic encode buffer extent size */ 00336 #endif 00337 00338 #ifndef ASN_K_MEMBUFSEG 00339 #define ASN_K_MEMBUFSEG 1024 /* memory buffer extent size */ 00340 #endif 00341 00342 /* Constants for encoding/decoding real values */ 00343 00344 #define ASN1_K_PLUS_INFINITY 0x40 00345 #define ASN1_K_MINUS_INFINITY 0x41 00346 00347 #define REAL_BINARY 0x80 00348 #define REAL_SIGN 0x40 00349 #define REAL_EXPLEN_MASK 0x03 00350 #define REAL_EXPLEN_1 0x00 00351 #define REAL_EXPLEN_2 0x01 00352 #define REAL_EXPLEN_3 0x02 00353 #define REAL_EXPLEN_LONG 0x03 00354 #define REAL_FACTOR_MASK 0x0c 00355 #define REAL_BASE_MASK 0x30 00356 #define REAL_BASE_2 0x00 00357 #define REAL_BASE_8 0x10 00358 #define REAL_BASE_16 0x20 00359 #define REAL_ISO6093_MASK 0x3F 00360 00361 /* ASN.1 Primitive Type Definitions */ 00362 00363 typedef char ASN1CHAR; 00364 typedef unsigned char ASN1OCTET; 00365 typedef ASN1OCTET ASN1BOOL; 00366 typedef signed char ASN1INT8; 00367 typedef unsigned char ASN1UINT8; 00368 typedef int ASN1INT; 00369 typedef unsigned int ASN1UINT; 00370 typedef ASN1INT ASN1ENUM; 00371 typedef double ASN1REAL; 00372 00373 #include <float.h> 00374 #define ASN1REALMAX (ASN1REAL)DBL_MAX 00375 #define ASN1REALMIN (ASN1REAL)-DBL_MAX 00376 00377 typedef short ASN1SINT; 00378 typedef unsigned short ASN1USINT; 00379 #ifdef ASN1C_EXPANDED_TAGS 00380 typedef ASN1UINT ASN1TAG; 00381 #define ASN1TAG_LSHIFT 24 00382 #else 00383 typedef ASN1USINT ASN1TAG; 00384 #define ASN1TAG_LSHIFT 8 00385 #endif 00386 typedef ASN1USINT ASN116BITCHAR; 00387 typedef ASN1UINT ASN132BITCHAR; 00388 typedef void* ASN1ANY; 00389 00390 #define ASN1UINT_MAX 4294967295U 00391 #define ASN1INT_MAX ((ASN1INT)2147483647L) 00392 #define ASN1INT_MIN ((ASN1INT)(-ASN1INT_MAX-1)) 00393 00394 /* 64-bit long integer type */ 00395 00396 #ifndef ASN1INT64 00397 #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__) 00398 #define ASN1INT64 __int64 00399 #define ASN1UINT64 unsigned __int64 00400 #define ASN1INT64FMT "%I64d" 00401 #define ASN1UINT64FMT "%I64u" 00402 #define ASN1INT64FMTX "%I64x" 00403 #define ASN1INT64MAX _I64_MAX 00404 #define ASN1UINT64MAX _UI64_MAX 00405 #define ASN1INT64MIN _I64_MIN 00406 #define ASN1I64CONST(val) val##i64 00407 #define ASN1UI64CONST(val) val##ui64 00408 00409 #elif defined(__IBMC__) || defined(__GNUC__) || defined(__SUNPRO_C) || \ 00410 defined(__SUNPRO_CC) || defined(__CC_ARM) || \ 00411 defined(__HPUX_CC__) || defined(__HP_aCC) 00412 #define ASN1INT64 long long 00413 #define ASN1UINT64 unsigned long long 00414 #define ASN1INT64FMT "%lld" 00415 #define ASN1UINT64FMT "%llu" 00416 #define ASN1INT64FMTX "%llx" 00417 #define ASN1I64CONST(val) val##LL 00418 #define ASN1UI64CONST(val) val##ULL 00419 00420 #if defined(__IBMC__) 00421 #define ASN1INT64MAX LONGLONG_MAX 00422 #define ASN1UINT64MAX ULONGLONG_MAX 00423 #define ASN1INT64MIN LONGLONG_MIN 00424 #elif defined(__SUNPRO_CC) || defined(__SUNPRO_C) 00425 #define ASN1INT64MAX LLONG_MAX 00426 #define ASN1UINT64MAX ULLONG_MAX 00427 #define ASN1INT64MIN LLONG_MIN 00428 #elif defined(__CC_ARM) || defined(__FreeBSD__) 00429 #define ASN1INT64MAX LLONG_MAX 00430 #define ASN1UINT64MAX ULLONG_MAX 00431 #define ASN1INT64MIN LLONG_MIN 00432 #elif defined(__HPUX_CC__) || defined(__HP_aCC) 00433 #ifdef __LP64__ /* for 64-bit HP-UX long is 64-bit */ 00434 #define ASN1INT64MAX LONG_MAX 00435 #define ASN1UINT64MAX ULONG_MAX 00436 #define ASN1INT64MIN LONG_MIN 00437 #else /* !__LP64__ */ 00438 #define ASN1INT64MAX LONG_LONG_MAX 00439 #define ASN1UINT64MAX ULONG_LONG_MAX 00440 #define ASN1INT64MIN LONG_LONG_MIN 00441 #endif /* __LP64__ */ 00442 #else /* !__IBMC__ && !SUN && !HP_CC etc */ 00443 #ifndef _GNU_SOURCE 00444 #define _GNU_SOURCE 00445 #endif /* _GNU_SOURCE */ 00446 #define ASN1INT64MAX LONG_LONG_MAX 00447 #define ASN1UINT64MAX ULONG_LONG_MAX 00448 #define ASN1INT64MIN LONG_LONG_MIN 00449 #endif /* __IBMC__ */ 00450 00451 #else /* !MSC_VER && !__IBMC__ etc */ 00452 #define ASN1INT64 long 00453 #define ASN1UINT64 unsigned long 00454 #define ASN1INT64FMT "%ld" 00455 #define ASN1UINT64FMT "%lu" 00456 #define ASN1INT64FMTX "%lx" 00457 #define ASN1INT64MAX LONG_MAX 00458 #define ASN1UINT64MAX ULONG_MAX 00459 #define ASN1INT64MIN LONG_MIN 00460 #define ASN1I64CONST(val) val##L 00461 #define ASN1UI64CONST(val) val##UL 00462 #endif /* MSC_VER ... */ 00463 #endif /* ASN1INT64 */ 00464 00465 typedef enum { ASN1IMPL, ASN1EXPL } ASN1TagType; 00466 typedef enum { ASN1HEX, ASN1BIN, ASN1CHR } ASN1StrType; 00467 typedef enum { ASN1ENCODE, ASN1DECODE } ASN1ActionType; 00468 00469 #ifdef __cplusplus 00470 typedef const char* ASN1ConstCharPtr; 00471 typedef const ASN1OCTET* ASN1ConstOctetPtr; 00472 typedef const void* ASN1ConstVoidPtr; 00473 typedef const ASN116BITCHAR* ASN1Const16BitCharPtr; 00474 #define ASN1Const const 00475 #else 00476 typedef char* ASN1ConstCharPtr; 00477 typedef ASN1OCTET* ASN1ConstOctetPtr; 00478 typedef void* ASN1ConstVoidPtr; 00479 typedef ASN116BITCHAR* ASN1Const16BitCharPtr; 00480 #define ASN1Const 00481 #endif 00482 00483 typedef struct { /* object identifier */ 00484 ASN1UINT numids; 00485 ASN1UINT subid[ASN_K_MAXSUBIDS]; 00486 } ASN1OBJID; 00487 00488 typedef struct { /* object identifier with 64-bit arcs */ 00489 ASN1UINT numids; 00490 ASN1UINT64 subid[ASN_K_MAXSUBIDS]; 00491 } ASN1OID64; 00492 00493 typedef union { /* double floating point (encode/decode real) */ 00494 ASN1OCTET byte[10]; 00495 ASN1USINT word[4]; 00496 double value; 00497 } ASN1_DFLOAT; 00498 00499 typedef struct { /* generic octet string structure */ 00500 ASN1UINT numocts; 00501 ASN1OCTET data[1]; 00502 } ASN1OctStr; 00503 00504 typedef struct { /* generic octet string structure (dynamic) */ 00505 ASN1UINT numocts; 00506 ASN1ConstOctetPtr data; 00507 } ASN1DynOctStr; 00508 00509 typedef struct { /* generic bit string structure (dynamic) */ 00510 ASN1UINT numbits; 00511 ASN1ConstOctetPtr data; 00512 } ASN1DynBitStr; 00513 00514 typedef struct { /* generic sequence of structure */ 00515 ASN1UINT n; 00516 void* elem; 00517 } ASN1SeqOf; 00518 00519 typedef struct { /* sequence of OCTET STRING */ 00520 ASN1UINT n; 00521 ASN1DynOctStr* elem; 00522 } ASN1SeqOfOctStr; 00523 00524 typedef struct _ASN1ListElem { /* generic linked list structure */ 00525 struct _ASN1ListElem* next; 00526 void* data_p; 00527 } ASN1ListElem; 00528 00529 typedef struct { /* generic open type data structure */ 00530 ASN1UINT numocts; 00531 ASN1ConstOctetPtr data; 00532 } ASN1OpenType; 00533 00534 typedef struct { /* generic table constraint value holder */ 00535 ASN1OpenType encoded; 00536 void* decoded; 00537 int index; /* table index */ 00538 } Asn1Object; 00539 00540 typedef Asn1Object ASN1Object; 00541 00542 /* ASN.1 useful type definitions */ 00543 00544 typedef struct { 00545 ASN1UINT nchars; 00546 ASN116BITCHAR* data; 00547 } Asn116BitCharString; 00548 00549 typedef struct { 00550 ASN1UINT nchars; 00551 ASN132BITCHAR* data; 00552 } Asn132BitCharString; 00553 00554 typedef ASN1ConstCharPtr ASN1GeneralizedTime; 00555 typedef ASN1ConstCharPtr ASN1GeneralString; 00556 typedef ASN1ConstCharPtr ASN1GraphicString; 00557 typedef ASN1ConstCharPtr ASN1IA5String; 00558 typedef ASN1ConstCharPtr ASN1ISO646String; 00559 typedef ASN1ConstCharPtr ASN1NumericString; 00560 typedef ASN1ConstCharPtr ASN1ObjectDescriptor; 00561 typedef ASN1ConstCharPtr ASN1PrintableString; 00562 typedef ASN1ConstCharPtr ASN1TeletexString; 00563 typedef ASN1ConstCharPtr ASN1T61String; 00564 typedef ASN1ConstCharPtr ASN1UTCTime; 00565 typedef ASN1ConstCharPtr ASN1UTF8String; 00566 typedef ASN1ConstCharPtr ASN1VideotexString; 00567 typedef ASN1ConstCharPtr ASN1VisibleString; 00568 00569 typedef Asn116BitCharString ASN1BMPString; 00570 typedef Asn132BitCharString ASN1UniversalString; 00571 00572 /* ASN.1 constrained string structures */ 00573 00574 typedef struct { 00575 int nchars; 00576 char data[255]; 00577 } Asn1CharArray; 00578 00579 typedef struct { 00580 Asn1CharArray charSet; 00581 ASN1ConstCharPtr canonicalSet; 00582 int canonicalSetSize; 00583 unsigned canonicalSetBits; 00584 unsigned charSetUnalignedBits; 00585 unsigned charSetAlignedBits; 00586 } Asn1CharSet; 00587 00588 typedef struct { 00589 Asn116BitCharString charSet; 00590 ASN1USINT firstChar, lastChar; 00591 unsigned unalignedBits; 00592 unsigned alignedBits; 00593 } Asn116BitCharSet; 00594 00595 typedef struct { 00596 Asn132BitCharString charSet; 00597 ASN1UINT firstChar, lastChar; 00598 unsigned unalignedBits; 00599 unsigned alignedBits; 00600 } Asn132BitCharSet; 00601 00602 /* Big Integer */ 00603 00604 typedef struct ASN1BigInt { 00605 size_t numocts; /* number of used octets in mag */ 00606 ASN1OCTET *mag; /* magnitude */ 00607 int sign; /* sign, can be -1, 0, 1 */ 00608 00609 size_t allocated; /* number of allocated octets for mag */ 00610 ASN1BOOL dynamic; /* is buffer dynamic? */ 00611 } ASN1BigInt; 00612 00613 /* Singly-linked list */ 00614 00615 typedef struct _Asn1RTSListNode { 00616 void* data; 00617 struct _Asn1RTSListNode* next; 00618 } Asn1RTSListNode; 00619 00620 struct ASN1CTXT; 00621 00622 typedef struct _Asn1RTSList { 00623 ASN1UINT count; 00624 Asn1RTSListNode* head; 00625 Asn1RTSListNode* tail; 00626 struct ASN1CTXT* pctxt; 00627 } Asn1RTSList; 00628 00629 /* Doubly-linked list */ 00630 00631 typedef struct _Asn1RTDListNode { 00632 void* data; 00633 struct _Asn1RTDListNode* next; 00634 struct _Asn1RTDListNode* prev; 00635 } Asn1RTDListNode; 00636 00637 typedef struct _Asn1RTDList { 00638 ASN1UINT count; 00639 Asn1RTDListNode* head; 00640 Asn1RTDListNode* tail; 00641 } Asn1RTDList; 00642 00643 /* Stack */ 00644 00645 typedef struct _Asn1RTStack { 00646 int level; 00647 void* data[ASN_K_MAXDEPTH]; 00648 } Asn1RTStack; 00649 00650 /* ASN.1 size constraint structure */ 00651 00652 typedef struct _Asn1SizeCnst { 00653 ASN1BOOL extended; 00654 ASN1UINT lower; 00655 ASN1UINT upper; 00656 struct _Asn1SizeCnst* next; 00657 } Asn1SizeCnst; 00658 00659 /* ASN.1 encode/decode buffer info structure */ 00660 00661 typedef struct { 00662 ASN1OCTET* data; /* pointer to start of data buffer */ 00663 size_t byteIndex; /* byte index */ 00664 size_t size; /* current buffer size */ 00665 ASN1SINT bitOffset; /* current bit offset (8 - 1) */ 00666 ASN1BOOL dynamic; /* is buffer dynamic? */ 00667 ASN1BOOL aligned; /* is buffer byte aligned? */ 00668 } ASN1BUFFER; 00669 00670 /* This structure is used to save the current state of the buffer */ 00671 00672 typedef struct { 00673 size_t byteIndex; /* byte index */ 00674 ASN1SINT bitOffset; /* current bit offset (8 - 1) */ 00675 ASN1USINT flags; /* flag bits */ 00676 } ASN1BUFSAVE; 00677 00678 /* ASN.1 context control block - this structure is used to keep track */ 00679 /* of pointer and length context values when decoding sets or sequence */ 00680 /* of constructs. */ 00681 00682 #define ASN1_K_CCBMaskSize 32 00683 #define ASN1_K_NumBitsPerMask 16 00684 #define ASN1_K_MaxSetElements (ASN1_K_CCBMaskSize*ASN1_K_NumBitsPerMask) 00685 00686 typedef struct { /* context control block */ 00687 ASN1OCTET* ptr; /* constructor pointer */ 00688 long len; /* constructor length */ 00689 int seqx; /* sequence element index */ 00690 unsigned short mask[ASN1_K_CCBMaskSize]; /* set mask value */ 00691 size_t bytes; /* bytes processed before block (for stream) */ 00692 int stat; /* status, returned by BS_CHKEND */ 00693 } ASN1CCB; 00694 00695 /* ASN.1 run-time error info structures */ 00696 00697 typedef struct { 00698 ASN1ConstCharPtr module; 00699 int lineno; 00700 } ASN1ErrLocn; 00701 00702 typedef struct { 00703 ASN1ErrLocn stack[ASN_K_MAXERRSTK]; 00704 int stkx; 00705 int status; 00706 int parmcnt; 00707 ASN1ConstCharPtr parms[ASN_K_MAXERRP]; 00708 } ASN1ErrInfo; 00709 00710 #define XM_K_MEMBLKSIZ (4*1024) 00711 00712 /* Flag mask constant values */ 00713 00714 #define ASN1DYNCTXT 0x8000 00715 #define ASN1INDEFLEN 0x4000 00716 #define ASN1TRACE 0x2000 00717 #define ASN1LASTEOC 0x1000 00718 #define ASN1FASTCOPY 0x0800 /* turns on the "fast copy" mode */ 00719 #define ASN1CONSTAG 0x0400 /* form of last parsed tag */ 00720 #define ASN1CANXER 0x0200 /* canonical XER */ 00721 #define ASN1SAVEBUF 0x0100 /* do not free dynamic encode buffer */ 00722 #define ASN1OPENTYPE 0x0080 /* item is an open type field */ 00723 00724 /* ASN.1 encode/decode context block structure */ 00725 00726 typedef struct ASN1CTXT { /* ASN.1 context block */ 00727 void* pMsgMemHeap; /* internal message memory heap */ 00728 void* pTypeMemHeap; /* memory heap */ 00729 ASN1BUFFER buffer; /* data buffer */ 00730 struct OSRTStream* pStream; /* Stream */ 00731 struct OSRTPrintStream *pPrintStrm; /* Print Stream */ 00732 ASN1BUFSAVE savedInfo; /* saved buffer info */ 00733 ASN1ErrInfo errInfo; /* run-time error info */ 00734 Asn1RTSList fieldList; /* PER field list */ 00735 Asn1SizeCnst* pSizeConstraint; /* Size constraint list */ 00736 ASN1ConstCharPtr pCharSet; /* String of permitted characters */ 00737 Asn1RTStack nameStack; /* Element name stack */ 00738 Asn1RTSList evtHndlrList; /* Event handler object list */ 00739 void* errHndlrCB; /* Error handler callback function */ 00740 ASN1UINT initCode; /* code double word to indicate init */ 00741 ASN1USINT flags; /* flag bits */ 00742 ASN1OCTET level; /* nesting level */ 00743 ASN1OCTET xerState; /* XER state */ 00744 jmp_buf jmpMark; /* Jump buff for setjmp/longjmp (XER C) */ 00745 const ASN1OCTET* key; /* pointer to run-time key data */ 00746 size_t keylen; /* run-time key length */ 00747 } ASN1CTXT; 00748 00749 #define OSRTISSTREAM(pctxt) ((pctxt)->pStream != 0) 00750 00751 /* ASN.1 memory buffer */ 00752 00753 typedef struct ASN1MemBuf { 00754 ASN1CTXT* pctxt; 00755 ASN1UINT segsize; /* segment size */ 00756 ASN1UINT startidx; /* start index of useful info */ 00757 ASN1UINT usedcnt; /* used byte count */ 00758 ASN1UINT bufsize; /* buffer size */ 00759 ASN1UINT bitOffset; /* bit offset */ 00760 ASN1UINT userState ; /* user state - any value, 0 is initial */ 00761 ASN1OCTET* buffer; /* memory buffer */ 00762 ASN1BOOL isDynamic; /* is buffer allocated dynamically? */ 00763 ASN1BOOL isExpandable; /* is buffer expandable? */ 00764 } ASN1MemBuf; 00765 00766 /* Date & Time structure */ 00767 #define OSDT_MAXSECFRAC 20 00768 typedef struct _OSDATETIME { 00769 short mYear; 00770 short mMonth; /* 1 - Jan, ... 12 - Dec */ 00771 short mDay; /* day of month, 1..31 (or 28,29,30) */ 00772 short mHour; /* 0..23 */ 00773 short mMinute; /* 0..59 */ 00774 short mSecond; /* 0..59 */ 00775 short mDiffHour; /* -12 .. +12 */ 00776 short mDiffMin; /* -59 .. 0 .. +59 */ 00777 char mSecondFrac[OSDT_MAXSECFRAC + 1]; /* > 0.000 */ 00778 ASN1BOOL mUtcFlag; /* is Z flag present or not */ 00779 } OSDATETIME; 00780 00781 #define ASN1MEMBUFPTR(pmb) ((pmb)->buffer + (pmb)->startidx) 00782 #define ASN1MEMBUFENDPTR(pmb) ((pmb)->buffer + (pmb)->startidx + (pmb)->usedcnt) 00783 #define ASN1MEMBUFUSEDSIZE(pmb) ((size_t)(pmb)->usedcnt) 00784 00785 #define ASN1MBAPPENDSTR(pmb,str) \ 00786 rtMemBufAppend(pmb,(ASN1OCTET*)str,strlen(str)) 00787 00788 #define ASN1MBAPPENDUTF8(pmb,str) \ 00789 rtMemBufAppend(pmb,(ASN1OCTET*)str,rtxUTF8LenBytes(str)) 00790 00791 /* ASN.1 dump utility callback function definition */ 00792 00793 typedef int (*ASN1DumpCbFunc) (ASN1ConstCharPtr text_p, void* cbArg_p); 00794 00795 /* ASNLIB function macros and prototypes */ 00796 00797 #ifndef ASN1MAX 00798 #define ASN1MAX(a,b) (((a)>(b))?(a):(b)) 00799 #endif 00800 00801 #ifndef ASN1MIN 00802 #define ASN1MIN(a,b) (((a)<(b))?(a):(b)) 00803 #endif 00804 00805 #if defined (ACVERSION) && ACVERSION <= 530 00806 #define MIN ASN1MIN 00807 #define MAX ASN1MAX 00808 #endif 00809 00829 #define ALLOC_ASN1ARRAY(pctxt,pseqof,type) do {\ 00830 if (sizeof(type)*(pseqof)->n < (pseqof)->n) return ASN_E_NOMEM; \ 00831 if (((pseqof)->elem = (type*) rtMemHeapAlloc \ 00832 (&(pctxt)->pTypeMemHeap, sizeof(type)*(pseqof)->n)) == 0) return ASN_E_NOMEM; \ 00833 } while (0) 00834 00847 #define ALLOC_ASN1ARRAY1(pctxt,pseqof,type) do {\ 00848 if (sizeof(type)*(pseqof)->n < (pseqof)->n) (pseqof)->elem = 0; \ 00849 else (pseqof)->elem = (type*) rtMemHeapAlloc \ 00850 (&(pctxt)->pTypeMemHeap, sizeof(type)*(pseqof)->n); \ 00851 } while (0) 00852 00862 #define ALLOC_ASN1ARRAY2(pctxt,n,type) \ 00863 ((type*) ((sizeof(type)*n < n) ? 0 : \ 00864 rtMemHeapAlloc (&(pctxt)->pTypeMemHeap, sizeof(type)*n))) 00865 00873 #define ALLOC_ASN1ELEM(pctxt,type) \ 00874 (type*) rtMemHeapAllocZ (&(pctxt)->pTypeMemHeap, sizeof(type)) 00875 00876 #define ALLOC_ASN1ELEMDNODE(pctxt,type) \ 00877 (type*) (((char*)rtMemHeapAllocZ (&(pctxt)->pTypeMemHeap, sizeof(type) + \ 00878 sizeof(Asn1RTDListNode))) + sizeof(Asn1RTDListNode)) 00879 00880 #define ALLOC_ASN1ELEMSNODE(pctxt,type) \ 00881 (type*) (((char*)rtMemHeapAllocZ (&(pctxt)->pTypeMemHeap, sizeof(type) + \ 00882 sizeof(Asn1RTSListNode))) + sizeof(Asn1RTSListNode)) 00883 00889 #define ASN1ARRAYSIZE(x) (sizeof(x)/sizeof(x[0])) 00890 00901 #define ASN1MALLOC(pctxt,nbytes) \ 00902 rtMemHeapAlloc(&(pctxt)->pTypeMemHeap, nbytes) 00903 00921 #define ASN1REALLOC(pctxt,pmem,nbytes) \ 00922 rtMemHeapRealloc(&(pctxt)->pTypeMemHeap, pmem, nbytes) 00923 00935 #define REALLOC_ASN1ARRAY(pctxt,pseqof,type) do {\ 00936 if (sizeof(type)*(pseqof)->n < (pseqof)->n) return ASN_E_NOMEM; \ 00937 if (((pseqof)->elem = (type*) rtMemHeapRealloc \ 00938 (&(pctxt)->pTypeMemHeap, (pseqof)->elem, sizeof(type)*(pseqof)->n)) == 0) \ 00939 return ASN_E_NOMEM; \ 00940 } while (0) 00941 00950 #define ASN1MEMFREE(pctxt) \ 00951 rtMemHeapFreeAll(&(pctxt)->pTypeMemHeap) 00952 00964 #define ASN1MEMFREEPTR(pctxt,pmem) \ 00965 rtMemHeapFreePtr(&(pctxt)->pTypeMemHeap, (void*)pmem) 00966 00980 #define ASN1MEMRESET(pctxt) \ 00981 rtMemHeapReset(&(pctxt)->pTypeMemHeap) 00982 00985 #define ASN1BUFCUR(cp) (cp)->buffer.data[(cp)->buffer.byteIndex] 00986 #define ASN1BUFPTR(cp) &(cp)->buffer.data[(cp)->buffer.byteIndex] 00987 #define ASN1BUF_INDEFLEN(cp) (((cp)->flags&ASN1INDEFLEN)!=0) 00988 #define ASN1BUF_PTR(cp) ASN1BUFPTR(cp) 00989 00990 #define ASN1NUMOCTS(nbits) ((nbits>0)?(((nbits-1)/8)+1):0) 00991 00992 #ifdef _TRACE 00993 #define RTDIAG1(msg) rtdiag(msg) 00994 #define RTDIAG2(msg,a) rtdiag(msg,a) 00995 #define RTDIAG3(msg,a,b) rtdiag(msg,a,b) 00996 #define RTDIAG4(msg,a,b,c) rtdiag(msg,a,b,c) 00997 #define RTDIAG5(msg,a,b,c,d) rtdiag(msg,a,b,c,d) 00998 #define RTDIAG6(msg,a,b,c,d,e) rtdiag(msg,a,b,c,d,e) 00999 #define RTDIAG7(msg,a,b,c,d,e,f) rtdiag(msg,a,b,c,d,e,f) 01000 #define RTDIAG8(msg,a,b,c,d,e,f,g) rtdiag(msg,a,b,c,d,e,f,g) 01001 #define RTDIAG9(msg,a,b,c,d,e,f,g,h) rtdiag(msg,a,b,c,d,e,f,g,h) 01002 #define RTDIAG10(msg,a,b,c,d,e,f,g,h,i) rtdiag(msg,a,b,c,d,e,f,g,h,i) 01003 #define RTHEXDUMP(buffer,numocts) rtDiagHexDump(buffer,numocts) 01004 /* Diagnosis macros printing out to string */ 01005 #define RTDIAGSTRM2(pctxt,msg) rtDiagStream(pctxt,msg) 01006 #define RTDIAGSTRM3(pctxt,msg, a) rtDiagStream(pctxt,msg,a) 01007 #define RTDIAGSTRM4(pctxt,msg,a,b) rtDiagStream(pctxt,msg,a,b) 01008 #define RTDIAGSTRM5(pctxt,msg,a,b,c) \ 01009 rtDiagStream(pctxt,msg,a,b,c) 01010 #define RTDIAGSTRM6(pctxt,msg,a,b,c,d) \ 01011 rtDiagStream(pctxt,msg,a,b,c,d) 01012 #define RTDIAGSTRM7(pctxt,msg,a,b,c,d,e) \ 01013 rtDiagStream(pctxt,msg,a,b,c,d,e) 01014 #define RTDIAGSTRM8(pctxt,msg,a,b,c,d,e,f) \ 01015 rtDiagStream(pctxt,msg,a,b,c,d,e,f) 01016 #define RTDIAGSTRM9(pctxt,msg,a,b,c,d,e,f,g) \ 01017 rtDiagStream(pctxt,msg,a,b,c,d,e,f,g) 01018 #define RTDIAGSTRM10(pctxt,msg,a,b,c,d,e,f,g,h) \ 01019 rtDiagStream(pctxt,msg,a,b,c,d,e,f,g,h) 01020 #define RTDIAGSTRM11(pctxt,msg,a,b,c,d,e,f,g,h,i) \ 01021 rtDiagStream(pctxt,msg,a,b,c,d,e,f,g,h,i) 01022 #define RTHEXDUMPSTRM(pctxt,buffer,numocts) \ 01023 rtDiagStreamHexDump(pctxt,buffer,numocts) 01024 #else 01025 #define RTDIAG1(msg) 01026 #define RTDIAG2(msg,a) 01027 #define RTDIAG3(msg,a,b) 01028 #define RTDIAG4(msg,a,b,c) 01029 #define RTDIAG5(msg,a,b,c,d) 01030 #define RTDIAG6(msg,a,b,c,d,e) 01031 #define RTDIAG7(msg,a,b,c,d,e,f) 01032 #define RTDIAG8(msg,a,b,c,d,e,f,g) 01033 #define RTDIAG9(msg,a,b,c,d,e,f,g,h) 01034 #define RTDIAG10(msg,a,b,c,d,e,f,g,h,i) 01035 #define RTHEXDUMP(buffer,numocts) 01036 01037 #define RTDIAGSTRM2(pctxt,msg) 01038 #define RTDIAGSTRM3(pctxt,msg, a) 01039 #define RTDIAGSTRM4(pctxt,msg,a,b) 01040 #define RTDIAGSTRM5(pctxt,msg,a,b,c) 01041 #define RTDIAGSTRM6(pctxt,msg,a,b,c,d) 01042 #define RTDIAGSTRM7(pctxt,msg,a,b,c,d,e) 01043 #define RTDIAGSTRM8(pctxt,msg,a,b,c,d,e,f) 01044 #define RTDIAGSTRM9(pctxt,msg,a,b,c,d,e,f,g) 01045 #define RTDIAGSTRM10(pctxt,msg,a,b,c,d,e,f,g,h) 01046 #define RTDIAGSTRM11(pctxt,msg,a,b,c,d,e,f,g,h,i) 01047 #define RTHEXDUMPSTRM(pctxt,buffer,numocts) 01048 #endif 01049 01050 #define HEXCHARTONIBBLE(ch,b) \ 01051 if (ch >= '0' && ch <= '9') b = (unsigned char)(ch - '0'); \ 01052 else if (ch >= 'a' && ch <= 'f') b = (unsigned char)((ch - 'a') + 10); \ 01053 else if (ch >= 'A' && ch <= 'F') b = (unsigned char)((ch - 'A') + 10); \ 01054 else b = 0xFF; 01055 01056 #define NIBBLETOHEXCHAR(b,ch) \ 01057 if (b >= 0 && b <= 9) ch = (char)(b + '0'); \ 01058 else if (b >= 0x0a && b <= 0x0f) ch = (char)((b - 10)+ 'a'); \ 01059 else ch = '?'; 01060 01061 #ifdef __cplusplus 01062 #define EXTERN_C extern "C" 01063 extern "C" { 01064 #else 01065 #define EXTERN_C extern 01066 #endif 01067 01068 #ifndef EXTERN 01069 #ifdef ASN1DLL 01070 #define EXTERN __declspec(dllexport) 01071 #elif defined (USEASN1DLL) 01072 #define EXTERN __declspec(dllimport) 01073 #else 01074 #define EXTERN 01075 #endif /* ASN1DLL */ 01076 #endif /* EXTERN */ 01077 01078 #ifndef EXTERNRT 01079 #ifdef BUILDASN1RTDLL 01080 #define EXTERNRT __declspec(dllexport) 01081 #elif defined (USEASN1RTDLL) 01082 #define EXTERNRT __declspec(dllimport) 01083 #else 01084 #define EXTERNRT 01085 #endif /* BUILDASN1RTDLL */ 01086 #endif /* EXTERNRT */ 01087 01088 #ifndef _NO_MALLOC 01089 #define ASN1CRTMALLOC0(nbytes) malloc(nbytes) 01090 #define ASN1CRTFREE0(ptr) free(ptr) 01091 #else 01092 01093 #ifdef _NO_THREADS 01094 extern EXTERNRT ASN1CTXT g_ctxt; 01095 01096 #define ASN1CRTMALLOC0(nbytes) rtMemAlloc(&g_ctxt,(nbytes)) 01097 #define ASN1CRTFREE0(ptr) rtMemFreePtr(&g_ctxt,(ptr)) 01098 #else 01099 #define ASN1CRTMALLOC0(nbytes) (void*)0 01100 #define ASN1CRTFREE0(ptr) (void*)0 01101 01102 #endif /* _NO_THREADS */ 01103 #endif /* _NO_MALLOC */ 01104 01105 #define ASN1CRTMALLOC ASN1MALLOC 01106 #define ASN1CRTFREE ASN1MEMFREEPTR 01107 01108 /* run-time error and diagnostic functions */ 01109 01110 extern int g_debug; 01111 01112 EXTERNRT long rtBase64EncodeData (ASN1CTXT* pctxt, ASN1ConstOctetPtr pSrcData, 01113 size_t srcDataSize, ASN1OCTET** ppDstData); 01114 01115 EXTERNRT long rtBase64DecodeData (ASN1CTXT* pctxt, ASN1ConstOctetPtr pSrcData, 01116 size_t srcDataSize, ASN1OCTET** ppDstData); 01117 01118 EXTERNRT int rtCheckBuffer (ASN1CTXT* pctxt, size_t nbytes); 01119 01120 EXTERNRT void rtCopyContext (ASN1CTXT* pdest, ASN1CTXT* psrc); 01121 EXTERNRT void rtXchgContext (ASN1CTXT* pdest, ASN1CTXT* psrc); 01122 EXTERNRT void rtCtxtSetFlag (ASN1CTXT* pctxt, ASN1USINT mask); 01123 EXTERNRT void rtCtxtClearFlag (ASN1CTXT* pctxt, ASN1USINT mask); 01124 01125 /* Context management functions */ 01126 01162 EXTERNRT int rtInitContextBuffer (ASN1CTXT* ctxt_p, 01163 ASN1ConstOctetPtr bufaddr, 01164 size_t bufsiz); 01165 01180 EXTERNRT int rtInitContextUsingKey 01181 (ASN1CTXT* ctxt_p, const ASN1OCTET* key, size_t keylen); 01182 01192 #ifndef rtInitContext 01193 EXTERNRT int rtInitContext (ASN1CTXT* pctxt); 01194 #endif 01195 EXTERNRT int rtInitSubContext (ASN1CTXT* ctxt_p, ASN1CTXT* psrc); 01196 EXTERNRT int rtPreInitContext (ASN1CTXT* ctxt_p); 01197 01216 EXTERNRT ASN1CTXT* rtNewContextUsingKey (const ASN1OCTET* key, size_t keylen); 01217 01226 EXTERNRT void rtFreeContext (ASN1CTXT* ctxt_p); 01227 01228 EXTERNRT int rtReadNextByte (ASN1CTXT* pCtxt); 01229 01233 EXTERNRT void rtSetCopyValues (ASN1CTXT* ctxt_p, ASN1BOOL value); 01234 01248 EXTERNRT void rtSetFastCopy (ASN1CTXT* ctxt_p, ASN1BOOL value); 01249 01278 EXTERNRT Asn1RTDListNode* rtDListAppend (ASN1CTXT* ctxt_p, 01279 Asn1RTDList* pList, void* pData); 01280 01296 EXTERNRT void rtDListInit (Asn1RTDList* pList); 01297 01317 EXTERNRT Asn1RTDListNode* rtDListInsert (ASN1CTXT* ctxt_p, 01318 Asn1RTDList* pList, 01319 int index, void* pData); 01320 01342 EXTERNRT Asn1RTDListNode* rtDListInsertBefore (ASN1CTXT* ctxt_p, 01343 Asn1RTDList* pList, 01344 Asn1RTDListNode* node, 01345 void* pData); 01346 01368 EXTERNRT Asn1RTDListNode* rtDListInsertAfter (ASN1CTXT* ctxt_p, 01369 Asn1RTDList* pList, 01370 Asn1RTDListNode* node, 01371 void* pData); 01372 01383 EXTERNRT Asn1RTDListNode* rtDListFindByIndex (Asn1RTDList* pList, int index); 01384 01396 EXTERNRT Asn1RTDListNode* rtDListFindByData (Asn1RTDList* pList, void* data); 01397 01410 EXTERNRT int rtDListFindIndexByData (Asn1RTDList* pList, void* data); 01411 01424 EXTERNRT void rtDListRemove (Asn1RTDList* pList, Asn1RTDListNode* node); 01425 01439 EXTERNRT void rtDListFreeNodes (ASN1CTXT* ctxt_p, Asn1RTDList* pList); 01440 01457 EXTERNRT void rtDListFreeAll (ASN1CTXT* ctxt_p, Asn1RTDList* pList); 01458 01480 EXTERNRT int rtDListToArray (ASN1CTXT* ctxt_p, Asn1RTDList* pList, 01481 void** ppArray, ASN1UINT* pElements, 01482 int elemSize); 01483 01503 EXTERNRT int rtDListAppendArray (ASN1CTXT* ctxt_p, Asn1RTDList* pList, 01504 ASN1ConstVoidPtr pArray, 01505 ASN1UINT numElements, int elemSize); 01506 01526 EXTERNRT int rtDListAppendArrayCopy (ASN1CTXT* ctxt_p, Asn1RTDList* pList, 01527 ASN1ConstVoidPtr pArray, 01528 ASN1UINT numElements, int elemSize); 01529 01530 /* 01531 * This function appends an item to a linked list structure. In cotrast to 01532 * rtDListAppend, this function does not allocate the memory for the node 01533 * strcture. The memory for node structure is taken by subtracting 01534 * sizeof(Asn1RTDListNode) from the pData pointer. Thus, the memory for the 01535 * data should be allocated using ALLOC_ASN1ELEMDNODE macro. This function 01536 * works faster than rtDListAppend because one memory allocation is used. 01537 * 01538 * @param ctxt_p A pointer to a context structure. This provides a 01539 * storage area for the function to store all working 01540 * variables that must be maintained between function 01541 * calls. 01542 * @param pList A pointer to a linked list structure onto which the data 01543 * item is to be appended. A pointer to the updated 01544 * linked list structure. 01545 * @param pData A pointer to the data item to be appended to the list. 01546 * @return A pointer to the allocated node used to link the given 01547 * data value into the list. 01548 */ 01549 EXTERNRT Asn1RTDListNode* rtDListAppendNode (ASN1CTXT* ctxt_p, 01550 Asn1RTDList* pList, void* pData); 01576 EXTERNRT void rtdiag (ASN1ConstCharPtr fmtspec, ...); 01577 01591 EXTERNRT void rtDiagStream(ASN1CTXT *pctxt, ASN1ConstCharPtr fmtspec, ...); 01592 01593 EXTERNRT void rtDiagStreamHexDump (ASN1CTXT *pctxt, ASN1ConstOctetPtr data, 01594 ASN1UINT numocts); 01595 01596 EXTERNRT void rtDiagHexDump (ASN1ConstOctetPtr data, ASN1UINT numocts); 01597 01604 EXTERNRT void rtSetDiag (int value); 01605 01616 EXTERNRT void rtHexDump (ASN1ConstOctetPtr data, ASN1UINT numocts); 01617 01628 EXTERNRT void rtHexDumpEx (ASN1ConstOctetPtr data, ASN1UINT numocts, 01629 int bytesPerUnit); 01630 01640 EXTERNRT void rtHexDumpToFile (FILE* fp, ASN1ConstOctetPtr data, 01641 ASN1UINT numocts); 01642 01654 EXTERNRT void rtHexDumpToFileEx (FILE* fp, ASN1ConstOctetPtr data, 01655 ASN1UINT numocts, int bytesPerUnit); 01656 01669 EXTERNRT int rtHexDumpToString (ASN1ConstOctetPtr data, ASN1UINT numocts, 01670 char* buffer, 01671 int bufferIndex, int bufferSize); 01672 01688 EXTERNRT int rtHexDumpToStringEx (ASN1ConstOctetPtr data, ASN1UINT numocts, 01689 char* buffer, int bufferIndex, 01690 int bufferSize, int bytesPerUnit); 01691 01701 EXTERNRT void rtHexDumpToStream (ASN1CTXT* pctxt, ASN1ConstOctetPtr data, 01702 ASN1UINT numocts); 01703 01716 EXTERNRT void rtHexDumpToStreamEx (ASN1CTXT* pctxt, ASN1ConstOctetPtr data, 01717 ASN1UINT numocts, int bytesPerUnit); 01718 01747 EXTERNRT int rtErrAddIntParm (ASN1ErrInfo* pErrInfo, int errParm); 01748 01763 EXTERNRT int rtErrAddStrParm (ASN1ErrInfo* pErrInfo, 01764 ASN1ConstCharPtr errprm_p); 01765 01780 EXTERNRT int rtErrAddTagParm (ASN1ErrInfo* pErrInfo, ASN1TAG errParm); 01781 01796 EXTERNRT int rtErrAddUIntParm (ASN1ErrInfo* pErrInfo, unsigned int errParm); 01797 01798 01799 EXTERNRT int rtErrCopyData (ASN1ErrInfo* pSrcErrInfo, 01800 ASN1ErrInfo* pDestErrInfo); 01801 01815 EXTERNRT void rtErrFreeParms (ASN1ErrInfo* pErrInfo); 01816 01817 01818 EXTERNRT char* rtErrFmtMsg (ASN1ErrInfo* pErrInfo, char* bufp); 01819 01825 EXTERNRT char* rtErrGetText (ASN1CTXT* ctxt_p); 01826 01853 EXTERNRT void rtErrLogUsingCB (ASN1ErrInfo* pErrInfo, 01854 ASN1DumpCbFunc cb, void* cbArg); 01855 01868 EXTERNRT void rtErrPrint (ASN1ErrInfo* pErrInfo); 01869 01879 EXTERNRT int rtErrReset (ASN1ErrInfo* pErrInfo); 01880 01904 EXTERNRT int rtErrSetData (ASN1ErrInfo* pErrInfo, int status, 01905 ASN1ConstCharPtr module, int lno); 01906 01912 EXTERNRT int rtGetIdentByteCount (ASN1UINT ident); 01913 EXTERNRT int rtGetIdent64ByteCount (ASN1UINT64 ident); 01914 01915 EXTERNRT unsigned int rtIntByteCount (ASN1INT val); 01916 EXTERNRT int rtOctetBitLen (ASN1OCTET w); 01917 01943 EXTERNRT void rtMemBufInit (ASN1CTXT* pCtxt, ASN1MemBuf* pMemBuf, 01944 ASN1UINT segsize); 01945 01963 EXTERNRT void rtMemBufInitBuffer (ASN1CTXT* pCtxt, ASN1MemBuf* pMemBuf, 01964 ASN1OCTET* buf, ASN1UINT bufsize, 01965 ASN1UINT segsize); 01966 01974 EXTERNRT void rtMemBufFree (ASN1MemBuf* pMemBuf); 01975 01990 EXTERNRT int rtMemBufAppend (ASN1MemBuf* pMemBuf, 01991 ASN1OCTET* pdata, ASN1UINT nbytes); 01992 02007 EXTERNRT int rtMemBufCut (ASN1MemBuf* pMemBuf, 02008 ASN1UINT fromOffset, ASN1UINT nbytes); 02009 02016 EXTERNRT void rtMemBufReset (ASN1MemBuf* pMemBuf); 02017 02023 EXTERNRT int rtMemBufTrimW (ASN1MemBuf* pMemBuf); 02024 02040 EXTERNRT int rtMemBufSet (ASN1MemBuf* pMemBuf, 02041 ASN1OCTET value, ASN1UINT nbytes); 02042 02051 EXTERNRT ASN1OCTET* rtMemBufGetData (ASN1MemBuf* pMemBuf, int* length); 02052 02059 EXTERNRT int rtMemBufGetDataLen (ASN1MemBuf* pMemBuf); 02060 02070 EXTERNRT int rtMemBufPreAllocate (ASN1MemBuf* pMemBuf, ASN1UINT nbytes); 02071 02083 EXTERNRT ASN1BOOL rtMemBufSetExpandable 02084 (ASN1MemBuf* pMemBuf, ASN1BOOL isExpandable); 02085 02113 EXTERNRT void rtSetOID (ASN1OBJID* ptarget, ASN1OBJID* psource); 02114 02130 EXTERNRT void rtAddOID (ASN1OBJID* ptarget, ASN1OBJID* psource); 02131 02132 02152 EXTERNRT int rtSetBit (ASN1OCTET* pBits, int numbits, int bitIndex); 02153 02154 #define OSSETBIT(bitStr,bitIndex) \ 02155 rtSetBit (bitStr.data, bitStr.numbits, bitIndex) 02156 02157 #define OSSETBITP(pBitStr,bitIndex) \ 02158 rtSetBit ((pBitStr)->data, (pBitStr)->numbits, bitIndex) 02159 02174 EXTERNRT int rtClearBit (ASN1OCTET* pBits, int numbits, int bitIndex); 02175 02176 #define OSCLEARBIT(bitStr,bitIndex) \ 02177 rtClearBit (bitStr.data, bitStr.numbits, bitIndex) 02178 02179 #define OSCLEARBITP(pBitStr,bitIndex) \ 02180 rtClearBit ((pBitStr)->data, (pBitStr)->numbits, bitIndex) 02181 02192 EXTERNRT ASN1BOOL rtTestBit (ASN1ConstOctetPtr pBits, 02193 int numbits, int bitIndex); 02194 02195 #define OSTESTBIT(bitStr,bitIndex) \ 02196 rtTestBit (bitStr.data, bitStr.numbits, bitIndex) 02197 02198 #define OSTESTBITP(pBitStr,bitIndex) \ 02199 rtTestBit ((pBitStr)->data, (pBitStr)->numbits, bitIndex) 02200 02226 EXTERNRT void rtSListInit (Asn1RTSList* pList); 02227 02239 EXTERNRT void rtSListInitEx (ASN1CTXT* pctxt, Asn1RTSList* pList); 02240 02249 EXTERNRT void rtSListFree (Asn1RTSList* pList); 02250 02257 EXTERNRT Asn1RTSList* rtSListCreate (void); 02258 02270 EXTERNRT Asn1RTSList* rtSListCreateEx (ASN1CTXT* pctxt); 02271 02282 EXTERNRT Asn1RTSListNode* rtSListAppend (Asn1RTSList* pList, void* pData); 02283 02295 EXTERNRT ASN1BOOL rtSListFind (Asn1RTSList* pList, void* pData); 02296 02306 EXTERNRT void rtSListRemove (Asn1RTSList* pList, void* pData); 02307 02314 EXTERNRT Asn1RTStack* rtStackCreate (void); 02315 02323 EXTERNRT Asn1RTStack* rtStackCreateEx (ASN1CTXT* pctxt); 02324 02331 EXTERNRT void rtStackInit (Asn1RTStack* pStack); 02332 02341 EXTERNRT void* rtStackPop (Asn1RTStack* pStack); 02342 02354 EXTERNRT int rtStackPush (Asn1RTStack* pStack, void* pData); 02355 02356 02362 EXTERNRT int rtWriteBytes (ASN1CTXT* pctxt, 02363 ASN1ConstOctetPtr pdata, size_t nocts); 02364 02381 EXTERNRT ASN1REAL rtGetPlusInfinity (void); 02382 02390 EXTERNRT ASN1REAL rtGetMinusInfinity (void); 02391 02392 EXTERNRT ASN1REAL rtGetMinusZero (void); 02393 EXTERNRT ASN1REAL rtGetNaN (void); 02394 EXTERNRT ASN1BOOL rtIsMinusInfinity (ASN1REAL value); 02395 EXTERNRT ASN1BOOL rtIsMinusZero (ASN1REAL value); 02396 EXTERNRT ASN1BOOL rtIsNaN (ASN1REAL value); 02397 EXTERNRT ASN1BOOL rtIsPlusInfinity (ASN1REAL value); 02398 02402 /* run-time print functions */ 02403 02404 02427 EXTERNRT ASN1ConstCharPtr rtBitStrToString (ASN1UINT numbits, 02428 ASN1ConstOctetPtr data, 02429 char* buffer, size_t bufsiz); 02430 02439 EXTERNRT ASN1ConstCharPtr rtBoolToString (ASN1BOOL value); 02440 02451 EXTERNRT ASN1ConstCharPtr rtIntToString (ASN1INT value, 02452 char* buffer, size_t bufsiz); 02453 02464 EXTERNRT ASN1ConstCharPtr rtInt64ToString (ASN1INT64 value, 02465 char* buffer, size_t bufsiz); 02466 02479 EXTERNRT ASN1ConstCharPtr rtUIntToString 02480 (ASN1UINT value, char* buffer, size_t bufsiz); 02481 02492 EXTERNRT ASN1ConstCharPtr rtUInt64ToString 02493 (ASN1UINT64 value, char* buffer, size_t bufsiz); 02494 02511 EXTERNRT ASN1ConstCharPtr rtOIDToString (ASN1UINT numids, ASN1UINT* data, 02512 char* buffer, size_t bufsiz); 02513 02530 EXTERNRT ASN1ConstCharPtr rtOID64ToString (ASN1UINT numids, ASN1UINT64* data, 02531 char* buffer, size_t bufsiz); 02532 02547 EXTERNRT ASN1ConstCharPtr rtOctStrToString (ASN1UINT numocts, 02548 ASN1ConstOctetPtr data, 02549 char* buffer, size_t bufsiz); 02550 02563 EXTERNRT ASN1ConstCharPtr rtTagToString (ASN1TAG tag, char* buffer, 02564 size_t bufsiz); 02565 02566 02597 EXTERNRT ASN1ConstCharPtr rtBCDToString (ASN1UINT numocts, 02598 ASN1ConstOctetPtr data, 02599 char* buffer, size_t bufsiz); 02600 02612 EXTERNRT size_t rtStringToBCD 02613 (ASN1ConstCharPtr str, ASN1OCTET* bcdStr, size_t bufsiz); 02614 02627 /* 16-bit character functions */ 02628 02639 EXTERNRT ASN1ConstCharPtr rtBMPToCString (ASN1BMPString* pBMPString, 02640 char* cstring, ASN1UINT cstrsize); 02641 02652 EXTERNRT ASN1ConstCharPtr rtBMPToNewCString (ASN1BMPString* pBMPString); 02653 02667 EXTERNRT ASN1ConstCharPtr rtBMPToNewCStringEx 02668 (ASN1CTXT *pctxt, ASN1BMPString* pBMPString); 02669 02685 EXTERNRT ASN1BMPString* rtCToBMPString (ASN1CTXT* ctxt_p, 02686 ASN1ConstCharPtr cstring, 02687 ASN1BMPString* pBMPString, 02688 Asn116BitCharSet* pCharSet); 02689 02690 EXTERNRT ASN1BOOL rtIsIn16BitCharSet (ASN116BITCHAR ch, 02691 Asn116BitCharSet* pCharSet); 02692 02693 /* 32-bit character (UCS-4) functions */ 02694 02695 02707 EXTERNRT ASN1ConstCharPtr rtUCSToCString (ASN1UniversalString* pUCSString, 02708 char* cstring, ASN1UINT cstrsize); 02709 02722 EXTERNRT ASN1ConstCharPtr rtUCSToNewCString (ASN1UniversalString* pUCSString); 02723 02738 EXTERNRT ASN1ConstCharPtr rtUCSToNewCStringEx 02739 (ASN1CTXT* pctxt, ASN1UniversalString* pUCSString); 02740 02756 EXTERNRT ASN1UniversalString* rtCToUCSString (ASN1CTXT* ctxt_p, 02757 ASN1ConstCharPtr cstring, 02758 ASN1UniversalString* pUCSString, 02759 Asn132BitCharSet* pCharSet); 02760 02761 02762 EXTERNRT ASN1BOOL rtIsIn32BitCharSet (ASN132BITCHAR ch, 02763 Asn132BitCharSet* pCharSet); 02764 02765 02778 EXTERNRT wchar_t* rtUCSToWCSString (ASN1UniversalString* pUCSString, 02779 wchar_t* wcstring, ASN1UINT wcstrsize); 02780 02781 02799 EXTERNRT ASN1UniversalString* rtWCSToUCSString 02800 (ASN1CTXT* ctxt_p, wchar_t* wcstring, 02801 ASN1UniversalString* pUCSString, Asn132BitCharSet* pCharSet); 02802 02803 02804 /* UTF-8 functions */ 02805 02818 EXTERNRT int rtUTF8ToWCS (ASN1CTXT* pCtxt, ASN1UTF8String inbuf, 02819 wchar_t* outbuf, size_t outbufsiz); 02820 02836 EXTERNRT long rtWCSToUTF8 (ASN1CTXT* pCtxt, wchar_t* inbuf, size_t inlen, 02837 ASN1OCTET* outbuf, size_t outbufsiz); 02838 02849 EXTERNRT int rtValidateUTF8 (ASN1CTXT* pCtxt, ASN1UTF8String inbuf); 02850 02860 EXTERNRT int rtUTF8Len (ASN1UTF8String inbuf); 02861 02869 EXTERNRT int rtUTF8LenBytes (ASN1UTF8String inbuf); 02870 02878 EXTERNRT int rtUTF8CharSize (ASN132BITCHAR wc); 02879 02891 EXTERNRT int rtUTF8EncodeChar (ASN132BITCHAR wc, ASN1OCTET* buf, int bufsiz); 02892 02893 EXTERNRT int rtUTF8DecodeChar (ASN1CTXT* pCtxt, 02894 ASN1UTF8String pinbuf, 02895 int* pInsize); 02896 02906 EXTERNRT char* rtUTF8Strdup (ASN1CTXT* pctxt, ASN1UTF8String utf8str); 02907 02919 EXTERNRT char* rtUTF8Strndup (ASN1CTXT* pctxt, 02920 ASN1UTF8String utf8str, 02921 int nbytes); 02922 02927 /* BigInt functions */ 02928 02947 EXTERNRT void rtBigIntInit (ASN1BigInt* pInt); 02948 02968 EXTERNRT int rtBigIntSetStr (ASN1CTXT* pCtxt, ASN1BigInt* pInt, 02969 ASN1ConstCharPtr value, int radix); 02970 02986 EXTERNRT int rtBigIntSetInt64 02987 (ASN1CTXT* pCtxt, ASN1BigInt* pInt, ASN1INT64 value); 02988 03008 EXTERNRT int rtBigIntSetBytes (ASN1CTXT* pCtxt, ASN1BigInt* pInt, 03009 ASN1OCTET* value, size_t vallen); 03010 03021 EXTERNRT size_t rtBigIntGetDataLen (ASN1BigInt* pInt); 03022 03041 EXTERNRT long rtBigIntGetData 03042 (ASN1CTXT* pCtxt, ASN1BigInt* pInt, ASN1OCTET* buffer, size_t bufSize); 03043 03055 EXTERNRT int rtBigIntDigitsNum (ASN1BigInt* pInt, int radix); 03056 03070 EXTERNRT int rtBigIntCopy 03071 (ASN1CTXT* pCtxt, const ASN1BigInt* pSrc, ASN1BigInt* pDst); 03072 03089 EXTERNRT int rtBigIntFastCopy 03090 (ASN1CTXT* pCtxt, ASN1BigInt* pSrc, ASN1BigInt* pDst); 03091 03108 EXTERNRT int rtBigIntToString (ASN1CTXT* pCtxt, ASN1BigInt* pInt, int radix, 03109 char* str, size_t strSize); 03110 03122 EXTERNRT int rtBigIntPrint 03123 (ASN1ConstCharPtr name, ASN1BigInt* bigint, int radix); 03124 03134 EXTERNRT int rtBigIntCompare (const ASN1BigInt* arg1, const ASN1BigInt* arg2); 03135 03152 EXTERNRT int rtBigIntStrCompare (ASN1CTXT* pCtxt, ASN1ConstCharPtr arg1, 03153 ASN1ConstCharPtr arg2); 03154 03167 EXTERNRT void rtBigIntFree (ASN1CTXT* pCtxt, ASN1BigInt* pInt); 03168 03172 /* deprecated names of some rtBigInt* functions */ 03173 03174 #define rtSetStrToBigInt rtBigIntSetStr 03175 #define rtSetInt64ToBigInt rtBigIntSetInt64 03176 #define rtSetBytesToBigInt rtBigIntSetBytes 03177 #define rtGetBigIntLen rtBigIntGetDataLen 03178 #define rtGetBigInt rtBigIntGetData 03179 #define rtPrintBigInt rtBigIntPrint 03180 #define rtCompareBigInt rtBigIntCompare 03181 #define rtCompareBigIntStr rtBigIntStrCompare 03182 03183 03217 EXTERNRT int rtMakeGeneralizedTime (ASN1CTXT* pctxt, 03218 const OSDATETIME* dateTime, 03219 char** outdata, 03220 int outdataSize); 03221 03246 EXTERNRT int rtMakeUTCTime (ASN1CTXT* pctxt, 03247 const OSDATETIME* dateTime, 03248 char** outdata, 03249 int outdataSize); 03250 03275 EXTERNRT int rtMakeXmlDateTime (ASN1CTXT* pctxt, const OSDATETIME* dateTime, 03276 char** outdata, int outdataSize); 03277 03293 EXTERNRT int rtParseGeneralizedTime (ASN1CTXT *pctxt, 03294 ASN1ConstCharPtr value, 03295 OSDATETIME* dateTime); 03296 03312 EXTERNRT int rtParseUTCTime (ASN1CTXT *pctxt, 03313 ASN1ConstCharPtr value, 03314 OSDATETIME* dateTime); 03315 03331 EXTERNRT int rtParseXmlDateTime (ASN1CTXT *pctxt, 03332 ASN1ConstCharPtr value, 03333 OSDATETIME* dateTime); 03338 /* file functions */ 03339 03355 EXTERNRT int rtFileReadBinary (ASN1CTXT* pctxt, const char* filePath, 03356 ASN1OCTET** ppMsgBuf, size_t* pLength); 03357 03358 03359 03360 #ifdef __cplusplus 03361 } 03362 #endif 03363 03364 #if defined (ACVERSION) && ACVERSION <= 530 03365 #include "asn1intl.h" 03366 #endif 03367 03368 #include "rtMemory.h" 03369 03370 #endif 03371

Copyright © 1997-2004 Objective Systems,Inc.
All Rights Reserved.
This document may be distributed in any form, electronic
or otherwise, provided that it is distributed in its entirety
and that the copyright and this notice are included.

This file was last modified on 1 Oct 2004.
ASN1C C/C++ Common Runtime, ASN1C v5.7x