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
00179 #define XM_SEEK 0x01
00180
00181 #define XM_ADVANCE 0x02
00182
00183 #define XM_DYNAMIC 0x04
00184
00185 #define XM_SKIP 0x08
00186
00187 #define XM_OPTIONAL 0x10
00188
00189
00190
00192 #define ASN_K_MAXDEPTH 32
00193
00194 #define ASN_K_MAXENUM 100
00195
00196 #define ASN_K_MAXERRP 5
00197
00198 #define ASN_K_MAXERRSTK 8
00199
00200 #ifndef ASN_K_ENCBUFSIZ
00201
00202 #define ASN_K_ENCBUFSIZ 16*1024
00203 #endif
00204
00205 #ifndef ASN_K_MEMBUFSEG
00206
00207 #define ASN_K_MEMBUFSEG 1024
00208 #endif
00209
00211 #define OSRTINDENTSPACES 3
00212
00213
00214
00216 #define ASN1_K_PLUS_INFINITY 0x40
00217
00219 #define ASN1_K_MINUS_INFINITY 0x41
00220
00221 #define REAL_BINARY 0x80
00222 #define REAL_SIGN 0x40
00223 #define REAL_EXPLEN_MASK 0x03
00224 #define REAL_EXPLEN_1 0x00
00225 #define REAL_EXPLEN_2 0x01
00226 #define REAL_EXPLEN_3 0x02
00227 #define REAL_EXPLEN_LONG 0x03
00228 #define REAL_FACTOR_MASK 0x0c
00229 #define REAL_BASE_MASK 0x30
00230 #define REAL_BASE_2 0x00
00231 #define REAL_BASE_8 0x10
00232 #define REAL_BASE_16 0x20
00233 #define REAL_ISO6093_MASK 0x3F
00234
00235 #ifndef __SYMBIAN32__
00236 #include <float.h>
00237 #define ASN1REALMAX (OSREAL)DBL_MAX
00238 #define ASN1REALMIN (OSREAL)-DBL_MAX
00239 #endif
00240
00241 typedef void* ASN1ANY;
00242
00247 typedef enum { ASN1HEX, ASN1BIN, ASN1CHR } ASN1StrType;
00248
00252 typedef enum { ASN1ENCODE, ASN1DECODE } ASN1ActionType;
00253
00254
00255
00256
00265 #define ASN_K_MAXSUBIDS 128
00266
00270 typedef struct {
00272 OSUINT32 numids;
00274 OSUINT32 subid[ASN_K_MAXSUBIDS];
00275 } ASN1OBJID;
00276
00280 typedef struct {
00282 OSUINT32 numids;
00284 OSUINT64 subid[ASN_K_MAXSUBIDS];
00285 } ASN1OID64;
00286
00288 #ifdef __cplusplus
00289 #define EXTERN_C extern "C"
00290 extern "C" {
00291 #else
00292 #define EXTERN_C extern
00293 #endif
00294
00310 EXTERNRT void rtSetOID (ASN1OBJID* ptarget, ASN1OBJID* psource);
00311
00327 EXTERNRT void rtAddOID (ASN1OBJID* ptarget, ASN1OBJID* psource);
00328
00336 EXTERNRT OSBOOL rtOIDsEqual (const ASN1OBJID* pOID1, const ASN1OBJID* pOID2);
00337
00351 EXTERNRT int rtOIDParseDottedNumberString
00352 (const char* oidstr, OSSIZE oidstrlen, ASN1OBJID* pvalue);
00353
00364 EXTERNRT OSBOOL rtOIDIsValid (const ASN1OBJID* pvalue);
00365
00370
00371
00372
00377 typedef struct {
00378 OSUINT32 numocts;
00379 OSOCTET data[1];
00380 } ASN1OctStr;
00381
00383 #define ASN1DynOctStr OSDynOctStr
00384
00385
00386
00387
00389 typedef struct {
00390 OSUINT32 numbits;
00391 const OSOCTET* data;
00392 } ASN1DynBitStr;
00393
00395 typedef struct {
00396 OSUINT32 numbits;
00397 OSOCTET data[4];
00398 } ASN1BitStr32;
00399
00400 #include "rtxsrc/rtxBitString.h"
00401
00408 #define OSSETBIT(bitStr,bitIndex) \
00409 rtxSetBit (bitStr.data, bitStr.numbits, bitIndex)
00410
00417 #define OSSETBITP(pBitStr,bitIndex) \
00418 rtxSetBit ((pBitStr)->data, (pBitStr)->numbits, bitIndex)
00419
00426 #define OSCLEARBIT(bitStr,bitIndex) \
00427 rtxClearBit (bitStr.data, bitStr.numbits, bitIndex)
00428
00435 #define OSCLEARBITP(pBitStr,bitIndex) \
00436 rtxClearBit ((pBitStr)->data, (pBitStr)->numbits, bitIndex)
00437
00446 #define OSTESTBIT(bitStr,bitIndex) \
00447 rtxTestBit (bitStr.data, bitStr.numbits, bitIndex)
00448
00455 #define OSTESTBITP(pBitStr,bitIndex) \
00456 rtxTestBit ((pBitStr)->data, (pBitStr)->numbits, bitIndex)
00457
00491 EXTERNRT int rtMakeGeneralizedTime (OSCTXT* pctxt,
00492 const OSNumDateTime* dateTime,
00493 char** outdata,
00494 size_t outdataSize);
00495
00520 EXTERNRT int rtMakeUTCTime (OSCTXT* pctxt,
00521 const OSNumDateTime* dateTime,
00522 char** outdata,
00523 size_t outdataSize);
00539 EXTERNRT int rtParseGeneralizedTime (OSCTXT *pctxt,
00540 const char* value,
00541 OSNumDateTime* dateTime);
00542
00558 EXTERNRT int rtParseUTCTime (OSCTXT *pctxt,
00559 const char* value,
00560 OSNumDateTime* dateTime);
00561
00567 EXTERNRT void normalizeTimeZone(OSNumDateTime* pvalue);
00568
00573
00574
00575
00580 typedef struct {
00582 OSUINT32 n;
00583
00585 void* elem;
00586 } ASN1SeqOf;
00587
00593 typedef struct {
00595 OSUINT32 n;
00596
00598 OSDynOctStr* elem;
00599 } ASN1SeqOfOctStr;
00600
00605 typedef struct {
00606 OSUINT32 numocts;
00607 const OSOCTET* data;
00608 } ASN1OpenType;
00609
00615 typedef struct {
00616 ASN1OpenType encoded;
00617 void* decoded;
00618 OSINT32 index;
00619 } Asn1Object;
00620
00621 typedef Asn1Object ASN1Object;
00622
00623
00624
00630 typedef struct {
00631 OSUINT32 nchars;
00632 OSUNICHAR* data;
00633 } Asn116BitCharString;
00634
00635 typedef OSUNICHAR ASN116BITCHAR;
00636
00642 typedef struct {
00643 OSUINT32 nchars;
00644 OS32BITCHAR* data;
00645 } Asn132BitCharString;
00646
00647 typedef const char* ASN1GeneralizedTime;
00648 typedef const char* ASN1GeneralString;
00649 typedef const char* ASN1GraphicString;
00650 typedef const char* ASN1IA5String;
00651 typedef const char* ASN1ISO646String;
00652 typedef const char* ASN1NumericString;
00653 typedef const char* ASN1ObjectDescriptor;
00654 typedef const char* ASN1PrintableString;
00655 typedef const char* ASN1TeletexString;
00656 typedef const char* ASN1T61String;
00657 typedef const char* ASN1UTCTime;
00658 typedef const char* ASN1VideotexString;
00659 typedef const char* ASN1VisibleString;
00660
00661 typedef const OSUTF8CHAR* ASN1UTF8String;
00662 typedef Asn116BitCharString ASN1BMPString;
00663 typedef Asn132BitCharString ASN1UniversalString;
00664
00665
00666
00671 typedef struct {
00672 int nchars;
00673 char data[255];
00674 } Asn1CharArray;
00675
00681 typedef struct {
00686 Asn1CharArray charSet;
00687
00691 const char* canonicalSet;
00692
00696 int canonicalSetSize;
00697
00701 unsigned canonicalSetBits;
00702
00707 unsigned charSetUnalignedBits;
00708
00713 unsigned charSetAlignedBits;
00714 } Asn1CharSet;
00715
00720 typedef struct {
00722 Asn116BitCharString charSet;
00723
00725 OSUINT16 firstChar, lastChar;
00726
00728 unsigned unalignedBits;
00729
00731 unsigned alignedBits;
00732 } Asn116BitCharSet;
00733
00738 typedef struct {
00740 Asn132BitCharString charSet;
00741
00743 OSUINT32 firstChar, lastChar;
00744
00746 unsigned unalignedBits;
00747
00749 unsigned alignedBits;
00750 } Asn132BitCharSet;
00751
00760
00761
00774 EXTERNRT int rtValidateStr (ASN1TAG tag, const char *pdata);
00775
00789 EXTERNRT int rtValidateChars (ASN1TAG tag, const char* pdata, size_t nchars);
00790
00791
00792
00803 EXTERNRT const char* rtBMPToCString (ASN1BMPString* pBMPString,
00804 char* cstring, OSUINT32 cstrsize);
00805
00816 EXTERNRT const char* rtBMPToNewCString (ASN1BMPString* pBMPString);
00817
00831 EXTERNRT const char* rtBMPToNewCStringEx
00832 (OSCTXT *pctxt, ASN1BMPString* pBMPString);
00833
00849 EXTERNRT ASN1BMPString* rtCToBMPString (OSCTXT* pctxt,
00850 const char* cstring,
00851 ASN1BMPString* pBMPString,
00852 Asn116BitCharSet* pCharSet);
00853
00864 EXTERNRT OSBOOL rtIsIn16BitCharSet (OSUNICHAR ch,
00865 Asn116BitCharSet* pCharSet);
00866
00867
00868
00869
00881 EXTERNRT const char* rtUCSToCString (ASN1UniversalString* pUCSString,
00882 char* cstring, OSUINT32 cstrsize);
00883
00896 EXTERNRT const char* rtUCSToNewCString (ASN1UniversalString* pUCSString);
00897
00912 EXTERNRT const char* rtUCSToNewCStringEx
00913 (OSCTXT* pctxt, ASN1UniversalString* pUCSString);
00914
00930 EXTERNRT ASN1UniversalString* rtCToUCSString
00931 (OSCTXT* pctxt, const char* cstring, ASN1UniversalString* pUCSString,
00932 Asn132BitCharSet* pCharSet);
00933
00934
00945 EXTERNRT OSBOOL rtIsIn32BitCharSet (OS32BITCHAR ch,
00946 Asn132BitCharSet* pCharSet);
00947
00960 EXTERNRT wchar_t* rtUCSToWCSString (ASN1UniversalString* pUCSString,
00961 wchar_t* wcstring, OSUINT32 wcstrsize);
00962
00963
00981 EXTERNRT ASN1UniversalString* rtWCSToUCSString
00982 (OSCTXT* pctxt, wchar_t* wcstring,
00983 ASN1UniversalString* pUCSString, Asn132BitCharSet* pCharSet);
00984
00996 EXTERNRT int rtUnivStrToUTF8
00997 (OSCTXT* pctxt, const ASN1UniversalString* pUnivStr, OSOCTET* outbuf,
00998 size_t outbufsiz);
00999
01014 EXTERNRT int rtUTF8StrToASN1DynBitStr
01015 (OSCTXT* pctxt, const OSUTF8CHAR* utf8str, ASN1DynBitStr* pvalue);
01016
01033 EXTERNRT int rtUTF8StrnToASN1DynBitStr
01034 (OSCTXT* pctxt, const OSUTF8CHAR* utf8str, size_t nbytes,
01035 ASN1DynBitStr* pvalue);
01036
01047 typedef struct ASN1BigInt {
01049 size_t numocts;
01050
01052 OSOCTET* mag;
01053
01055 int sign;
01056
01058 size_t allocated;
01059
01061 OSBOOL dynamic;
01062 } ASN1BigInt;
01063
01065 #define ASN1_K_CCBMaskSize 32
01066
01068 #define ASN1_K_NumBitsPerMask 16
01069
01071 #define ASN1_K_MaxSetElements (ASN1_K_CCBMaskSize*ASN1_K_NumBitsPerMask)
01072
01080 typedef struct {
01082 OSOCTET* ptr;
01083
01085 long len;
01086
01088 int seqx;
01089
01091 OSUINT16 mask[ASN1_K_CCBMaskSize];
01092
01094 size_t bytes;
01095
01097 int stat;
01098 } ASN1CCB;
01099
01101 typedef int (*ASN1DumpCbFunc) (const char* text_p, void* cbArg_p);
01102
01121 #define ALLOC_ASN1ARRAY(pctxt,pseqof,type) do {\
01122 if (sizeof(type)*(pseqof)->n < (pseqof)->n) return RTERR_NOMEM; \
01123 if (((pseqof)->elem = (type*) rtxMemHeapAllocZ \
01124 (&(pctxt)->pMemHeap, sizeof(type)*(pseqof)->n)) == 0) return RTERR_NOMEM; \
01125 } while (0)
01126
01139 #define ALLOC_ASN1ARRAY1(pctxt,pseqof,type) do {\
01140 if (sizeof(type)*(pseqof)->n < (pseqof)->n) (pseqof)->elem = 0; \
01141 else (pseqof)->elem = (type*) rtxMemHeapAllocZ \
01142 (&(pctxt)->pMemHeap, sizeof(type)*(pseqof)->n); \
01143 } while (0)
01144
01149 #define ASN1NUMOCTS(nbits) ((nbits>0)?(((nbits-1)/8)+1):0)
01150
01151 #ifdef __cplusplus
01152 }
01153 #endif
01154
01155 #include "rtsrc/rtContext.h"
01156 #include "rtxsrc/rtxCommonDefs.h"
01157 #include "rtxsrc/rtxError.h"
01158 #include "rtxsrc/rtxMemory.h"
01159
01164 #endif