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
00396 typedef struct {
00397 OSSIZE numbits;
00398 const OSOCTET* data;
00399 } ASN1DynBitStr64;
00400
00402 typedef struct {
00403 OSUINT32 numbits;
00404 OSOCTET data[4];
00405 } ASN1BitStr32;
00406
00407 #include "rtxsrc/rtxBitString.h"
00408
00415 #define OSSETBIT(bitStr,bitIndex) \
00416 rtxSetBit (bitStr.data, bitStr.numbits, bitIndex)
00417
00424 #define OSSETBITP(pBitStr,bitIndex) \
00425 rtxSetBit ((pBitStr)->data, (pBitStr)->numbits, bitIndex)
00426
00433 #define OSCLEARBIT(bitStr,bitIndex) \
00434 rtxClearBit (bitStr.data, bitStr.numbits, bitIndex)
00435
00442 #define OSCLEARBITP(pBitStr,bitIndex) \
00443 rtxClearBit ((pBitStr)->data, (pBitStr)->numbits, bitIndex)
00444
00453 #define OSTESTBIT(bitStr,bitIndex) \
00454 rtxTestBit (bitStr.data, bitStr.numbits, bitIndex)
00455
00462 #define OSTESTBITP(pBitStr,bitIndex) \
00463 rtxTestBit ((pBitStr)->data, (pBitStr)->numbits, bitIndex)
00464
00498 EXTERNRT int rtMakeGeneralizedTime (OSCTXT* pctxt,
00499 const OSNumDateTime* dateTime,
00500 char** outdata,
00501 size_t outdataSize);
00502
00527 EXTERNRT int rtMakeUTCTime (OSCTXT* pctxt,
00528 const OSNumDateTime* dateTime,
00529 char** outdata,
00530 size_t outdataSize);
00546 EXTERNRT int rtParseGeneralizedTime (OSCTXT *pctxt,
00547 const char* value,
00548 OSNumDateTime* dateTime);
00549
00565 EXTERNRT int rtParseUTCTime (OSCTXT *pctxt,
00566 const char* value,
00567 OSNumDateTime* dateTime);
00568
00574 EXTERNRT void normalizeTimeZone(OSNumDateTime* pvalue);
00575
00580
00581
00582
00587 typedef struct {
00589 OSUINT32 n;
00590
00592 void* elem;
00593 } ASN1SeqOf;
00594
00600 typedef struct {
00602 OSUINT32 n;
00603
00605 OSDynOctStr* elem;
00606 } ASN1SeqOfOctStr;
00607
00612 typedef struct {
00613 OSSIZE numocts;
00614 const OSOCTET* data;
00615 } ASN1OpenType;
00616
00622 typedef struct {
00623 ASN1OpenType encoded;
00624 void* decoded;
00625 OSINT32 index;
00626 } Asn1Object;
00627
00628 typedef Asn1Object ASN1Object;
00629
00630
00631
00637 typedef struct {
00638 OSSIZE nchars;
00639 OSUNICHAR* data;
00640 } Asn116BitCharString;
00641
00642 typedef OSUNICHAR ASN116BITCHAR;
00643
00649 typedef struct {
00650 OSSIZE nchars;
00651 OS32BITCHAR* data;
00652 } Asn132BitCharString;
00653
00654 typedef const char* ASN1GeneralizedTime;
00655 typedef const char* ASN1GeneralString;
00656 typedef const char* ASN1GraphicString;
00657 typedef const char* ASN1IA5String;
00658 typedef const char* ASN1ISO646String;
00659 typedef const char* ASN1NumericString;
00660 typedef const char* ASN1ObjectDescriptor;
00661 typedef const char* ASN1PrintableString;
00662 typedef const char* ASN1TeletexString;
00663 typedef const char* ASN1T61String;
00664 typedef const char* ASN1UTCTime;
00665 typedef const char* ASN1VideotexString;
00666 typedef const char* ASN1VisibleString;
00667
00668 typedef const OSUTF8CHAR* ASN1UTF8String;
00669 typedef Asn116BitCharString ASN1BMPString;
00670 typedef Asn132BitCharString ASN1UniversalString;
00671
00672
00673
00678 typedef struct {
00679 int nchars;
00680 char data[255];
00681 } Asn1CharArray;
00682
00688 typedef struct {
00693 Asn1CharArray charSet;
00694
00698 const char* canonicalSet;
00699
00703 int canonicalSetSize;
00704
00708 unsigned canonicalSetBits;
00709
00714 unsigned charSetUnalignedBits;
00715
00720 unsigned charSetAlignedBits;
00721 } Asn1CharSet;
00722
00727 typedef struct {
00729 Asn116BitCharString charSet;
00730
00732 OSUINT16 firstChar, lastChar;
00733
00735 unsigned unalignedBits;
00736
00738 unsigned alignedBits;
00739 } Asn116BitCharSet;
00740
00745 typedef struct {
00747 Asn132BitCharString charSet;
00748
00750 OSUINT32 firstChar, lastChar;
00751
00753 unsigned unalignedBits;
00754
00756 unsigned alignedBits;
00757 } Asn132BitCharSet;
00758
00767
00768
00781 EXTERNRT int rtValidateStr (ASN1TAG tag, const char *pdata);
00782
00796 EXTERNRT int rtValidateChars (ASN1TAG tag, const char* pdata, size_t nchars);
00797
00798
00799
00810 EXTERNRT const char* rtBMPToCString (ASN1BMPString* pBMPString,
00811 char* cstring, OSSIZE cstrsize);
00812
00823 EXTERNRT const char* rtBMPToNewCString (ASN1BMPString* pBMPString);
00824
00838 EXTERNRT const char* rtBMPToNewCStringEx
00839 (OSCTXT *pctxt, ASN1BMPString* pBMPString);
00840
00856 EXTERNRT ASN1BMPString* rtCToBMPString (OSCTXT* pctxt,
00857 const char* cstring,
00858 ASN1BMPString* pBMPString,
00859 Asn116BitCharSet* pCharSet);
00860
00871 EXTERNRT OSBOOL rtIsIn16BitCharSet (OSUNICHAR ch,
00872 Asn116BitCharSet* pCharSet);
00873
00874
00875
00876
00888 EXTERNRT const char* rtUCSToCString (ASN1UniversalString* pUCSString,
00889 char* cstring, OSSIZE cstrsize);
00890
00903 EXTERNRT const char* rtUCSToNewCString (ASN1UniversalString* pUCSString);
00904
00919 EXTERNRT const char* rtUCSToNewCStringEx
00920 (OSCTXT* pctxt, ASN1UniversalString* pUCSString);
00921
00937 EXTERNRT ASN1UniversalString* rtCToUCSString
00938 (OSCTXT* pctxt, const char* cstring, ASN1UniversalString* pUCSString,
00939 Asn132BitCharSet* pCharSet);
00940
00941
00952 EXTERNRT OSBOOL rtIsIn32BitCharSet (OS32BITCHAR ch,
00953 Asn132BitCharSet* pCharSet);
00954
00967 EXTERNRT wchar_t* rtUCSToWCSString (ASN1UniversalString* pUCSString,
00968 wchar_t* wcstring, OSUINT32 wcstrsize);
00969
00970
00988 EXTERNRT ASN1UniversalString* rtWCSToUCSString
00989 (OSCTXT* pctxt, wchar_t* wcstring,
00990 ASN1UniversalString* pUCSString, Asn132BitCharSet* pCharSet);
00991
01003 EXTERNRT int rtUnivStrToUTF8
01004 (OSCTXT* pctxt, const ASN1UniversalString* pUnivStr, OSOCTET* outbuf,
01005 size_t outbufsiz);
01006
01021 EXTERNRT int rtUTF8StrToASN1DynBitStr
01022 (OSCTXT* pctxt, const OSUTF8CHAR* utf8str, ASN1DynBitStr* pvalue);
01023
01040 EXTERNRT int rtUTF8StrnToASN1DynBitStr
01041 (OSCTXT* pctxt, const OSUTF8CHAR* utf8str, size_t nbytes,
01042 ASN1DynBitStr* pvalue);
01043
01054 typedef struct ASN1BigInt {
01056 size_t numocts;
01057
01059 OSOCTET* mag;
01060
01062 int sign;
01063
01065 size_t allocated;
01066
01068 OSBOOL dynamic;
01069 } ASN1BigInt;
01070
01072 #define ASN1_K_CCBMaskSize 32
01073
01075 #define ASN1_K_NumBitsPerMask 16
01076
01078 #define ASN1_K_MaxSetElements (ASN1_K_CCBMaskSize*ASN1_K_NumBitsPerMask)
01079
01087 typedef struct {
01089 OSOCTET* ptr;
01090
01092 long len;
01093
01095 int seqx;
01096
01098 OSUINT16 mask[ASN1_K_CCBMaskSize];
01099
01101 OSSIZE bytes;
01102
01104 int stat;
01105 } ASN1CCB;
01106
01108 typedef int (*ASN1DumpCbFunc) (const char* text_p, void* cbArg_p);
01109
01110
01129 #define ALLOC_ASN1ARRAY(pctxt,pseqof,type) do {\
01130 if (sizeof(type)*(pseqof)->n < (pseqof)->n) return RTERR_NOMEM; \
01131 if (((pseqof)->elem = (type*) rtxMemHeapAllocZ \
01132 (&(pctxt)->pMemHeap, sizeof(type)*(pseqof)->n)) == 0) return RTERR_NOMEM; \
01133 } while (0)
01134
01147 #define ALLOC_ASN1ARRAY1(pctxt,pseqof,type) do {\
01148 if (sizeof(type)*(pseqof)->n < (pseqof)->n) (pseqof)->elem = 0; \
01149 else (pseqof)->elem = (type*) rtxMemHeapAllocZ \
01150 (&(pctxt)->pMemHeap, sizeof(type)*(pseqof)->n); \
01151 } while (0)
01152
01157 #define ASN1NUMOCTS(nbits) ((nbits>0)?(((nbits-1)/8)+1):0)
01158
01159 #ifdef __cplusplus
01160 }
01161 #endif
01162
01163 #include "rtsrc/rtContext.h"
01164 #include "rtxsrc/rtxCommonDefs.h"
01165 #include "rtxsrc/rtxError.h"
01166 #include "rtxsrc/rtxMemory.h"
01167
01172 #endif