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 #ifndef EXTERNBER
00110 #ifdef BUILDASN1BERDLL
00111 #define EXTERNBER __declspec(dllexport)
00112 #elif defined (USEASN1BERDLL)
00113 #define EXTERNBER __declspec(dllimport)
00114 #else
00115 #define EXTERNBER
00116 #endif
00117 #endif
00118
00119
00152 EXTERNBER int xd_tag (OSCTXT* pctxt, ASN1TAG *tag_p);
00153
00174 EXTERNBER int xd_tag_len (OSCTXT *pctxt, ASN1TAG *tag_p,
00175 int *len_p, OSOCTET flags);
00176
00201 EXTERNBER int xd_match (OSCTXT *pctxt, ASN1TAG tag,
00202 int *len_p, OSOCTET flags);
00203
00229 EXTERNBER int xd_boolean (OSCTXT *pctxt, OSBOOL *object_p,
00230 ASN1TagType tagging, int length);
00231
00255 EXTERNBER int xd_integer (OSCTXT *pctxt, OSINT32 *object_p,
00256 ASN1TagType tagging, int length);
00257
00275 EXTERNBER int xd_int8 (OSCTXT *pctxt, OSINT8 *object_p,
00276 ASN1TagType tagging, int length);
00277
00295 EXTERNBER int xd_int16 (OSCTXT *pctxt, OSINT16 *object_p,
00296 ASN1TagType tagging, int length);
00297
00322 EXTERNBER int xd_unsigned (OSCTXT *pctxt, OSUINT32 *object_p,
00323 ASN1TagType tagging, int length);
00324
00343 EXTERNBER int xd_uint8 (OSCTXT *pctxt, OSUINT8 *object_p,
00344 ASN1TagType tagging, int length);
00345
00364 EXTERNBER int xd_uint16 (OSCTXT *pctxt, OSUINT16 *object_p,
00365 ASN1TagType tagging, int length);
00366
00387 EXTERNBER int xd_int64 (OSCTXT *pctxt, OSINT64 *object_p,
00388 ASN1TagType tagging, int length);
00389
00411 EXTERNBER int xd_uint64 (OSCTXT *pctxt, OSUINT64 *object_p,
00412 ASN1TagType tagging, int length);
00413
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
00834 EXTERNBER int xd_OpenTypeExt (OSCTXT* pctxt, ASN1CCB* ccb_p, ASN1TAG* tags,
00835 int tagCount, OSRTDList *pElemList);
00836
00849 EXTERNBER int xd_OpenTypeAppend (OSCTXT *pctxt, OSRTDList *pElemList);
00850
00866 EXTERNBER int xd_real10 (OSCTXT *pctxt, const char** object_p,
00867 ASN1TagType tagging, int length);
00868
00899 EXTERNBER int xd_setp (OSCTXT *pctxt, const OSOCTET* msg_p,
00900 int msglen, ASN1TAG *tag_p, int *len_p);
00901
00909 EXTERNBER int xd_indeflen_ex (const OSOCTET* msg_p, int bufSize);
00910
00911
00912 #define xd_indeflen(m) xd_indeflen_ex(m, INT_MAX)
00913
00925 EXTERNBER int xd_len (OSCTXT *pctxt, int *len_p);
00926
00941 EXTERNBER int xd_chkend (OSCTXT *pctxt, ASN1CCB* ccb_p);
00942
00954 EXTERNBER int xd_count (OSCTXT *pctxt, int length, int *count_p);
00955
00964 EXTERNBER int xd_NextElement (OSCTXT* pctxt);
00965
00980 EXTERNBER int xd_Tag1AndLen (OSCTXT* pctxt, OSINT32* len_p);
00981
00982
00997 EXTERNBER int xd_memcpy (OSCTXT* pctxt, OSOCTET *object_p, int length) ;
00998
01017 EXTERNBER int xd_match1 (OSCTXT *pctxt, OSOCTET tag, int *len_p);
01018
01019
01022
01023
01059 EXTERNBER int xdf_tag (FILE* fp, ASN1TAG* ptag, OSOCTET* buffer, int* pbufidx);
01060
01079 EXTERNBER int xdf_len (FILE* fp, OSINT32* plen, OSOCTET* buffer, int* pbufidx);
01080
01101 EXTERNBER int xdf_TagAndLen (FILE* fp, ASN1TAG* ptag, OSINT32* plen,
01102 OSOCTET* buffer, int* pbufidx);
01103
01125 EXTERNBER int xdf_ReadPastEOC (FILE* fp, OSOCTET* buffer,
01126 int bufsiz, int* pbufidx);
01127
01151 EXTERNBER int xdf_ReadContents (FILE* fp, int len, OSOCTET* buffer,
01152 int bufsiz, int* pbufidx);
01157
01205 EXTERNBER int xe_tag_len (OSCTXT *pctxt, ASN1TAG tag, int length) ;
01206
01230 EXTERNBER int xe_boolean (OSCTXT* pctxt, OSBOOL* object_p,
01231 ASN1TagType tagging);
01232
01253 EXTERNBER int xe_integer (OSCTXT* pctxt, int *object_p, ASN1TagType tagging);
01254
01276 EXTERNBER int xe_unsigned (OSCTXT* pctxt, OSUINT32 *object_p,
01277 ASN1TagType tagging);
01278
01299 EXTERNBER int xe_int8 (OSCTXT* pctxt, OSINT8 *object_p, ASN1TagType tagging);
01300
01321 EXTERNBER int xe_int16 (OSCTXT* pctxt, OSINT16 *object_p, ASN1TagType tagging);
01322
01345 EXTERNBER int xe_int64 (OSCTXT* pctxt, OSINT64 *object_p,
01346 ASN1TagType tagging);
01347
01371 EXTERNBER int xe_uint64 (OSCTXT* pctxt, OSUINT64 *object_p,
01372 ASN1TagType tagging);
01373
01395 EXTERNBER int xe_uint8 (OSCTXT* pctxt, OSUINT8 *object_p, ASN1TagType tagging);
01396
01418 EXTERNBER int xe_uint16 (OSCTXT* pctxt, OSUINT16 *object_p, ASN1TagType tagging);
01419
01446 EXTERNBER int xe_bigint (OSCTXT* pctxt, const char* object_p,
01447 ASN1TagType tagging);
01448
01470 EXTERNBER int xe_bitstr (OSCTXT* pctxt, const OSOCTET* object_p,
01471 OSUINT32 numbits, ASN1TagType tagging);
01472
01495 EXTERNBER int xe_octstr (OSCTXT* pctxt, const OSOCTET* object_p,
01496 OSUINT32 numocts, ASN1TagType tagging);
01497
01524 EXTERNBER int xe_charstr (OSCTXT* pctxt, const char* object_p,
01525 ASN1TagType tagging, ASN1TAG tag);
01526
01546 #define xe_utf8str(pctxt,object_p,tagging) \
01547 xe_charstr (pctxt, (const char*)object_p, tagging, ASN_ID_UTF8String)
01548
01578 EXTERNBER int xe_16BitCharStr (OSCTXT* pctxt, Asn116BitCharString* object_p,
01579 ASN1TagType tagging, ASN1TAG tag);
01580
01610 EXTERNBER int xe_32BitCharStr (OSCTXT* pctxt, Asn132BitCharString* object_p,
01611 ASN1TagType tagging, ASN1TAG tag);
01612
01629 EXTERNBER int xe_null (OSCTXT* pctxt, ASN1TagType tagging);
01630
01648 EXTERNBER int xe_objid (OSCTXT* pctxt, ASN1OBJID *object_p,
01649 ASN1TagType tagging);
01650
01669 EXTERNBER int xe_oid64 (OSCTXT* pctxt, ASN1OID64 *object_p,
01670 ASN1TagType tagging);
01671
01689 EXTERNBER int xe_reloid (OSCTXT* pctxt, ASN1OBJID *object_p,
01690 ASN1TagType tagging);
01691
01712 EXTERNBER int xe_enum (OSCTXT* pctxt, OSINT32 *object_p, ASN1TagType tagging);
01713
01734 EXTERNBER int xe_enumUnsigned (OSCTXT* pctxt, OSUINT32 *object_p,
01735 ASN1TagType tagging);
01736
01761 EXTERNBER int xe_real (OSCTXT* pctxt, OSREAL *object_p, ASN1TagType tagging);
01762
01782 EXTERNBER int xe_OpenType (OSCTXT* pctxt, const OSOCTET* object_p,
01783 OSUINT32 numocts);
01784
01791 EXTERNBER int xe_OpenTypeExt (OSCTXT* pctxt, OSRTDList* pElemList);
01792
01811 EXTERNBER int xe_real10 (OSCTXT *pctxt, const char* object_p,
01812 ASN1TagType tagging);
01813
01832 EXTERNBER int xe_derReal10 (OSCTXT *pctxt, const char* object_p,
01833 ASN1TagType tagging);
01834
01852 EXTERNBER int xe_setp (OSCTXT* pctxt, OSOCTET *buf_p, int bufsiz);
01853
01867 EXTERNBER OSOCTET* xe_getp (OSCTXT* pctxt);
01868
01886 EXTERNBER void xe_free (OSCTXT* pctxt);
01887
01911 EXTERNBER int xe_expandBuffer (OSCTXT *pctxt, size_t length);
01912
01933 EXTERNBER int xe_memcpy (OSCTXT *pctxt, const OSOCTET* object_p,
01934 size_t length) ;
01935
01948 EXTERNBER int xe_len (OSCTXT *pctxt, int length) ;
01949
01968 EXTERNBER int xe_derCanonicalSort (OSCTXT* pctxt, OSRTSList* pList);
01969
01985 EXTERNBER int xe_TagAndIndefLen (OSCTXT *pctxt, ASN1TAG tag, int length) ;
01986
01994 EXTERNBER void xe_getBufLocDescr (OSCTXT *pctxt, OSUINT32 length,
01995 Asn1BufLocDescr* pDescr);
01996
02016 EXTERNBER int derEncBitString
02017 (OSCTXT* pctxt, const OSOCTET* pvalue, OSUINT32 numbits,
02018 ASN1TagType tagging);
02019
02022
02023
02046 EXTERNBER int berDefToIndefLen (OSCTXT *pSrcCtxt, OSCTXT *pDstCtxt);
02047
02058 EXTERNBER int berIndefToDefLen (OSCTXT *pSrcCtxt, OSCTXT *pDstCtxt);
02059
02067 EXTERNBER OSBOOL berErrAddTagParm (OSCTXT* pctxt, ASN1TAG tag);
02068
02069
02070
02071 #define xu_addTagErrParm berErrAddTagParm
02072
02082 EXTERNBER int berErrUnexpTag (OSCTXT* pctxt, ASN1TAG exptag);
02083
02088 EXTERNBER int berGetLibVersion (void);
02089
02095 EXTERNBER const char *berGetLibInfo (void);
02096
02115 EXTERNBER int berParseTagLen
02116 (const OSOCTET* buffer, size_t bufidx, size_t bufsiz,
02117 ASN1TAG* ptag, size_t* plen);
02118
02128 EXTERNBER const char* berTagToString
02129 (ASN1TAG tag, char* buffer, size_t bufsiz);
02130
02141 EXTERNBER const char* berTagToDynStr (OSCTXT* pctxt, ASN1TAG tag);
02142
02143 EXTERNBER int xu_verify_len (OSOCTET *msg_p);
02144 EXTERNBER void *xu_parse_mmbuf (
02145 OSOCTET **buf_p2, int *buflen_p, OSOCTET *start_p, int bufsiz);
02146
02170 EXTERNBER void xu_alloc_array (
02171 OSCTXT* pctxt, ASN1SeqOf* seqOf_p, int recSize, int recCount);
02172
02173 EXTERNBER void xu_octscpy_s (
02174 OSUINT32* nocts_p, OSOCTET *data_p, char *cstr, char zterm);
02175
02176 EXTERNBER void xu_octscpy_ss (ASN1OctStr *octStr_p, char *cstring, char zterm);
02177
02178 EXTERNBER void xu_octscpy_d (
02179 OSCTXT* pctxt, OSUINT32* nocts_p, const OSOCTET** data_p2,
02180 char* cstring, char zterm);
02181
02182 EXTERNBER void xu_octscpy_ds (
02183 OSCTXT* pctxt, ASN1DynOctStr *octStr_p, char *cstring, char zterm);
02184
02185 EXTERNBER void xu_octmcpy_s (ASN1OctStr *octStr_p, void* data_p, int datalen);
02186
02187 EXTERNBER void xu_octmcpy_d (
02188 OSCTXT* pctxt, ASN1DynOctStr *octStr_p, void* data_p, int datalen);
02189
02190 EXTERNBER char* xu_fetchstr (int numocts, char *data);
02191
02192 EXTERNBER int xu_hexstrcpy (char *data, char *hstring);
02193 EXTERNBER int xu_binstrcpy (char *data, char *bstring);
02194
02220 EXTERNBER int xu_dump (const OSOCTET *msgptr, ASN1DumpCbFunc cb, void* cbArg_p);
02221
02233 EXTERNBER int xu_fdump (FILE *file_p, const OSOCTET *msgptr);
02234
02250 #define xu_hex_dump(msg,numoct,hdr) rtxHexDump(msg,numoct)
02251
02272 EXTERNBER int xu_dump2 (OSCTXT *pctxt, const OSOCTET *msgptr);
02273
02274 EXTERNBER void xu_fmt_tag (
02275 ASN1TAG *tag_p, char *class_p, char *form_p, char *id_code);
02276
02277 EXTERNBER char* xu_fmt_contents (OSCTXT* pctxt, int len, int *count);
02278
02279 EXTERNBER int xu_fread (FILE* fp, OSOCTET* bufp, int bufsiz);
02280
02287 EXTERNBER void xu_SaveBufferState (OSCTXT* pCtxt, OSRTBufSave* pSavedInfo);
02288
02296 EXTERNBER void xu_RestoreBufferState (OSCTXT* pCtxt, OSRTBufSave* pSavedInfo);
02297
02301
02302
02303
02304 #define XD_MEMCPY1(pctxt, object_p) \
02305 ((ASN1BUF_INDEFLEN(pctxt) || \
02306 ((pctxt)->buffer.byteIndex < (pctxt)->buffer.size)) ? \
02307 (*object_p = *OSRTBUFPTR(pctxt), (pctxt)->buffer.byteIndex ++, 0) : \
02308 RTERR_ENDOFBUF)
02309
02310
02311
02312
02313 #define XD_FETCH1(pctxt) ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex++])
02314
02315
02316
02317
02318 #define XD_PEEKTAG(pctxt, tag) \
02319 (((pctxt)->buffer.data[(pctxt)->buffer.byteIndex] & (~0x20)) == (tag & (~0x20)))
02320
02321
02322
02323
02324 #define XD_PEEKPC(pctxt) \
02325 (((pctxt)->buffer.data[(pctxt)->buffer.byteIndex] & 0x20) == 0x20)
02326
02327
02328
02329 #define XD_MATCHEOC(pctxt) \
02330 ( ( (pctxt)->buffer.byteIndex + 2 <= (pctxt)->buffer.size ) && \
02331 ( (pctxt)->buffer.data[(pctxt)->buffer.byteIndex] == 0 ) && \
02332 ( (pctxt)->buffer.data[(pctxt)->buffer.byteIndex + 1] == 0 ) )
02333
02334
02335
02336 #define XD_MATCHBYTES1(pctxt, b1) \
02337 ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex] == b1)
02338
02339 #define XD_MATCHBYTES2(pctxt, b1, b2) \
02340 (((pctxt)->buffer.data[(pctxt)->buffer.byteIndex] == b1) && \
02341 ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex+1] == b2))
02342
02343 #define XD_MATCHBYTES3(pctxt, b1, b2, b3) \
02344 (((pctxt)->buffer.data[(pctxt)->buffer.byteIndex] == b1) && \
02345 ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex+1] == b2) && \
02346 ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex+2] == b3))
02347
02348 #define XD_MATCHBYTES4(pctxt, b1, b2, b3, b4) \
02349 (((pctxt)->buffer.data[(pctxt)->buffer.byteIndex] == b1) && \
02350 ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex+1] == b2) && \
02351 ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex+2] == b3) && \
02352 ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex+3] == b4))
02353
02354 #define XD_MATCHBYTES5(pctxt, b1, b2, b3, b4, b5) \
02355 (((pctxt)->buffer.data[(pctxt)->buffer.byteIndex] == b1) && \
02356 ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex+1] == b2) && \
02357 ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex+2] == b3) && \
02358 ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex+3] == b4) && \
02359 ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex+4] == b5))
02360
02361
02362
02363
02364 #define XD_BUMPIDX(pctxt, nbytes) ((pctxt)->buffer.byteIndex += nbytes)
02365
02366
02367
02368 #define XD_CHKBUFEND(pctxt) \
02369 (((ASN1BUF_INDEFLEN(pctxt)) || \
02370 ((pctxt)->buffer.byteIndex <= (pctxt)->buffer.size)) ? 0 : RTERR_ENDOFBUF)
02371
02372
02373
02374
02375
02376 #define XD_CHKDEFLEN(pctxt,len) \
02377 (((ASN1BUF_INDEFLEN(pctxt)) || \
02378 (((pctxt)->buffer.byteIndex + len) <= (pctxt)->buffer.size)) ? \
02379 0 : RTERR_ENDOFBUF)
02380
02381
02382
02383 #define XD_CHKEOB(pctxt) \
02384 (((pctxt)->buffer.byteIndex + 2 > (pctxt)->buffer.size) ? TRUE : \
02385 (((pctxt)->buffer.data[(pctxt)->buffer.byteIndex] == 0 && \
02386 (pctxt)->buffer.data[(pctxt)->buffer.byteIndex + 1] == 0 ) ? \
02387 TRUE : FALSE))
02388
02389
02390
02391 #define XD_CHKEND(pctxt,ccb_p) \
02392 (((ccb_p)->len == ASN_K_INDEFLEN) ? XD_CHKEOB(pctxt) : \
02393 ((OSRTBUFPTR(pctxt) - (ccb_p)->ptr >= (ccb_p)->len) || \
02394 ((pctxt)->buffer.byteIndex >= (pctxt)->buffer.size)))
02395
02396
02397
02398
02399 #define XE_CHKBUF(pctxt,len) \
02400 if (len > (pctxt)->buffer.byteIndex) { \
02401 int xstat = xe_expandBuffer (pctxt, len); \
02402 if (xstat != 0) return xstat; }
02403
02404
02405
02406
02407 #define XE_PUT1(pctxt,ch) \
02408 (pctxt)->buffer.data[--(pctxt)->buffer.byteIndex] = ch;
02409
02410
02411
02412
02413 #define XE_PUT2(pctxt,ch1,ch2) \
02414 (pctxt)->buffer.byteIndex -= 2; \
02415 (pctxt)->buffer.data[(pctxt)->buffer.byteIndex] = ch1; \
02416 (pctxt)->buffer.data[(pctxt)->buffer.byteIndex+1] = ch2;
02417
02418
02419
02420
02421
02422
02423 #define XE_SAFEPUT1(pctxt,ch) \
02424 XE_CHKBUF(pctxt,1); (pctxt)->buffer.data[--(pctxt)->buffer.byteIndex] = ch;
02425
02426 #ifdef __cplusplus
02427 }
02428 #endif
02429
02430 #endif