00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00100 #ifndef _ASN1TYPE_H_
00101 #define _ASN1TYPE_H_
00102
00103 #include <limits.h>
00104 #include <stdio.h>
00105 #include <string.h>
00106 #include <stddef.h>
00107 #include <setjmp.h>
00108 #include <stdlib.h>
00109 #ifndef _WIN32_WCE
00110 #include <time.h>
00111 #endif
00112
00113 #ifdef _NUCLEUS
00114 #ifndef NUCLEUS
00115 #include <nucleus.h>
00116 #endif
00117 #else
00118
00119 #if !defined(_MSC_VER) && !defined(__GNUC__) && !defined(_16BIT) && !defined(__SYMBIAN32__)
00120 #include <wchar.h>
00121 #endif
00122
00123 #endif
00124
00125 #include "rtxsrc/rtxExternDefs.h"
00126 #include "rtxsrc/rtxSList.h"
00127 #include "rtxsrc/rtxStack.h"
00128 #include "rtxsrc/rtxUTF8.h"
00129
00130
00169 #include "rtsrc/asn1tag.h"
00170 #include "rtsrc/asn1ErrCodes.h"
00171 #include "rtsrc/asn1version.h"
00172 #include "rtsrc/rtExternDefs.h"
00173
00174
00175
00176
00177
00178 #define XM_SEEK 0x01
00179 #define XM_ADVANCE 0x02
00180 #define XM_DYNAMIC 0x04
00181 #define XM_SKIP 0x08
00182 #define XM_OPTIONAL 0x10
00183
00184
00185
00186 #define ASN_K_MAXDEPTH 32
00187 #define ASN_K_MAXENUM 100
00188 #define ASN_K_MAXERRP 5
00189 #define ASN_K_MAXERRSTK 8
00190
00191 #ifndef ASN_K_ENCBUFSIZ
00192 #define ASN_K_ENCBUFSIZ 16*1024
00193 #endif
00194
00195 #ifndef ASN_K_MEMBUFSEG
00196 #define ASN_K_MEMBUFSEG 1024
00197 #endif
00198
00199 #define OSRTINDENTSPACES 3
00200
00201
00202
00203 #define ASN1_K_PLUS_INFINITY 0x40
00204 #define ASN1_K_MINUS_INFINITY 0x41
00205
00206 #define REAL_BINARY 0x80
00207 #define REAL_SIGN 0x40
00208 #define REAL_EXPLEN_MASK 0x03
00209 #define REAL_EXPLEN_1 0x00
00210 #define REAL_EXPLEN_2 0x01
00211 #define REAL_EXPLEN_3 0x02
00212 #define REAL_EXPLEN_LONG 0x03
00213 #define REAL_FACTOR_MASK 0x0c
00214 #define REAL_BASE_MASK 0x30
00215 #define REAL_BASE_2 0x00
00216 #define REAL_BASE_8 0x10
00217 #define REAL_BASE_16 0x20
00218 #define REAL_ISO6093_MASK 0x3F
00219
00220 #ifndef __SYMBIAN32__
00221 #include <float.h>
00222 #define ASN1REALMAX (OSREAL)DBL_MAX
00223 #define ASN1REALMIN (OSREAL)-DBL_MAX
00224 #endif
00225
00226 typedef void* ASN1ANY;
00227
00232 typedef enum { ASN1HEX, ASN1BIN, ASN1CHR } ASN1StrType;
00233
00237 typedef enum { ASN1ENCODE, ASN1DECODE } ASN1ActionType;
00238
00239
00240
00241
00250 #define ASN_K_MAXSUBIDS 128
00251
00255 typedef struct {
00257 OSUINT32 numids;
00259 OSUINT32 subid[ASN_K_MAXSUBIDS];
00260 } ASN1OBJID;
00261
00265 typedef struct {
00267 OSUINT32 numids;
00269 OSUINT64 subid[ASN_K_MAXSUBIDS];
00270 } ASN1OID64;
00271
00273 #ifdef __cplusplus
00274 #define EXTERN_C extern "C"
00275 extern "C" {
00276 #else
00277 #define EXTERN_C extern
00278 #endif
00279
00295 EXTERNRT void rtSetOID (ASN1OBJID* ptarget, ASN1OBJID* psource);
00296
00312 EXTERNRT void rtAddOID (ASN1OBJID* ptarget, ASN1OBJID* psource);
00313
00321 EXTERNRT OSBOOL rtOIDsEqual (const ASN1OBJID* pOID1, const ASN1OBJID* pOID2);
00322
00336 EXTERNRT int rtOIDParseDottedNumberString
00337 (const char* oidstr, OSSIZE oidstrlen, ASN1OBJID* pvalue);
00338
00349 EXTERNRT OSBOOL rtOIDIsValid (const ASN1OBJID* pvalue);
00350
00355
00356
00357
00358 typedef struct {
00359 OSUINT32 numocts;
00360 OSOCTET data[1];
00361 } ASN1OctStr;
00362
00363 #define ASN1DynOctStr OSDynOctStr
00364
00365
00366
00367
00368 typedef struct {
00369 OSUINT32 numbits;
00370 const OSOCTET* data;
00371 } ASN1DynBitStr;
00372
00373 typedef struct {
00374 OSUINT32 numbits;
00375 OSOCTET data[4];
00376 } ASN1BitStr32;
00377
00378 #include "rtxsrc/rtxBitString.h"
00379
00380 #define OSSETBIT(bitStr,bitIndex) \
00381 rtxSetBit (bitStr.data, bitStr.numbits, bitIndex)
00382
00383 #define OSSETBITP(pBitStr,bitIndex) \
00384 rtxSetBit ((pBitStr)->data, (pBitStr)->numbits, bitIndex)
00385
00386 #define OSCLEARBIT(bitStr,bitIndex) \
00387 rtxClearBit (bitStr.data, bitStr.numbits, bitIndex)
00388
00389 #define OSCLEARBITP(pBitStr,bitIndex) \
00390 rtxClearBit ((pBitStr)->data, (pBitStr)->numbits, bitIndex)
00391
00392 #define OSTESTBIT(bitStr,bitIndex) \
00393 rtxTestBit (bitStr.data, bitStr.numbits, bitIndex)
00394
00395 #define OSTESTBITP(pBitStr,bitIndex) \
00396 rtxTestBit ((pBitStr)->data, (pBitStr)->numbits, bitIndex)
00397
00431 EXTERNRT int rtMakeGeneralizedTime (OSCTXT* pctxt,
00432 const OSNumDateTime* dateTime,
00433 char** outdata,
00434 size_t outdataSize);
00435
00460 EXTERNRT int rtMakeUTCTime (OSCTXT* pctxt,
00461 const OSNumDateTime* dateTime,
00462 char** outdata,
00463 size_t outdataSize);
00479 EXTERNRT int rtParseGeneralizedTime (OSCTXT *pctxt,
00480 const char* value,
00481 OSNumDateTime* dateTime);
00482
00498 EXTERNRT int rtParseUTCTime (OSCTXT *pctxt,
00499 const char* value,
00500 OSNumDateTime* dateTime);
00501
00502 EXTERNRT void normalizeTimeZone(OSNumDateTime* pvalue);
00503
00508
00509
00510
00511 typedef struct {
00512 OSUINT32 n;
00513 void* elem;
00514 } ASN1SeqOf;
00515
00516 typedef struct {
00517 OSUINT32 n;
00518 OSDynOctStr* elem;
00519 } ASN1SeqOfOctStr;
00520
00525 typedef struct {
00526 OSUINT32 numocts;
00527 const OSOCTET* data;
00528 } ASN1OpenType;
00529
00530 typedef struct {
00531 ASN1OpenType encoded;
00532 void* decoded;
00533 OSINT32 index;
00534 } Asn1Object;
00535
00536 typedef Asn1Object ASN1Object;
00537
00538
00539
00540 typedef struct {
00541 OSUINT32 nchars;
00542 OSUNICHAR* data;
00543 } Asn116BitCharString;
00544
00545 typedef OSUNICHAR ASN116BITCHAR;
00546
00547 typedef struct {
00548 OSUINT32 nchars;
00549 OS32BITCHAR* data;
00550 } Asn132BitCharString;
00551
00552 typedef const char* ASN1GeneralizedTime;
00553 typedef const char* ASN1GeneralString;
00554 typedef const char* ASN1GraphicString;
00555 typedef const char* ASN1IA5String;
00556 typedef const char* ASN1ISO646String;
00557 typedef const char* ASN1NumericString;
00558 typedef const char* ASN1ObjectDescriptor;
00559 typedef const char* ASN1PrintableString;
00560 typedef const char* ASN1TeletexString;
00561 typedef const char* ASN1T61String;
00562 typedef const char* ASN1UTCTime;
00563 typedef const char* ASN1VideotexString;
00564 typedef const char* ASN1VisibleString;
00565
00566 typedef const OSUTF8CHAR* ASN1UTF8String;
00567 typedef Asn116BitCharString ASN1BMPString;
00568 typedef Asn132BitCharString ASN1UniversalString;
00569
00570
00571
00572 typedef struct {
00573 int nchars;
00574 char data[255];
00575 } Asn1CharArray;
00576
00577 typedef struct {
00578 Asn1CharArray charSet;
00579 const char* canonicalSet;
00580 int canonicalSetSize;
00581 unsigned canonicalSetBits;
00582 unsigned charSetUnalignedBits;
00583 unsigned charSetAlignedBits;
00584 } Asn1CharSet;
00585
00586 typedef struct {
00587 Asn116BitCharString charSet;
00588 OSUINT16 firstChar, lastChar;
00589 unsigned unalignedBits;
00590 unsigned alignedBits;
00591 } Asn116BitCharSet;
00592
00593 typedef struct {
00594 Asn132BitCharString charSet;
00595 OSUINT32 firstChar, lastChar;
00596 unsigned unalignedBits;
00597 unsigned alignedBits;
00598 } Asn132BitCharSet;
00599
00608
00609
00622 EXTERNRT int rtValidateStr (ASN1TAG tag, const char *pdata);
00623
00637 EXTERNRT int rtValidateChars (ASN1TAG tag, const char* pdata, size_t nchars);
00638
00639
00640
00651 EXTERNRT const char* rtBMPToCString (ASN1BMPString* pBMPString,
00652 char* cstring, OSUINT32 cstrsize);
00653
00664 EXTERNRT const char* rtBMPToNewCString (ASN1BMPString* pBMPString);
00665
00679 EXTERNRT const char* rtBMPToNewCStringEx
00680 (OSCTXT *pctxt, ASN1BMPString* pBMPString);
00681
00697 EXTERNRT ASN1BMPString* rtCToBMPString (OSCTXT* pctxt,
00698 const char* cstring,
00699 ASN1BMPString* pBMPString,
00700 Asn116BitCharSet* pCharSet);
00701
00702 EXTERNRT OSBOOL rtIsIn16BitCharSet (OSUNICHAR ch,
00703 Asn116BitCharSet* pCharSet);
00704
00705
00706
00707
00719 EXTERNRT const char* rtUCSToCString (ASN1UniversalString* pUCSString,
00720 char* cstring, OSUINT32 cstrsize);
00721
00734 EXTERNRT const char* rtUCSToNewCString (ASN1UniversalString* pUCSString);
00735
00750 EXTERNRT const char* rtUCSToNewCStringEx
00751 (OSCTXT* pctxt, ASN1UniversalString* pUCSString);
00752
00768 EXTERNRT ASN1UniversalString* rtCToUCSString
00769 (OSCTXT* pctxt, const char* cstring, ASN1UniversalString* pUCSString,
00770 Asn132BitCharSet* pCharSet);
00771
00772
00773 EXTERNRT OSBOOL rtIsIn32BitCharSet (OS32BITCHAR ch,
00774 Asn132BitCharSet* pCharSet);
00775
00788 EXTERNRT wchar_t* rtUCSToWCSString (ASN1UniversalString* pUCSString,
00789 wchar_t* wcstring, OSUINT32 wcstrsize);
00790
00791
00809 EXTERNRT ASN1UniversalString* rtWCSToUCSString
00810 (OSCTXT* pctxt, wchar_t* wcstring,
00811 ASN1UniversalString* pUCSString, Asn132BitCharSet* pCharSet);
00812
00824 EXTERNRT int rtUnivStrToUTF8
00825 (OSCTXT* pctxt, const ASN1UniversalString* pUnivStr, OSOCTET* outbuf,
00826 size_t outbufsiz);
00827
00842 EXTERNRT int rtUTF8StrToASN1DynBitStr
00843 (OSCTXT* pctxt, const OSUTF8CHAR* utf8str, ASN1DynBitStr* pvalue);
00844
00861 EXTERNRT int rtUTF8StrnToASN1DynBitStr
00862 (OSCTXT* pctxt, const OSUTF8CHAR* utf8str, size_t nbytes,
00863 ASN1DynBitStr* pvalue);
00864
00869
00870
00871 typedef struct ASN1BigInt {
00872 size_t numocts;
00873 OSOCTET* mag;
00874 int sign;
00875 size_t allocated;
00876 OSBOOL dynamic;
00877 } ASN1BigInt;
00878
00879
00880
00881
00882
00883 #define ASN1_K_CCBMaskSize 32
00884 #define ASN1_K_NumBitsPerMask 16
00885 #define ASN1_K_MaxSetElements (ASN1_K_CCBMaskSize*ASN1_K_NumBitsPerMask)
00886
00887 typedef struct {
00888 OSOCTET* ptr;
00889 long len;
00890 int seqx;
00891 OSUINT16 mask[ASN1_K_CCBMaskSize];
00892 size_t bytes;
00893 int stat;
00894 } ASN1CCB;
00895
00896
00897
00898 typedef int (*ASN1DumpCbFunc) (const char* text_p, void* cbArg_p);
00899
00918 #define ALLOC_ASN1ARRAY(pctxt,pseqof,type) do {\
00919 if (sizeof(type)*(pseqof)->n < (pseqof)->n) return RTERR_NOMEM; \
00920 if (((pseqof)->elem = (type*) rtxMemHeapAlloc \
00921 (&(pctxt)->pMemHeap, sizeof(type)*(pseqof)->n)) == 0) return RTERR_NOMEM; \
00922 } while (0)
00923
00936 #define ALLOC_ASN1ARRAY1(pctxt,pseqof,type) do {\
00937 if (sizeof(type)*(pseqof)->n < (pseqof)->n) (pseqof)->elem = 0; \
00938 else (pseqof)->elem = (type*) rtxMemHeapAlloc \
00939 (&(pctxt)->pMemHeap, sizeof(type)*(pseqof)->n); \
00940 } while (0)
00941
00946 #define ASN1NUMOCTS(nbits) ((nbits>0)?(((nbits-1)/8)+1):0)
00947
00948 #ifdef __cplusplus
00949 }
00950 #endif
00951
00952 #include "rtsrc/rtContext.h"
00953 #include "rtxsrc/rtxCommonDefs.h"
00954 #include "rtxsrc/rtxError.h"
00955 #include "rtxsrc/rtxMemory.h"
00956
00961 #endif