00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00082 #ifndef _ASN1BER_H_
00083 #define _ASN1BER_H_
00084
00085 #include "rtsrc/asn1type.h"
00086
00087 #define ASN_K_INDEFLEN -9999
00088
00089 #define XU_DUMP(msg) xu_dump(msg,0,0)
00090 #define xd_resetp(pctxt) rtxResetContext(pctxt)
00091
00092 #define ASN1TAG2BYTE(tag) \
00093 ((OSOCTET)(((tag)&TM_B_IDCODE)|((tag)>>ASN1TAG_LSHIFT)))
00094
00099 typedef struct _Asn1BufLocDescr {
00100 OSUINT32 numocts;
00101 OSINT32 offset;
00102 } Asn1BufLocDescr;
00103
00104 #ifdef __cplusplus
00105 extern "C" {
00106
00107 #endif
00108
00109 #if defined(_WIN32) || defined(_WIN64)
00110 #ifndef EXTERNBER
00111 #ifdef BUILDASN1BERDLL
00112 #define EXTERNBER __declspec(dllexport)
00113 #elif defined (USEASN1BERDLL)
00114 #define EXTERNBER __declspec(dllimport)
00115 #else
00116 #define EXTERNBER
00117 #endif
00118 #endif
00119 #else
00120 #ifndef EXTERNBER
00121 #define EXTERNBER
00122 #endif
00123 #endif
00124
00125
00158 EXTERNBER int xd_tag (OSCTXT* pctxt, ASN1TAG *tag_p);
00159
00180 EXTERNBER int xd_tag_len (OSCTXT *pctxt, ASN1TAG *tag_p,
00181 int *len_p, OSOCTET flags);
00182
00207 EXTERNBER int xd_match (OSCTXT *pctxt, ASN1TAG tag,
00208 int *len_p, OSOCTET flags);
00209
00235 EXTERNBER int xd_boolean (OSCTXT *pctxt, OSBOOL *object_p,
00236 ASN1TagType tagging, int length);
00237
00261 EXTERNBER int xd_integer (OSCTXT *pctxt, OSINT32 *object_p,
00262 ASN1TagType tagging, int length);
00263
00281 EXTERNBER int xd_int8 (OSCTXT *pctxt, OSINT8 *object_p,
00282 ASN1TagType tagging, int length);
00283
00301 EXTERNBER int xd_int16 (OSCTXT *pctxt, OSINT16 *object_p,
00302 ASN1TagType tagging, int length);
00303
00328 EXTERNBER int xd_unsigned (OSCTXT *pctxt, OSUINT32 *object_p,
00329 ASN1TagType tagging, int length);
00330
00349 EXTERNBER int xd_uint8 (OSCTXT *pctxt, OSUINT8 *object_p,
00350 ASN1TagType tagging, int length);
00351
00370 EXTERNBER int xd_uint16 (OSCTXT *pctxt, OSUINT16 *object_p,
00371 ASN1TagType tagging, int length);
00372
00393 EXTERNBER int xd_int64 (OSCTXT *pctxt, OSINT64 *object_p,
00394 ASN1TagType tagging, int length);
00395
00417 EXTERNBER int xd_uint64 (OSCTXT *pctxt, OSUINT64 *object_p,
00418 ASN1TagType tagging, int length);
00419
00449 EXTERNBER int xd_bigint (OSCTXT *pctxt, const char** object_p,
00450 ASN1TagType tagging, int length);
00451
00479 EXTERNBER int xd_bitstr_s (OSCTXT *pctxt, OSOCTET* object_p,
00480 OSUINT32* numbits_p, ASN1TagType tagging,
00481 int length);
00482
00505 EXTERNBER int xd_bitstr (OSCTXT *pctxt, const OSOCTET** object_p2,
00506 OSUINT32* numbits_p, ASN1TagType tagging, int length);
00507
00527 EXTERNBER int xd_octstr_s (OSCTXT *pctxt, OSOCTET* object_p,
00528 OSUINT32* pnumocts, ASN1TagType tagging,
00529 int length);
00530
00550 EXTERNBER int xd_octstr (OSCTXT *pctxt, const OSOCTET** object_p2,
00551 OSUINT32* pnumocts, ASN1TagType tagging, int length);
00552
00574 EXTERNBER int xd_charstr (OSCTXT* pctxt, const char** object_p,
00575 ASN1TagType tagging, ASN1TAG tag, int length);
00576
00597 EXTERNBER int berDecCharArray (OSCTXT* pctxt, char* charArray,
00598 OSSIZE arraySize, ASN1TagType tagging,
00599 ASN1TAG tag, int length);
00600
00621 #define xd_utf8str(pctxt,object_p,tagging,length) \
00622 xd_charstr (pctxt, (const char**)object_p, tagging, ASN_ID_UTF8String, length)
00623
00646 EXTERNBER int xd_16BitCharStr (OSCTXT* pctxt, Asn116BitCharString* object_p,
00647 ASN1TagType tagging, ASN1TAG tag, int length);
00648
00671 EXTERNBER int xd_32BitCharStr (OSCTXT* pctxt, Asn132BitCharString* object_p,
00672 ASN1TagType tagging, ASN1TAG tag, int length);
00673
00688 EXTERNBER int xd_null (OSCTXT *pctxt, ASN1TagType tagging);
00689
00706 EXTERNBER int xd_objid (OSCTXT *pctxt, ASN1OBJID *object_p,
00707 ASN1TagType tagging, int length);
00708
00726 EXTERNBER int xd_oid64 (OSCTXT *pctxt, ASN1OID64 *object_p,
00727 ASN1TagType tagging, int length);
00728
00745 EXTERNBER int xd_reloid (OSCTXT *pctxt, ASN1OBJID *object_p,
00746 ASN1TagType tagging, int length);
00747
00763 EXTERNBER int xd_real (OSCTXT *pctxt, OSREAL *object_p,
00764 ASN1TagType tagging, int length);
00765
00781 EXTERNBER int xd_enum (OSCTXT *pctxt, OSINT32 *object_p,
00782 ASN1TagType tagging, int length);
00783
00799 EXTERNBER int xd_enumUnsigned (OSCTXT *pctxt, OSUINT32 *object_p,
00800 ASN1TagType tagging, int length);
00801
00817 EXTERNBER int xd_OpenType (OSCTXT *pctxt, const OSOCTET** object_p2,
00818 OSUINT32* pnumocts);
00819
00840 EXTERNBER int xd_OpenTypeExt (OSCTXT* pctxt, ASN1CCB* ccb_p, ASN1TAG* tags,
00841 int tagCount, OSRTDList *pElemList);
00842
00855 EXTERNBER int xd_OpenTypeAppend (OSCTXT *pctxt, OSRTDList *pElemList);
00856
00872 EXTERNBER int xd_real10 (OSCTXT *pctxt, const char** object_p,
00873 ASN1TagType tagging, int length);
00874
00905 EXTERNBER int xd_setp (OSCTXT *pctxt, const OSOCTET* msg_p,
00906 int msglen, ASN1TAG *tag_p, int *len_p);
00907
00915 EXTERNBER int xd_indeflen_ex (const OSOCTET* msg_p, int bufSize);
00916
00917
00918 #define xd_indeflen(m) xd_indeflen_ex(m, INT_MAX)
00919
00931 EXTERNBER int xd_len (OSCTXT *pctxt, int *len_p);
00932
00947 EXTERNBER int xd_chkend (OSCTXT *pctxt, ASN1CCB* ccb_p);
00948
00960 EXTERNBER int xd_count (OSCTXT *pctxt, int length, int *count_p);
00961
00970 EXTERNBER int xd_NextElement (OSCTXT* pctxt);
00971
00986 EXTERNBER int xd_Tag1AndLen (OSCTXT* pctxt, OSINT32* len_p);
00987
00988
01003 EXTERNBER int xd_memcpy (OSCTXT* pctxt, OSOCTET *object_p, int length) ;
01004
01023 EXTERNBER int xd_match1 (OSCTXT *pctxt, OSOCTET tag, int *len_p);
01024
01025
01028
01029
01065 EXTERNBER int xdf_tag (FILE* fp, ASN1TAG* ptag, OSOCTET* buffer, int* pbufidx);
01066
01085 EXTERNBER int xdf_len (FILE* fp, OSINT32* plen, OSOCTET* buffer, int* pbufidx);
01086
01107 EXTERNBER int xdf_TagAndLen (FILE* fp, ASN1TAG* ptag, OSINT32* plen,
01108 OSOCTET* buffer, int* pbufidx);
01109
01131 EXTERNBER int xdf_ReadPastEOC (FILE* fp, OSOCTET* buffer,
01132 int bufsiz, int* pbufidx);
01133
01157 EXTERNBER int xdf_ReadContents (FILE* fp, int len, OSOCTET* buffer,
01158 int bufsiz, int* pbufidx);
01163
01211 EXTERNBER int xe_tag_len (OSCTXT *pctxt, ASN1TAG tag, int length) ;
01212
01236 EXTERNBER int xe_boolean (OSCTXT* pctxt, OSBOOL* object_p,
01237 ASN1TagType tagging);
01238
01259 EXTERNBER int xe_integer (OSCTXT* pctxt, int *object_p, ASN1TagType tagging);
01260
01282 EXTERNBER int xe_unsigned (OSCTXT* pctxt, OSUINT32 *object_p,
01283 ASN1TagType tagging);
01284
01305 EXTERNBER int xe_int8 (OSCTXT* pctxt, OSINT8 *object_p, ASN1TagType tagging);
01306
01327 EXTERNBER int xe_int16 (OSCTXT* pctxt, OSINT16 *object_p, ASN1TagType tagging);
01328
01351 EXTERNBER int xe_int64 (OSCTXT* pctxt, OSINT64 *object_p,
01352 ASN1TagType tagging);
01353
01377 EXTERNBER int xe_uint64 (OSCTXT* pctxt, OSUINT64 *object_p,
01378 ASN1TagType tagging);
01379
01401 EXTERNBER int xe_uint8 (OSCTXT* pctxt, OSUINT8 *object_p, ASN1TagType tagging);
01402
01424 EXTERNBER int xe_uint16 (OSCTXT* pctxt, OSUINT16 *object_p, ASN1TagType tagging);
01425
01452 EXTERNBER int xe_bigint (OSCTXT* pctxt, const char* object_p,
01453 ASN1TagType tagging);
01454
01476 EXTERNBER int xe_bitstr (OSCTXT* pctxt, const OSOCTET* object_p,
01477 OSUINT32 numbits, ASN1TagType tagging);
01478
01501 EXTERNBER int xe_octstr (OSCTXT* pctxt, const OSOCTET* object_p,
01502 OSUINT32 numocts, ASN1TagType tagging);
01503
01530 EXTERNBER int xe_charstr (OSCTXT* pctxt, const char* object_p,
01531 ASN1TagType tagging, ASN1TAG tag);
01532
01552 #define xe_utf8str(pctxt,object_p,tagging) \
01553 xe_charstr (pctxt, (const char*)object_p, tagging, ASN_ID_UTF8String)
01554
01584 EXTERNBER int xe_16BitCharStr (OSCTXT* pctxt, Asn116BitCharString* object_p,
01585 ASN1TagType tagging, ASN1TAG tag);
01586
01616 EXTERNBER int xe_32BitCharStr (OSCTXT* pctxt, Asn132BitCharString* object_p,
01617 ASN1TagType tagging, ASN1TAG tag);
01618
01635 EXTERNBER int xe_null (OSCTXT* pctxt, ASN1TagType tagging);
01636
01654 EXTERNBER int xe_objid (OSCTXT* pctxt, ASN1OBJID *object_p,
01655 ASN1TagType tagging);
01656
01675 EXTERNBER int xe_oid64 (OSCTXT* pctxt, ASN1OID64 *object_p,
01676 ASN1TagType tagging);
01677
01695 EXTERNBER int xe_reloid (OSCTXT* pctxt, ASN1OBJID *object_p,
01696 ASN1TagType tagging);
01697
01718 EXTERNBER int xe_enum (OSCTXT* pctxt, OSINT32 *object_p, ASN1TagType tagging);
01719
01740 EXTERNBER int xe_enumUnsigned (OSCTXT* pctxt, OSUINT32 *object_p,
01741 ASN1TagType tagging);
01742
01767 EXTERNBER int xe_real (OSCTXT* pctxt, OSREAL *object_p, ASN1TagType tagging);
01768
01788 EXTERNBER int xe_OpenType (OSCTXT* pctxt, const OSOCTET* object_p,
01789 OSUINT32 numocts);
01790
01797 EXTERNBER int xe_OpenTypeExt (OSCTXT* pctxt, OSRTDList* pElemList);
01798
01817 EXTERNBER int xe_real10 (OSCTXT *pctxt, const char* object_p,
01818 ASN1TagType tagging);
01819
01838 EXTERNBER int xe_derReal10 (OSCTXT *pctxt, const char* object_p,
01839 ASN1TagType tagging);
01840
01858 EXTERNBER int xe_setp (OSCTXT* pctxt, OSOCTET *buf_p, int bufsiz);
01859
01873 EXTERNBER OSOCTET* xe_getp (OSCTXT* pctxt);
01874
01892 EXTERNBER void xe_free (OSCTXT* pctxt);
01893
01917 EXTERNBER int xe_expandBuffer (OSCTXT *pctxt, size_t length);
01918
01939 EXTERNBER int xe_memcpy (OSCTXT *pctxt, const OSOCTET* object_p,
01940 size_t length) ;
01941
01954 EXTERNBER int xe_len (OSCTXT *pctxt, int length) ;
01955
01974 EXTERNBER int xe_derCanonicalSort (OSCTXT* pctxt, OSRTSList* pList);
01975
01991 EXTERNBER int xe_TagAndIndefLen (OSCTXT *pctxt, ASN1TAG tag, int length) ;
01992
02000 EXTERNBER void xe_getBufLocDescr (OSCTXT *pctxt, OSUINT32 length,
02001 Asn1BufLocDescr* pDescr);
02002
02022 EXTERNBER int derEncBitString
02023 (OSCTXT* pctxt, const OSOCTET* pvalue, OSUINT32 numbits,
02024 ASN1TagType tagging);
02025
02028
02029
02052 EXTERNBER int berDefToIndefLen (OSCTXT *pSrcCtxt, OSCTXT *pDstCtxt);
02053
02064 EXTERNBER int berIndefToDefLen (OSCTXT *pSrcCtxt, OSCTXT *pDstCtxt);
02065
02073 EXTERNBER OSBOOL berErrAddTagParm (OSCTXT* pctxt, ASN1TAG tag);
02074
02075
02076
02077 #define xu_addTagErrParm berErrAddTagParm
02078
02088 EXTERNBER int berErrUnexpTag (OSCTXT* pctxt, ASN1TAG exptag);
02089
02094 EXTERNBER int berGetLibVersion (OSVOIDARG);
02095
02101 EXTERNBER const char *berGetLibInfo (OSVOIDARG);
02102
02121 EXTERNBER int berParseTagLen
02122 (const OSOCTET* buffer, size_t bufidx, size_t bufsiz,
02123 ASN1TAG* ptag, size_t* plen);
02124
02134 EXTERNBER const char* berTagToString
02135 (ASN1TAG tag, char* buffer, size_t bufsiz);
02136
02147 EXTERNBER const char* berTagToDynStr (OSCTXT* pctxt, ASN1TAG tag);
02148
02149 EXTERNBER int xu_verify_len (OSOCTET *msg_p);
02150 EXTERNBER void *xu_parse_mmbuf (
02151 OSOCTET **buf_p2, int *buflen_p, OSOCTET *start_p, int bufsiz);
02152
02176 EXTERNBER void xu_alloc_array (
02177 OSCTXT* pctxt, ASN1SeqOf* seqOf_p, int recSize, int recCount);
02178
02179 EXTERNBER void xu_octscpy_s (
02180 OSUINT32* nocts_p, OSOCTET *data_p, char *cstr, char zterm);
02181
02182 EXTERNBER void xu_octscpy_ss (ASN1OctStr *octStr_p, char *cstring, char zterm);
02183
02184 EXTERNBER void xu_octscpy_d (
02185 OSCTXT* pctxt, OSUINT32* nocts_p, const OSOCTET** data_p2,
02186 char* cstring, char zterm);
02187
02188 EXTERNBER void xu_octscpy_ds (
02189 OSCTXT* pctxt, ASN1DynOctStr *octStr_p, char *cstring, char zterm);
02190
02191 EXTERNBER void xu_octmcpy_s (ASN1OctStr *octStr_p, void* data_p, int datalen);
02192
02193 EXTERNBER void xu_octmcpy_d (
02194 OSCTXT* pctxt, ASN1DynOctStr *octStr_p, void* data_p, int datalen);
02195
02196 EXTERNBER char* xu_fetchstr (int numocts, char *data);
02197
02198 EXTERNBER int xu_hexstrcpy (char *data, char *hstring);
02199 EXTERNBER int xu_binstrcpy (char *data, char *bstring);
02200
02226 EXTERNBER int xu_dump (const OSOCTET *msgptr, ASN1DumpCbFunc cb, void* cbArg_p);
02227
02239 EXTERNBER int xu_fdump (FILE *file_p, const OSOCTET *msgptr);
02240
02256 #define xu_hex_dump(msg,numoct,hdr) rtxHexDump(msg,numoct)
02257
02278 EXTERNBER int xu_dump2 (OSCTXT *pctxt, const OSOCTET *msgptr);
02279
02280 EXTERNBER void xu_fmt_tag (
02281 ASN1TAG *tag_p, char *class_p, char *form_p, char *id_code);
02282
02283 EXTERNBER char* xu_fmt_tag2 (ASN1TAG *tag_p, char* bufp);
02284
02285 EXTERNBER char* xu_fmt_contents (OSCTXT* pctxt, int len, int *count);
02286
02287 EXTERNBER int xu_fread (FILE* fp, OSOCTET* bufp, int bufsiz);
02288
02295 EXTERNBER void xu_SaveBufferState (OSCTXT* pCtxt, OSRTBufSave* pSavedInfo);
02296
02304 EXTERNBER void xu_RestoreBufferState (OSCTXT* pCtxt, OSRTBufSave* pSavedInfo);
02305
02309
02310
02311
02312 #define XD_MEMCPY1(pctxt, object_p) \
02313 ((ASN1BUF_INDEFLEN(pctxt) || \
02314 ((pctxt)->buffer.byteIndex < (pctxt)->buffer.size)) ? \
02315 (*object_p = *OSRTBUFPTR(pctxt), (pctxt)->buffer.byteIndex ++, 0) : \
02316 RTERR_ENDOFBUF)
02317
02318
02319
02320
02321 #define XD_FETCH1(pctxt) ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex++])
02322
02323
02324
02325
02326 #define XD_PEEKTAG(pctxt, tag) \
02327 (((pctxt)->buffer.data[(pctxt)->buffer.byteIndex] & (~0x20)) == (tag & (~0x20)))
02328
02329
02330
02331
02332 #define XD_PEEKPC(pctxt) \
02333 (((pctxt)->buffer.data[(pctxt)->buffer.byteIndex] & 0x20) == 0x20)
02334
02335
02336
02337 #define XD_MATCHEOC(pctxt) \
02338 ( ( (pctxt)->buffer.byteIndex + 2 <= (pctxt)->buffer.size ) && \
02339 ( (pctxt)->buffer.data[(pctxt)->buffer.byteIndex] == 0 ) && \
02340 ( (pctxt)->buffer.data[(pctxt)->buffer.byteIndex + 1] == 0 ) )
02341
02342
02343
02344 #define XD_MATCHBYTES1(pctxt, b1) \
02345 ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex] == b1)
02346
02347 #define XD_MATCHBYTES2(pctxt, b1, b2) \
02348 (((pctxt)->buffer.data[(pctxt)->buffer.byteIndex] == b1) && \
02349 ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex+1] == b2))
02350
02351 #define XD_MATCHBYTES3(pctxt, b1, b2, b3) \
02352 (((pctxt)->buffer.data[(pctxt)->buffer.byteIndex] == b1) && \
02353 ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex+1] == b2) && \
02354 ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex+2] == b3))
02355
02356 #define XD_MATCHBYTES4(pctxt, b1, b2, b3, b4) \
02357 (((pctxt)->buffer.data[(pctxt)->buffer.byteIndex] == b1) && \
02358 ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex+1] == b2) && \
02359 ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex+2] == b3) && \
02360 ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex+3] == b4))
02361
02362 #define XD_MATCHBYTES5(pctxt, b1, b2, b3, b4, b5) \
02363 (((pctxt)->buffer.data[(pctxt)->buffer.byteIndex] == b1) && \
02364 ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex+1] == b2) && \
02365 ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex+2] == b3) && \
02366 ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex+3] == b4) && \
02367 ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex+4] == b5))
02368
02369
02370
02371
02372 #define XD_BUMPIDX(pctxt, nbytes) ((pctxt)->buffer.byteIndex += nbytes)
02373
02374
02375
02376 #define XD_CHKBUFEND(pctxt) \
02377 (((ASN1BUF_INDEFLEN(pctxt)) || \
02378 ((pctxt)->buffer.byteIndex <= (pctxt)->buffer.size)) ? 0 : RTERR_ENDOFBUF)
02379
02380
02381
02382
02383
02384 #define XD_CHKDEFLEN(pctxt,len) \
02385 (((ASN1BUF_INDEFLEN(pctxt)) || \
02386 (((pctxt)->buffer.byteIndex + len) <= (pctxt)->buffer.size)) ? \
02387 0 : RTERR_ENDOFBUF)
02388
02389
02390
02391 #define XD_CHKEOB(pctxt) \
02392 (((pctxt)->buffer.byteIndex + 2 > (pctxt)->buffer.size) ? TRUE : \
02393 (((pctxt)->buffer.data[(pctxt)->buffer.byteIndex] == 0 && \
02394 (pctxt)->buffer.data[(pctxt)->buffer.byteIndex + 1] == 0 ) ? \
02395 TRUE : FALSE))
02396
02397
02398
02399 #define XD_CHKEND(pctxt,ccb_p) \
02400 (((ccb_p)->len == ASN_K_INDEFLEN) ? XD_CHKEOB(pctxt) : \
02401 ((OSRTBUFPTR(pctxt) - (ccb_p)->ptr >= (ccb_p)->len) || \
02402 ((pctxt)->buffer.byteIndex >= (pctxt)->buffer.size)))
02403
02404
02405
02406
02407 #define XE_CHKBUF(pctxt,len) \
02408 if (len > (pctxt)->buffer.byteIndex) { \
02409 int xstat = xe_expandBuffer (pctxt, len); \
02410 if (xstat != 0) return xstat; }
02411
02412
02413
02414
02415 #define XE_PUT1(pctxt,ch) \
02416 (pctxt)->buffer.data[--(pctxt)->buffer.byteIndex] = ch;
02417
02418
02419
02420
02421 #define XE_PUT2(pctxt,ch1,ch2) \
02422 (pctxt)->buffer.byteIndex -= 2; \
02423 (pctxt)->buffer.data[(pctxt)->buffer.byteIndex] = ch1; \
02424 (pctxt)->buffer.data[(pctxt)->buffer.byteIndex+1] = ch2;
02425
02426
02427
02428
02429
02430
02431 #define XE_SAFEPUT1(pctxt,ch) \
02432 XE_CHKBUF(pctxt,1); (pctxt)->buffer.data[--(pctxt)->buffer.byteIndex] = ch;
02433
02434 #ifdef __cplusplus
02435 }
02436 #endif
02437
02438 #endif