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
00036
00084 #ifndef _ASN1BER_H_
00085 #define _ASN1BER_H_
00086
00087 #include "rtsrc/asn1type.h"
00088
00089 #define ASN_K_INDEFLEN -9999
00090
00091 #define XU_DUMP(msg) xu_dump(msg,0,0)
00092 #define xd_resetp(pctxt) rtxResetContext(pctxt)
00093
00094 #define ASN1TAG2BYTE(tag) \
00095 ((OSOCTET)(((tag)&TM_B_IDCODE)|((tag)>>ASN1TAG_LSHIFT)))
00096
00101 typedef struct _Asn1BufLocDescr {
00102 OSUINT32 numocts;
00103 OSINT32 offset;
00104 } Asn1BufLocDescr;
00105
00106 #ifdef __cplusplus
00107 extern "C" {
00108
00109 #endif
00110
00111 #ifndef EXTERNBER
00112 #ifdef BUILDASN1BERDLL
00113 #define EXTERNBER __declspec(dllexport)
00114 #elif defined (USEASN1BERDLL)
00115 #define EXTERNBER __declspec(dllimport)
00116 #else
00117 #define EXTERNBER
00118 #endif
00119 #endif
00120
00121
00154 EXTERNBER int xd_tag (OSCTXT* pctxt, ASN1TAG *tag_p);
00155
00176 EXTERNBER int xd_tag_len (OSCTXT *pctxt, ASN1TAG *tag_p,
00177 int *len_p, OSOCTET flags);
00178
00203 EXTERNBER int xd_match (OSCTXT *pctxt, ASN1TAG tag,
00204 int *len_p, OSOCTET flags);
00205
00231 EXTERNBER int xd_boolean (OSCTXT *pctxt, OSBOOL *object_p,
00232 ASN1TagType tagging, int length);
00233
00257 EXTERNBER int xd_integer (OSCTXT *pctxt, OSINT32 *object_p,
00258 ASN1TagType tagging, int length);
00259
00277 EXTERNBER int xd_int8 (OSCTXT *pctxt, OSINT8 *object_p,
00278 ASN1TagType tagging, int length);
00279
00297 EXTERNBER int xd_int16 (OSCTXT *pctxt, OSINT16 *object_p,
00298 ASN1TagType tagging, int length);
00299
00324 EXTERNBER int xd_unsigned (OSCTXT *pctxt, OSUINT32 *object_p,
00325 ASN1TagType tagging, int length);
00326
00345 EXTERNBER int xd_uint8 (OSCTXT *pctxt, OSUINT8 *object_p,
00346 ASN1TagType tagging, int length);
00347
00366 EXTERNBER int xd_uint16 (OSCTXT *pctxt, OSUINT16 *object_p,
00367 ASN1TagType tagging, int length);
00368
00389 EXTERNBER int xd_int64 (OSCTXT *pctxt, OSINT64 *object_p,
00390 ASN1TagType tagging, int length);
00391
00413 EXTERNBER int xd_uint64 (OSCTXT *pctxt, OSUINT64 *object_p,
00414 ASN1TagType tagging, int length);
00415
00443 EXTERNBER int xd_bigint (OSCTXT *pctxt, const char** object_p,
00444 ASN1TagType tagging, int length);
00445
00473 EXTERNBER int xd_bitstr_s (OSCTXT *pctxt, OSOCTET* object_p,
00474 OSUINT32* numbits_p, ASN1TagType tagging,
00475 int length);
00476
00499 EXTERNBER int xd_bitstr (OSCTXT *pctxt, const OSOCTET** object_p2,
00500 OSUINT32* numbits_p, ASN1TagType tagging, int length);
00501
00521 EXTERNBER int xd_octstr_s (OSCTXT *pctxt, OSOCTET* object_p,
00522 OSUINT32* pnumocts, ASN1TagType tagging,
00523 int length);
00524
00544 EXTERNBER int xd_octstr (OSCTXT *pctxt, const OSOCTET** object_p2,
00545 OSUINT32* pnumocts, ASN1TagType tagging, int length);
00546
00568 EXTERNBER int xd_charstr (OSCTXT* pctxt, const char** object_p,
00569 ASN1TagType tagging, ASN1TAG tag, int length);
00570
00591 EXTERNBER int berDecCharArray (OSCTXT* pctxt, char* charArray,
00592 OSSIZE arraySize, ASN1TagType tagging,
00593 ASN1TAG tag, int length);
00594
00615 #define xd_utf8str(pctxt,object_p,tagging,length) \
00616 xd_charstr (pctxt, (const char**)object_p, tagging, ASN_ID_UTF8String, length)
00617
00640 EXTERNBER int xd_16BitCharStr (OSCTXT* pctxt, Asn116BitCharString* object_p,
00641 ASN1TagType tagging, ASN1TAG tag, int length);
00642
00665 EXTERNBER int xd_32BitCharStr (OSCTXT* pctxt, Asn132BitCharString* object_p,
00666 ASN1TagType tagging, ASN1TAG tag, int length);
00667
00682 EXTERNBER int xd_null (OSCTXT *pctxt, ASN1TagType tagging);
00683
00700 EXTERNBER int xd_objid (OSCTXT *pctxt, ASN1OBJID *object_p,
00701 ASN1TagType tagging, int length);
00702
00720 EXTERNBER int xd_oid64 (OSCTXT *pctxt, ASN1OID64 *object_p,
00721 ASN1TagType tagging, int length);
00722
00739 EXTERNBER int xd_reloid (OSCTXT *pctxt, ASN1OBJID *object_p,
00740 ASN1TagType tagging, int length);
00741
00757 EXTERNBER int xd_real (OSCTXT *pctxt, OSREAL *object_p,
00758 ASN1TagType tagging, int length);
00759
00775 EXTERNBER int xd_enum (OSCTXT *pctxt, OSINT32 *object_p,
00776 ASN1TagType tagging, int length);
00777
00793 EXTERNBER int xd_enumUnsigned (OSCTXT *pctxt, OSUINT32 *object_p,
00794 ASN1TagType tagging, int length);
00795
00811 EXTERNBER int xd_OpenType (OSCTXT *pctxt, const OSOCTET** object_p2,
00812 OSUINT32* pnumocts);
00813
00833 EXTERNBER int xd_OpenTypeExt (OSCTXT* pctxt, ASN1CCB* ccb_p, ASN1TAG tag,
00834 OSRTDList *pElemList);
00835
00848 EXTERNBER int xd_OpenTypeAppend (OSCTXT *pctxt, OSRTDList *pElemList);
00849
00865 EXTERNBER int xd_real10 (OSCTXT *pctxt, const char** object_p,
00866 ASN1TagType tagging, int length);
00867
00898 EXTERNBER int xd_setp (OSCTXT *pctxt, const OSOCTET* msg_p,
00899 int msglen, ASN1TAG *tag_p, int *len_p);
00900
00908 EXTERNBER int xd_indeflen_ex (const OSOCTET* msg_p, int bufSize);
00909
00910
00911 #define xd_indeflen(m) xd_indeflen_ex(m, INT_MAX)
00912
00924 EXTERNBER int xd_len (OSCTXT *pctxt, int *len_p);
00925
00940 EXTERNBER int xd_chkend (OSCTXT *pctxt, ASN1CCB* ccb_p);
00941
00953 EXTERNBER int xd_count (OSCTXT *pctxt, int length, int *count_p);
00954
00963 EXTERNBER int xd_NextElement (OSCTXT* pctxt);
00964
00979 EXTERNBER int xd_Tag1AndLen (OSCTXT* pctxt, OSINT32* len_p);
00980
00981
00996 EXTERNBER int xd_memcpy (OSCTXT* pctxt, OSOCTET *object_p, int length) ;
00997
01016 EXTERNBER int xd_match1 (OSCTXT *pctxt, OSOCTET tag, int *len_p);
01017
01018
01021
01022
01058 EXTERNBER int xdf_tag (FILE* fp, ASN1TAG* ptag, OSOCTET* buffer, int* pbufidx);
01059
01078 EXTERNBER int xdf_len (FILE* fp, OSINT32* plen, OSOCTET* buffer, int* pbufidx);
01079
01100 EXTERNBER int xdf_TagAndLen (FILE* fp, ASN1TAG* ptag, OSINT32* plen,
01101 OSOCTET* buffer, int* pbufidx);
01102
01124 EXTERNBER int xdf_ReadPastEOC (FILE* fp, OSOCTET* buffer,
01125 int bufsiz, int* pbufidx);
01126
01150 EXTERNBER int xdf_ReadContents (FILE* fp, int len, OSOCTET* buffer,
01151 int bufsiz, int* pbufidx);
01156
01204 EXTERNBER int xe_tag_len (OSCTXT *pctxt, ASN1TAG tag, int length) ;
01205
01229 EXTERNBER int xe_boolean (OSCTXT* pctxt, OSBOOL* object_p,
01230 ASN1TagType tagging);
01231
01252 EXTERNBER int xe_integer (OSCTXT* pctxt, int *object_p, ASN1TagType tagging);
01253
01275 EXTERNBER int xe_unsigned (OSCTXT* pctxt, OSUINT32 *object_p,
01276 ASN1TagType tagging);
01277
01298 EXTERNBER int xe_int8 (OSCTXT* pctxt, OSINT8 *object_p, ASN1TagType tagging);
01299
01320 EXTERNBER int xe_int16 (OSCTXT* pctxt, OSINT16 *object_p, ASN1TagType tagging);
01321
01344 EXTERNBER int xe_int64 (OSCTXT* pctxt, OSINT64 *object_p,
01345 ASN1TagType tagging);
01346
01370 EXTERNBER int xe_uint64 (OSCTXT* pctxt, OSUINT64 *object_p,
01371 ASN1TagType tagging);
01372
01394 EXTERNBER int xe_uint8 (OSCTXT* pctxt, OSUINT8 *object_p, ASN1TagType tagging);
01395
01417 EXTERNBER int xe_uint16 (OSCTXT* pctxt, OSUINT16 *object_p, ASN1TagType tagging);
01418
01444 EXTERNBER int xe_bigint (OSCTXT* pctxt, const char* object_p,
01445 ASN1TagType tagging);
01446
01468 EXTERNBER int xe_bitstr (OSCTXT* pctxt, const OSOCTET* object_p,
01469 OSUINT32 numbits, ASN1TagType tagging);
01470
01493 EXTERNBER int xe_octstr (OSCTXT* pctxt, const OSOCTET* object_p,
01494 OSUINT32 numocts, ASN1TagType tagging);
01495
01522 EXTERNBER int xe_charstr (OSCTXT* pctxt, const char* object_p,
01523 ASN1TagType tagging, ASN1TAG tag);
01524
01544 #define xe_utf8str(pctxt,object_p,tagging) \
01545 xe_charstr (pctxt, (const char*)object_p, tagging, ASN_ID_UTF8String)
01546
01576 EXTERNBER int xe_16BitCharStr (OSCTXT* pctxt, Asn116BitCharString* object_p,
01577 ASN1TagType tagging, ASN1TAG tag);
01578
01608 EXTERNBER int xe_32BitCharStr (OSCTXT* pctxt, Asn132BitCharString* object_p,
01609 ASN1TagType tagging, ASN1TAG tag);
01610
01627 EXTERNBER int xe_null (OSCTXT* pctxt, ASN1TagType tagging);
01628
01646 EXTERNBER int xe_objid (OSCTXT* pctxt, ASN1OBJID *object_p,
01647 ASN1TagType tagging);
01648
01667 EXTERNBER int xe_oid64 (OSCTXT* pctxt, ASN1OID64 *object_p,
01668 ASN1TagType tagging);
01669
01687 EXTERNBER int xe_reloid (OSCTXT* pctxt, ASN1OBJID *object_p,
01688 ASN1TagType tagging);
01689
01710 EXTERNBER int xe_enum (OSCTXT* pctxt, OSINT32 *object_p, ASN1TagType tagging);
01711
01732 EXTERNBER int xe_enumUnsigned (OSCTXT* pctxt, OSUINT32 *object_p,
01733 ASN1TagType tagging);
01734
01759 EXTERNBER int xe_real (OSCTXT* pctxt, OSREAL *object_p, ASN1TagType tagging);
01760
01780 EXTERNBER int xe_OpenType (OSCTXT* pctxt, const OSOCTET* object_p,
01781 OSUINT32 numocts);
01782
01789 EXTERNBER int xe_OpenTypeExt (OSCTXT* pctxt, OSRTDList* pElemList);
01790
01809 EXTERNBER int xe_real10 (OSCTXT *pctxt, const char* object_p,
01810 ASN1TagType tagging);
01811
01830 EXTERNBER int xe_derReal10 (OSCTXT *pctxt, const char* object_p,
01831 ASN1TagType tagging);
01832
01850 EXTERNBER int xe_setp (OSCTXT* pctxt, OSOCTET *buf_p, int bufsiz);
01851
01865 EXTERNBER OSOCTET* xe_getp (OSCTXT* pctxt);
01866
01884 EXTERNBER void xe_free (OSCTXT* pctxt);
01885
01909 EXTERNBER int xe_expandBuffer (OSCTXT *pctxt, size_t length);
01910
01931 EXTERNBER int xe_memcpy (OSCTXT *pctxt, const OSOCTET* object_p,
01932 size_t length) ;
01933
01947 EXTERNBER int xe_len (OSCTXT *pctxt, int length) ;
01948
01967 EXTERNBER int xe_derCanonicalSort (OSCTXT* pctxt, OSRTSList* pList);
01968
01984 EXTERNBER int xe_TagAndIndefLen (OSCTXT *pctxt, ASN1TAG tag, int length) ;
01985
01993 EXTERNBER void xe_getBufLocDescr (OSCTXT *pctxt, OSUINT32 length,
01994 Asn1BufLocDescr* pDescr);
01995
02015 EXTERNBER int derEncBitString
02016 (OSCTXT* pctxt, const OSOCTET* pvalue, OSUINT32 numbits,
02017 ASN1TagType tagging);
02018
02021
02022
02045 EXTERNBER int berDefToIndefLen (OSCTXT *pSrcCtxt, OSCTXT *pDstCtxt);
02046
02057 EXTERNBER int berIndefToDefLen (OSCTXT *pSrcCtxt, OSCTXT *pDstCtxt);
02058
02066 EXTERNBER OSBOOL berErrAddTagParm (OSCTXT* pctxt, ASN1TAG tag);
02067
02068
02069
02070 #define xu_addTagErrParm berErrAddTagParm
02071
02081 EXTERNBER int berErrUnexpTag (OSCTXT* pctxt, ASN1TAG exptag);
02082
02087 EXTERNBER int berGetLibVersion ();
02088
02094 EXTERNBER const char *berGetLibInfo ();
02095
02114 EXTERNBER int berParseTagLen
02115 (const OSOCTET* buffer, size_t bufidx, size_t bufsize,
02116 ASN1TAG* ptag, size_t* plen);
02117
02127 EXTERNBER const char* berTagToString
02128 (ASN1TAG tag, char* buffer, size_t bufsiz);
02129
02140 EXTERNBER const char* berTagToDynStr (OSCTXT* pctxt, ASN1TAG tag);
02141
02142 EXTERNBER int xu_verify_len (OSOCTET *msg_p);
02143 EXTERNBER void *xu_parse_mmbuf (
02144 OSOCTET **buf_p2, int *buflen_p, OSOCTET *start_p, int bufsiz);
02145
02169 EXTERNBER void xu_alloc_array (
02170 OSCTXT* pctxt, ASN1SeqOf* seqOf_p, int recSize, int recCount);
02171
02172 EXTERNBER void xu_octscpy_s (
02173 OSUINT32* nocts_p, OSOCTET *data_p, char *cstr, char zterm);
02174
02175 EXTERNBER void xu_octscpy_ss (ASN1OctStr *octStr_p, char *cstring, char zterm);
02176
02177 EXTERNBER void xu_octscpy_d (
02178 OSCTXT* pctxt, OSUINT32* nocts_p, const OSOCTET** data_p2,
02179 char* cstring, char zterm);
02180
02181 EXTERNBER void xu_octscpy_ds (
02182 OSCTXT* pctxt, ASN1DynOctStr *octStr_p, char *cstring, char zterm);
02183
02184 EXTERNBER void xu_octmcpy_s (ASN1OctStr *octStr_p, void* data_p, int datalen);
02185
02186 EXTERNBER void xu_octmcpy_d (
02187 OSCTXT* pctxt, ASN1DynOctStr *octStr_p, void* data_p, int datalen);
02188
02189 EXTERNBER char* xu_fetchstr (int numocts, char *data);
02190
02191 EXTERNBER int xu_hexstrcpy (char *data, char *hstring);
02192 EXTERNBER int xu_binstrcpy (char *data, char *bstring);
02193
02219 EXTERNBER int xu_dump (const OSOCTET *msgptr, ASN1DumpCbFunc cb, void* cbArg_p);
02220
02232 EXTERNBER int xu_fdump (FILE *file_p, const OSOCTET *msgptr);
02233
02249 #define xu_hex_dump(msg,numoct,hdr) rtxHexDump(msg,numoct)
02250
02271 EXTERNBER int xu_dump2 (OSCTXT *pctxt, const OSOCTET *msgptr);
02272
02273 EXTERNBER void xu_fmt_tag (
02274 ASN1TAG *tag_p, char *class_p, char *form_p, char *id_code);
02275
02276 EXTERNBER char* xu_fmt_contents (OSCTXT* pctxt, int len, int *count);
02277
02278 EXTERNBER int xu_fread (FILE* fp, OSOCTET* bufp, int bufsiz);
02279
02286 EXTERNBER void xu_SaveBufferState (OSCTXT* pCtxt, OSRTBufSave* pSavedInfo);
02287
02295 EXTERNBER void xu_RestoreBufferState (OSCTXT* pCtxt, OSRTBufSave* pSavedInfo);
02296
02300
02301
02302
02303 #define XD_MEMCPY1(pctxt, object_p) \
02304 ((ASN1BUF_INDEFLEN(pctxt) || \
02305 ((pctxt)->buffer.byteIndex < (pctxt)->buffer.size)) ? \
02306 (*object_p = *OSRTBUFPTR(pctxt), (pctxt)->buffer.byteIndex ++, 0) : \
02307 RTERR_ENDOFBUF)
02308
02309
02310
02311
02312 #define XD_FETCH1(pctxt) ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex++])
02313
02314
02315
02316
02317 #define XD_PEEKTAG(pctxt, tag) \
02318 (((pctxt)->buffer.data[(pctxt)->buffer.byteIndex] & (~0x20)) == (tag & (~0x20)))
02319
02320
02321
02322
02323 #define XD_PEEKPC(pctxt) \
02324 (((pctxt)->buffer.data[(pctxt)->buffer.byteIndex] & 0x20) == 0x20)
02325
02326
02327
02328 #define XD_MATCHEOC(pctxt) \
02329 ( ( (pctxt)->buffer.byteIndex + 2 <= (pctxt)->buffer.size ) && \
02330 ( (pctxt)->buffer.data[(pctxt)->buffer.byteIndex] == 0 ) && \
02331 ( (pctxt)->buffer.data[(pctxt)->buffer.byteIndex + 1] == 0 ) )
02332
02333
02334
02335 #define XD_MATCHBYTES1(pctxt, b1) \
02336 ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex] == b1)
02337
02338 #define XD_MATCHBYTES2(pctxt, b1, b2) \
02339 (((pctxt)->buffer.data[(pctxt)->buffer.byteIndex] == b1) && \
02340 ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex+1] == b2))
02341
02342 #define XD_MATCHBYTES3(pctxt, b1, b2, b3) \
02343 (((pctxt)->buffer.data[(pctxt)->buffer.byteIndex] == b1) && \
02344 ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex+1] == b2) && \
02345 ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex+2] == b3))
02346
02347 #define XD_MATCHBYTES4(pctxt, b1, b2, b3, b4) \
02348 (((pctxt)->buffer.data[(pctxt)->buffer.byteIndex] == b1) && \
02349 ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex+1] == b2) && \
02350 ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex+2] == b3) && \
02351 ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex+3] == b4))
02352
02353 #define XD_MATCHBYTES5(pctxt, b1, b2, b3, b4, b5) \
02354 (((pctxt)->buffer.data[(pctxt)->buffer.byteIndex] == b1) && \
02355 ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex+1] == b2) && \
02356 ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex+2] == b3) && \
02357 ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex+3] == b4) && \
02358 ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex+4] == b5))
02359
02360
02361
02362
02363 #define XD_BUMPIDX(pctxt, nbytes) ((pctxt)->buffer.byteIndex += nbytes)
02364
02365
02366
02367 #define XD_CHKBUFEND(pctxt) \
02368 (((ASN1BUF_INDEFLEN(pctxt)) || \
02369 ((pctxt)->buffer.byteIndex <= (pctxt)->buffer.size)) ? 0 : RTERR_ENDOFBUF)
02370
02371
02372
02373
02374
02375 #define XD_CHKDEFLEN(pctxt,len) \
02376 (((ASN1BUF_INDEFLEN(pctxt)) || \
02377 (((pctxt)->buffer.byteIndex + len) <= (pctxt)->buffer.size)) ? \
02378 0 : RTERR_ENDOFBUF)
02379
02380
02381
02382 #define XD_CHKEOB(pctxt) \
02383 (((pctxt)->buffer.byteIndex + 2 > (pctxt)->buffer.size) ? TRUE : \
02384 (((pctxt)->buffer.data[(pctxt)->buffer.byteIndex] == 0 && \
02385 (pctxt)->buffer.data[(pctxt)->buffer.byteIndex + 1] == 0 ) ? \
02386 TRUE : FALSE))
02387
02388
02389
02390 #define XD_CHKEND(pctxt,ccb_p) \
02391 (((ccb_p)->len == ASN_K_INDEFLEN) ? XD_CHKEOB(pctxt) : \
02392 ((OSRTBUFPTR(pctxt) - (ccb_p)->ptr >= (ccb_p)->len) || \
02393 ((pctxt)->buffer.byteIndex >= (pctxt)->buffer.size)))
02394
02395
02396
02397
02398 #define XE_CHKBUF(pctxt,len) \
02399 if (len > (pctxt)->buffer.byteIndex) { \
02400 int xstat = xe_expandBuffer (pctxt, len); \
02401 if (xstat != 0) return xstat; }
02402
02403
02404
02405
02406 #define XE_PUT1(pctxt,ch) \
02407 (pctxt)->buffer.data[--(pctxt)->buffer.byteIndex] = ch;
02408
02409
02410
02411
02412 #define XE_PUT2(pctxt,ch1,ch2) \
02413 (pctxt)->buffer.byteIndex -= 2; \
02414 (pctxt)->buffer.data[(pctxt)->buffer.byteIndex] = ch1; \
02415 (pctxt)->buffer.data[(pctxt)->buffer.byteIndex+1] = ch2;
02416
02417
02418
02419
02420
02421
02422 #define XE_SAFEPUT1(pctxt,ch) \
02423 XE_CHKBUF(pctxt,1); (pctxt)->buffer.data[--(pctxt)->buffer.byteIndex] = ch;
02424
02425 #ifdef __cplusplus
02426 }
02427 #endif
02428
02429 #endif