Debian Codegraph @

cxx-lib/inc/asn-incl.h

raw symbols SCIP
1 // file: .../c++-lib/inc/asn-incl.h - C++ class SNACCDLL_API
2 //
3 //
4 // NEW HISTORY started once all SNACC class definitions move to a single file.
5 //
6
7 #ifndef SNACC_CXX_ASN_INCL_H
8 #define SNACC_CXX_ASN_INCL_H
9
10
11 #include "asn-config.h"
12 #include "asn-buf.h"
13
14 #ifdef WIN32
15 #if defined(_MSC_VER)
16 #pragma warning(push,3)
17 #endif
18 #include <string>
19 #include <string.h>
20 #if defined(_MSC_VER)
21 #pragma warning(pop)
22 #endif
23 #else // WIN32
24 #include <iostream>
25 #include <string>
26 #include "asn-chartraits.h"
27
28 #if defined(SunOS) || defined(SCO_SV) || defined(HPUX) || defined(HPUX32)
29 namespace std
30 {
31 typedef basic_string<wchar_t> wstring;
32 }
33 #endif // SunOS
34 #endif //WIN32
35
36
37 #if TCL
38 #include <tcl.h>
39 #undef VOID
40 #endif
41
42 #if META
43 #include "meta.h"
44 #endif
45
46 void SNACCDLL_API BDEC_2ND_EOC_OCTET(const SNACC::AsnBuf& b,
47 SNACC::AsnLen& bytesDecoded);
48
49 _BEGIN_SNACC_NAMESPACE
50
51 typedef std::list<std::string> ConstraintFailList;
52
53
54 //########################################################################
55
56 #if SIZEOF_INT == 4
57 #define UL unsigned int
58 #elif SIZEOF_LONG == 4
59 #define UL unsigned long
60 #elif SIZEOF_SHORT == 4
61 #define UL unsigned short
62 #else
63 #define UL unsigned int
64 #endif
65 typedef UL AsnTag;
66
67 // Tag Id's byte len
68 #define TB sizeof(SNACC::AsnTag)
69
70 // The MAKE_TAG_ID macro generates the TAG_ID rep for the
71 // the given class/form/code (rep'd in long integer form)
72 // if the class/form/code are constants the compiler (should)
73 // calculate the tag completely --> zero runtime overhead.
74 // This is good for efficiently comparing tags in switch statements
75 // (decoding) etc. because run-time bit fiddling (eliminated) minimized
76 #define MAKE_TAG_ID( cl, fm, cd)\
77 ((((UL)(cl)) << ((TB-1)*8)) | (((UL)(fm)) << ((TB-1)*8)) | (MAKE_TAG_ID_CODE(((UL)(cd)))))
78
79 #define MAKE_TAG_ID_CODE( cd)\
80 ((cd < 31) ? (MAKE_TAG_ID_CODE1 (cd)):\
81 ((cd < 128) ? (MAKE_TAG_ID_CODE2 (cd)):\
82 ((cd < 16384) ? (MAKE_TAG_ID_CODE3 (cd)):\
83 (MAKE_TAG_ID_CODE4 (cd)))))
84
85 #define MAKE_TAG_ID_CODE1(cd) ((UL)cd << ((TB-1)*8))
86 #define MAKE_TAG_ID_CODE2(cd) ((31l << ((TB-1)*8)) | (cd << ((TB-2)*8)))
87 #define MAKE_TAG_ID_CODE3(cd) ((31l << ((TB-1)*8))\
88 | ((cd & 0x3f80) << 9)\
89 | (0x0080 << ((TB-2)*8))\
90 | ((cd & 0x007F) << ((TB-3)*8)))
91
92 #define MAKE_TAG_ID_CODE4(cd) ((31l << ((TB-1)*8))\
93 | ((cd & 0x1fc000) << 2)\
94 | (0x0080 << ((TB-2)*8))\
95 | ((cd & 0x3f80) << 1)\
96 | (0x0080 << ((TB-3)*8))\
97 | ((cd & 0x007F) << ((TB-4)*8)))
98
99 typedef enum BER_CLASS
100 {
101 ANY_CLASS = -2,
102 NULL_CLASS = -1,
103 UNIV = 0,
104 APPL = (1 << 6),
105 CNTX = (2 << 6),
106 PRIV = (3 << 6)
107 } BER_CLASS;
108
109 typedef enum BER_FORM
110 {
111 ANY_FORM = -2,
112 NULL_FORM = -1,
113 PRIM = 0,
114 CONS = (1 << 5)
115 } BER_FORM;
116
117 typedef enum BER_UNIV_CODE
118 {
119 NO_TAG_CODE = 0,
120 BOOLEAN_TAG_CODE = 1,
121 INTEGER_TAG_CODE,
122 BITSTRING_TAG_CODE,
123 OCTETSTRING_TAG_CODE,
124 NULLTYPE_TAG_CODE,
125 OID_TAG_CODE,
126 OD_TAG_CODE,
127 EXTERNAL_TAG_CODE,
128 REAL_TAG_CODE,
129 ENUM_TAG_CODE,
130 UTF8STRING_TAG_CODE = 12,
131 RELATIVE_OID_TAG_CODE = 13,
132 SEQ_TAG_CODE = 16,
133 SET_TAG_CODE,
134 NUMERICSTRING_TAG_CODE,
135 PRINTABLESTRING_TAG_CODE,
136 TELETEXSTRING_TAG_CODE,
137 VIDEOTEXSTRING_TAG_CODE,
138 IA5STRING_TAG_CODE,
139 UTCTIME_TAG_CODE,
140 GENERALIZEDTIME_TAG_CODE,
141 GRAPHICSTRING_TAG_CODE,
142 VISIBLESTRING_TAG_CODE,
143 GENERALSTRING_TAG_CODE,
144 UNIVERSALSTRING_TAG_CODE = 28,
145 BMPSTRING_TAG_CODE = 30
146 } BER_UNIV_CODE;
147
148 #define TT61STRING_TAG_CODE TELETEXSTRING_TAG_CODE
149 #define ISO646STRING_TAG_CODE VISIBLESTRING_TAG_CODE
150
151 /*
152 * the TAG_ID_[CLASS/FORM/CODE] macros are not
153 * super fast - try not to use during encoding/decoding
154 */
155 #define TAG_ID_CLASS(tid) ( (tid & (0xC0 << ((TB-1)*8))) >> ((TB-1)*8))
156 #define TAG_ID_FORM(tid) ( (tid & (0x20 << ((TB-1)*8))) >> ((TB-1)*8))
157
158 /*
159 * TAG_IS_CONS evaluates to true if the given AsnTag type
160 * tag has the constructed bit set.
161 */
162 #define TAG_IS_CONS(tag) ((tag) & (CONS << ((TB-1)*8)))
163
164 #define EOC_TAG_ID 0
165
166 /*
167 * tag encoders. given constant exprs for class SNACCDLL_API form & code in the
168 * source, these can be optimized by the compiler (eg
169 * do the shifts and bitwise ors etc)
170 */
171 #define BEncTag1( b, class, form, code)\
172 1;\
173 b.PutByteRvs((unsigned char)((class) | (form) | (code)))
174
175 #define BEncTag2( b, class, form, code)\
176 2;\
177 b.PutByteRvs(code);\
178 b.PutByteRvs((char)((class) | (form) | 31))
179
180 #define BEncTag3( b, class, form, code)\
181 3;\
182 b.PutByteRvs((code) & 0x7F);\
183 b.PutByteRvs((char)(0x80 | (char)((code) >> 7)));\
184 b.PutByteRvs((class) | (form) | 31)
185
186 #define BEncTag4( b, class, form, code)\
187 4;\
188 b.PutByteRvs((code) & 0x7F);\
189 b.PutByteRvs((char)(0x80 | (char)((code) >> 7)));\
190 b.PutByteRvs((char)(0x80 | (char)((code) >> 14)));\
191 b.PutByteRvs((class) | (form) | 31)
192
193 #define BEncTag5( b, class, form, code)\
194 5;\
195 b.PutByteRvs((code) & 0x7F);\
196 b.PutByteRvs((char)(0x80 | (char)((code) >> 7)));\
197 b.PutByteRvs((char)(0x80 | (char)((code) >> 14)));\
198 b.PutByteRvs((char)(0x80 | (char)((code) >> 21)));\
199 b.PutByteRvs((class) | (form) | 31)
200
201 AsnLen SNACCDLL_API PEncTag(AsnBufBits& b, unsigned char ucClass,
202 unsigned char form, long code, long lByteCount);
203 AsnTag SNACCDLL_API BDecTag(const AsnBuf& b, AsnLen& bytesDecoded);
204 AsnTag SNACCDLL_API PDecTag(AsnBufBits& bufBits, AsnLen& bitsDecoded);
205 long SNACCDLL_API BytesInTag(AsnTag tag);
206 long SNACCDLL_API BytesInLen(AsnLen len);
207
208 //########################################################################
209
210 #define INDEFINITE_LEN ~0UL // max unsigned value used for indef rep
211 #define MAX_OCTS 1048576 // 1 meg
212 #define l_16k 16384
213
214 #ifdef USE_INDEF_LEN
215
216 #define BEncEocIfNec(b)\
217 BEncEoc (b)
218 #define BEncConsLen(b, len)\
219 2 + BEncIndefLen (b) // include len for EOC */
220
221 #else // default -- use definite length -- usually faster
222 // and smaller encodings
223
224 #define BEncEocIfNec(b) 0; // do nothing
225
226 #define BEncConsLen(b, len)\
227 BEncDefLen (b, len)
228
229 #endif
230
231 #define BEncIndefLen( b)\
232 1;\
233 b.PutByteRvs (0x80)
234
235 /*
236 * use if you know the encoded length will be 0 >= len <= 127
237 * Eg for booleans, nulls, any resonable integers and reals
238 *
239 * NOTE: this particular Encode Routine does NOT return the length
240 * encoded (1). The length counter must be explicity incremented
241 */
242 #define BEncDefLenTo127( b, len)\
243 b.PutByteRvs ((unsigned char) len)
244
245 AsnLen SNACCDLL_API BDecLen(const AsnBuf& b, AsnLen& bytesDecoded);
246 AsnLen SNACCDLL_API BEncDefLen(AsnBuf& b, AsnLen len);
247
248 AsnLen SNACCDLL_API BEncEoc(AsnBuf& b);
249 void SNACCDLL_API BDecEoc(const AsnBuf& b, AsnLen& bytesDecoded);
250
251 AsnLen SNACCDLL_API PEncDefLenTo127(AsnBufBits& b, int len);
252 AsnLen SNACCDLL_API PEncLen_16kFragment(AsnBufBits& b, int len);
253 AsnLen SNACCDLL_API PEncLen_1to16k(AsnBufBits& b, int len);
254
255
256 // Indent function used in Print() functions
257 void SNACCDLL_API Indent(std::ostream& os, unsigned short i);
258
259 //########################################################################
260
261 AsnLen SNACCDLL_API PEncLen_16kFragment(AsnBufBits &b, int len);
262
263 AsnLen SNACCDLL_API PEncLen_1to16k(AsnBufBits &b, int len);
264
265 //Forward definition
266 class AsnType;
267
268 typedef struct SNACCDLL_API ContainedSubtype{
269 AsnType *containedSubtype;
270 }ContainedSubtype;
271
272 typedef struct SNACCDLL_API SizeConstraint{
273 unsigned long lowerBound;
274 unsigned long upperBound;
275 int upperBoundExists;
276 }SizeConstraint;
277
278 typedef struct SNACCDLL_API ValueRange{
279 long lowerBound;
280 long upperBound;
281 int upperBoundExists;
282 }ValueRange;
283
284 typedef struct SNACCDLL_API PermittedAlphabet{
285 unsigned char* ucApha;
286 }PermittedAlphabet;
287
288
289 class SNACCDLL_API PERGeneral
290 {
291 protected:
292 virtual AsnLen EncodeGeneral(AsnBufBits& b) const;
293 virtual AsnLen Interpret(AsnBufBits& b, long offset) const = 0;
294
295 virtual long lEncLen() const { return 0; }
296 virtual void Clear() = 0;
297
298 virtual void DecodeGeneral(AsnBufBits& b, AsnLen& bitsDecoded);
299 virtual void Deterpret(AsnBufBits&b, AsnLen& bitsDecoded, long offset) = 0;
300 virtual void Allocate(long size) = 0;
301 };
302
303
304 class SNACCDLL_API AsnType
305 {
306 protected:
307 ContainedSubtype *containedSubtypes;
308
309 public:
310
311 virtual ~AsnType();
312
313 virtual AsnType* Clone() const = 0;
314 virtual const char* typeName() const = 0;
315
316 /* JKG: virtual constraint check function added 7/29/03 */
317 /* function returns 1 on error and 0 on success */
318 virtual int checkConstraints(ConstraintFailList* ) const { return 0; }
319
320 virtual void BDec(const AsnBuf &b, AsnLen &bytesDecoded) = 0;
321 virtual AsnLen BEnc(AsnBuf &b) const = 0;
322
323 virtual void PDec(AsnBufBits &, AsnLen &) {}
324 virtual AsnLen PEnc(AsnBufBits &) const { return 0; }
325
326 bool BEncPdu(AsnBuf &b, AsnLen &bytesEncoded) const;
327 bool BDecPdu(const AsnBuf &b, AsnLen &bytesDecoded);
328
329 virtual void Print(std::ostream& os, unsigned short indent = 0) const = 0;
330
331 #if META
332 static const AsnTypeDesc _desc;
333 virtual const AsnTypeDesc* _getdesc() const;
334 virtual AsnType* _getref(const char* membername, bool create = false);
335
336 private:
337 const char* _typename() const;
338
339 #if TCL
340 public:
341 virtual int TclGetDesc(Tcl_DString* ) const;
342 virtual int TclGetVal(Tcl_Interp* ) const;
343 virtual int TclSetVal(Tcl_Interp* , const char* val);
344 virtual int TclUnsetVal(Tcl_Interp* , const char* membernames);
345 #endif // TCL
346 #endif // META
347 };
348
349
350 //########################################################################
351 //########################################################################
352
353 typedef std::pair<unsigned char *, unsigned long> StringPair;
354
355 class ConsStringDeck : public std::deque< StringPair >
356 {
357 public:
358 ConsStringDeck(AsnTag baseTag = OCTETSTRING_TAG_CODE) {m_baseTag = baseTag;}
359
360 virtual ~ConsStringDeck();
361 void Fill(const AsnBuf &b, AsnLen elmtLen, AsnLen &bytesDecoded);
362 void Collapse(std::string &str);
363
364 private:
365 AsnTag m_baseTag;
366 };
367
368 //########################################################################
369
370 class SNACCDLL_API AsnNull: public AsnType
371 {
372 public:
373
374 virtual AsnType* Clone() const { return new AsnNull(*this); }
375 virtual const char* typeName() const { return "AsnNull"; }
376
377 AsnLen BEncContent (AsnBuf &) const { return 0; }
378 void BDecContent (const AsnBuf &b, AsnTag tagId, AsnLen elmtLen, AsnLen &bytesDecoded);
379 AsnLen BEnc (AsnBuf &b) const;
380 void BDec (const AsnBuf &b, AsnLen &bytesDecoded);
381
382 AsnLen PEnc (AsnBufBits &b) const;
383 void PDec (AsnBufBits &b, AsnLen &bitsDecoded);
384
385 void Print(std::ostream& os, unsigned short indent = 0) const;
386 void PrintXML (std::ostream &os, const char *lpszTitle=NULL) const;
387
388 #if META
389 static const AsnNullTypeDesc _desc;
390 const AsnTypeDesc *_getdesc() const;
391
392 #if TCL
393 int TclGetVal (Tcl_Interp *) const;
394 int TclSetVal (Tcl_Interp *, const char *val);
395 #endif /* TCL */
396 #endif /* META */
397 };
398
399 //########################################################################
400
401 class SNACCDLL_API AsnBool: public AsnType
402 {
403 protected:
404 bool value;
405
406 public:
407 AsnBool (const bool val = false) { value = val; }
408
409 virtual AsnType* Clone() const { return new AsnBool(*this);}
410 virtual const char* typeName() const { return "AsnBool"; }
411
412 operator bool() const { return value; }
413
414 AsnBool &operator = (bool newvalue) { value = newvalue; return *this; }
415
416 AsnLen BEnc (AsnBuf &b) const;
417 void BDec (const AsnBuf &b, AsnLen &bytesDecoded);
418 AsnLen BEncContent (AsnBuf &b) const;
419 void BDecContent (const AsnBuf &b, AsnTag tagId, AsnLen elmtLen, AsnLen &bytesDecoded);
420
421 AsnLen PEnc (AsnBufBits &b) const;
422 void PDec (AsnBufBits &b, AsnLen &bitsDecoded);
423
424
425 void Print(std::ostream& os, unsigned short indent = 0) const;
426 void PrintXML (std::ostream &os, const char *lpszTitle=NULL) const;
427 char* checkBoolSingleVal(const bool m_SingleVal)const;
428
429 #if META
430 static const AsnBoolTypeDesc _desc;
431
432 const AsnTypeDesc *_getdesc() const;
433
434 #if TCL
435 int TclGetVal (Tcl_Interp *) const;
436 int TclSetVal (Tcl_Interp *, const char *val);
437 #endif // TCL
438 #endif // META
439 };
440
441 //########################################################################
442
443 class SNACCDLL_API AsnOcts: public AsnType
444 {
445 public:
446 // constructor always copies strings so destructor can always delete
447 AsnOcts() {m_pFileSeg = NULL; }
448 AsnOcts (const char *str) { m_pFileSeg = NULL; m_str.assign(str); }
449 AsnOcts (const char *str, const size_t len) { m_pFileSeg = NULL; m_str.assign(str, len); }
450 AsnOcts (const AsnOcts &o);
451 // AsnOcts (const std::filebuf &fb);
452 virtual ~AsnOcts();
453
454 virtual const SizeConstraint* SizeConstraints(int &sizeList)const { sizeList = 0; return NULL;}
455
456 virtual AsnType* Clone() const { return new AsnOcts(*this); }
457 virtual const char* typeName() const { return "AsnOcts"; }
458
459 AsnOcts &operator = (const AsnOcts &o) { return SetEqual(o); }
460 AsnOcts &operator = (const char *str) { return SetEqual(str); }
461
462 AsnOcts &SetEqual(const AsnOcts &o) { m_str = o.m_str; return *this; }
463 AsnOcts &SetEqual(const char *str) { m_str.assign(str); return *this; }
464
465
466 void Set (const char *str, size_t len);
467
468 size_t Len() const;
469 long length(){return (long)Len();}
470 long length()const{return (long)Len();}
471
472 void clear(){m_str.erase();}
473
474 const std::string & data() const;
475 const char * c_str() const;
476 const unsigned char * c_ustr() const;
477
478 bool operator == (const AsnOcts &o) const;
479 bool operator != (const AsnOcts &o) const;
480
481 AsnLen BEncContent (AsnBuf &b) const;
482 void BDecContent (const AsnBuf &b, AsnTag tagId, AsnLen elmtLen, AsnLen &bytesDecoded);
483 AsnLen BEnc (AsnBuf &b) const ;
484 void BDec (const AsnBuf &b, AsnLen &bytesDecoded);
485
486 AsnLen PEnc (AsnBufBits &b)const;
487 void PDec (AsnBufBits &b, AsnLen &bitsDecoded);
488
489 void Print(std::ostream& os, unsigned short indent = 0) const;
490 void PrintXML (std::ostream &os, const char *lpszTitle=NULL,
491 const char *lpszType=NULL) const;
492
493 protected:
494 AsnLen EncodeGeneral(AsnBufBits &b)const;
495 void DecodeGeneral(AsnBufBits &b, AsnLen &bitsDecoded);
496 AsnLen EncodeWithSizeConstraint(AsnBufBits &b)const;
497 void DecodeWithSizeConstraint(AsnBufBits &b, AsnLen &bitsDecoded);
498 long FindSizeConstraintBounds(int &iSCLowerBound, int &iSCUpperBound)const;
499
500 private:
501 void BDecConsOcts (const AsnBuf &b, AsnLen elmtLen, AsnLen &bytesDecoded);
502 void FillStringDeck(AsnBuf &b, AsnLen elmtLen, AsnLen &bytesDecoded);
503
504
505 // IF AsnOcts length is < MAX_OCTS, store in AsnString base
506 mutable std::string m_str;
507
508 // IF AsnOcts length is > MAX_OCTS, store in m_FileBuf;
509 mutable AsnFileSeg *m_pFileSeg;
510 };
511
512 //########################################################################
513
514 class SNACCDLL_API AsnBits: public AsnType
515 {
516 public:
517
518 AsnBits(const char *stringForm=NULL);
519 AsnBits (size_t numBits)
520 { bits=NULL;nblFlag = false; Set (numBits); }
521 AsnBits (const unsigned char *bitOcts, size_t numBits)
522 {bits=NULL; nblFlag = false; Set (bitOcts, numBits); }
523 AsnBits (const AsnBits &b) { bits=NULL; Set (b); }
524 ~AsnBits();
525
526 virtual const SizeConstraint* SizeConstraints(int &sizeList)const { sizeList = 0; return NULL;}
527
528 virtual AsnType* Clone() const { return new AsnBits(*this); }
529 virtual const char* typeName() const { return "AsnBits"; }
530
531 AsnBits &operator = (const AsnBits &b) { Set (b); return *this; }
532
533 // overwrite existing bits and bitLen values
534 void Set (size_t numBits);
535 void Set (const unsigned char *bitOcts, size_t numBits);
536 void Set (const AsnBits &b);
537
538 AsnBits & SetEqual(const char *stringForm);
539
540 AsnBits & operator = (const char *stringForm);
541 bool operator == (const AsnBits &ab) const { return BitsEquiv (ab); }
542 bool operator != (const AsnBits &ab) const { return !BitsEquiv (ab); }
543
544 void SetSize(size_t);
545 bool soloBitCheck(size_t);
546 void SetBit (size_t);
547 void ClrBit (size_t);
548 bool GetBit (size_t) const;
549 bool IsEmpty() const;
550 long FindSizeConstraintBounds(int &iSCLowerBound, int &iSCUpperBound)const;
551
552
553 void UseNamedBitListRules(bool flag) { nblFlag = flag; }
554
555 void clear(){if(bits) delete[] bits; bits = NULL; bitLen = 0;}
556
557 size_t BitLen() const { return bitLen; }
558 const unsigned char* data() const { return bits; }
559 size_t length() const { return ((bitLen+7)/8); }
560 size_t encLen() const;
561 virtual void Allocate(long size);
562
563
564 AsnLen BEncContent (AsnBuf &b) const;
565 void BDecContent (const AsnBuf &b, AsnTag tagId, AsnLen elmtLen, AsnLen &bytesDecoded);
566 AsnLen BEnc (AsnBuf &b) const;
567 void BDec (const AsnBuf &b, AsnLen &bytesDecoded);
568
569 AsnLen EncodeGeneral (AsnBufBits &b)const;
570 void DecodeGeneral (AsnBufBits &b, AsnLen &bitsDecoded);
571 AsnLen EncodeWithSizeConstraint (AsnBufBits &b)const;
572 void DecodeWithSizeConstraint (AsnBufBits &b, AsnLen &bitsDecoded);
573 AsnLen PEnc (AsnBufBits &b) const;
574 void PDec (AsnBufBits &b, AsnLen &bitsDecoded);
575
576
577 void Print(std::ostream& os, unsigned short indent = 0) const;
578 void PrintXML (std::ostream &os, const char *lpszTitle=NULL) const;
579
580 #if META
581 static const AsnBitsTypeDesc _desc;
582
583 const AsnTypeDesc *_getdesc() const;
584
585 #if TCL
586 int TclGetVal (Tcl_Interp *) const;
587 int TclSetVal (Tcl_Interp *, const char *val);
588 #endif /* TCL */
589 #endif /* META */
590
591 private:
592 bool BitsEquiv (const AsnBits &ab) const;
593 void BDecConsBits (const AsnBuf &b, AsnLen elmtLen, AsnLen &bytesDecoded);
594
595 protected:
596 size_t bitLen;
597 unsigned char* bits;
598 bool nblFlag;
599 };
600
601 extern SNACCDLL_API char numToHexCharTblG[];
602
603 #define TO_HEX(fourBits) (numToHexCharTblG[(fourBits) & 0x0F])
604
605 //########################################################################
606
607 class SNACCDLL_API AsnInt : public AsnType, protected PERGeneral
608 {
609 protected:
610
611 unsigned char *m_bytes;
612 unsigned long m_len;
613
614 void storeDERInteger(const unsigned char *pDataCopy, long dataLen, bool unsignedFlag);
615
616 void Clear(){if(m_bytes) delete[] m_bytes; /*RWC*/ m_bytes = NULL; m_len = 0;}
617 long lEncLen()const{return length();}
618 char getByte(long offset)const{return m_bytes[offset];}
619 void putByte(long offset, unsigned char cByte);
620
621 virtual AsnLen Interpret(AsnBufBits &b,long offset)const;
622 virtual void Deterpret(AsnBufBits &b, AsnLen &bitsDecoded, long offset);
623 virtual void Allocate(long size);
624
625 public:
626 AsnInt (AsnIntType val=0);
627 AsnInt (const char *str, bool unsignedFlag = true);
628 AsnInt (const AsnOcts &o, bool unsignedFlag = true);
629 AsnInt (const char *str, const size_t len, bool unsignedFlag = true);
630 AsnInt (const AsnInt &that);//generate this
631 virtual ~AsnInt ();
632
633 virtual const ValueRange* ValueRanges(int &sizeVRList)const { sizeVRList = 0; return NULL;}
634
635 virtual AsnType* Clone() const { return new AsnInt(*this); }
636 virtual const char* typeName() const { return "AsnInt"; }
637
638 operator AsnIntType() const;
639 bool operator == (AsnIntType o) const;
640 bool operator != (AsnIntType o) const { return !operator==(o);}
641 bool operator == (const AsnInt &o) const;
642 bool operator != (const AsnInt &o) const;
643 bool operator < (const AsnInt &o) const;
644 AsnInt & operator = (const AsnInt &o);//generate this
645 //unsigned char* Append_m_bytes(const unsigned char* AppendBytes, unsigned long templen);
646
647 long length()const{ return m_len; }
648 long length(void){ return m_len; }
649 const unsigned char * c_str(void) const { return m_bytes; }
650 void getPadded(unsigned char *&data, size_t &len, const size_t padToSize=0) const;
651
652 int checkConstraints (ConstraintFailList* pConstraintFails)const;
653
654 void Set(const unsigned char *str, size_t len, bool unsignedFlag=true);
655 void Set(AsnIntType i);
656
657 AsnLen BEnc (AsnBuf &b) const;
658 void BDec (const AsnBuf &b, AsnLen &bytesDecoded);
659 AsnLen BEncContent (AsnBuf &b) const;
660 void BDecContent (const AsnBuf &b, AsnTag tagId, AsnLen elmtLen, AsnLen &bytesDecoded);
661
662 virtual AsnLen PEnc (AsnBufBits &b)const;
663 AsnLen PEncSemiConstrained (AsnBufBits &b, long lowerBound )const;
664 AsnLen PEncFullyConstrained (AsnBufBits &b, long lowerBound, long upperBound)const;
665
666 void PDecSemiConstrained(AsnBufBits &b, long lowerBound, AsnLen &bitsDecoded);
667 void PDecFullyConstrained (AsnBufBits &b, long lowerBound, long upperBound, AsnLen &bitsDecoded);
668 void PDec (AsnBufBits &b, AsnLen &bitsDecoded);
669
670
671 void Print(std::ostream& os, unsigned short indent = 0) const;
672 void PrintXML (std::ostream &os, const char *lpszTitle=NULL) const;
673
674 #if META
675 static const AsnIntTypeDesc _desc;
676
677 const AsnTypeDesc *_getdesc() const;
678
679 #if TCL
680 int TclGetVal (Tcl_Interp *) const;
681 int TclSetVal (Tcl_Interp *, const char *val);
682 #endif /* TCL */
683 #endif /* META */
684 };
685
686 //########################################################################
687
688 class SNACCDLL_API AsnEnum : public AsnInt
689 {
690 public:
691 AsnEnum(int val = 0) : AsnInt(val) {}
692
693 AsnLen BEnc(AsnBuf& b) const;
694 void BDec(const AsnBuf& b, AsnLen& bytesDecoded);
695
696 virtual AsnType *Clone() const { return new AsnEnum(*this); }
697 virtual const char* typeName() const { return "AsnEnum"; }
698
699 long IndexedVal(long* penumList, long numVals) const;
700 void SetIndex(long* penumList, long numVals, long index);
701
702 #if META
703 static const AsnEnumTypeDesc _desc;
704 const AsnTypeDesc* _getdesc() const;
705
706 #if TCL
707 int TclGetVal(Tcl_Interp * ) const;
708 int TclSetVal(Tcl_Interp * , const char* val);
709 #endif /* TCL */
710 #endif /* META */
711 };
712
713 //########################################################################
714
715 class SNACCDLL_API AsnReal : public AsnType
716 {
717 protected:
718 double value;
719
720 public:
721 AsnReal():value (0.0){}
722 AsnReal (double val):value (val){}
723
724 virtual AsnType *Clone() const { return new AsnReal(*this); }
725 virtual const char* typeName() const { return "AsnReal"; }
726
727 operator double() const { return value; }
728 AsnReal &operator = (double newvalue) { value = newvalue; return *this; }
729
730 AsnLen BEncContent (AsnBuf &b) const;
731 void BDecContent (const AsnBuf &b, AsnTag tagId, AsnLen elmtLen, AsnLen &bytesDecoded);
732 AsnLen BEnc (AsnBuf &b) const;
733 void BDec (const AsnBuf &b, AsnLen &bytesDecoded);
734
735 AsnLen PEnc (AsnBufBits &b)const;
736 void PDec (AsnBufBits &b, AsnLen &bitsDecoded);
737
738 void Print(std::ostream& os, unsigned short indent = 0) const;
739 void PrintXML (std::ostream &os, const char *lpszTitle=NULL) const;
740
741 char* checkRealSingleVal(const double m_SingleVal)const;
742 char* checkRealValRange(const double m_Lower, const double m_Upper) const;
743
744
745 #if META
746 static const AsnRealTypeDesc _desc;
747
748 const AsnTypeDesc *_getdesc() const;
749
750 #if TCL
751 int TclGetVal (Tcl_Interp *) const;
752 int TclSetVal (Tcl_Interp *, const char *val);
753 #endif /* TCL */
754 #endif /* META */
755 };
756
757 extern const AsnReal PLUS_INFINITY;
758 extern const AsnReal MINUS_INFINITY;
759
760 //########################################################################
761
762 class SNACCDLL_API AsnRelativeOid : public AsnType
763 {
764 public:
765 AsnRelativeOid() { Init(); }
766 AsnRelativeOid(const AsnRelativeOid& o) { Init(); Set(o); }
767 AsnRelativeOid(const char* pszOID) { Init(); Set(pszOID); }
768 virtual ~AsnRelativeOid();
769
770 AsnRelativeOid& operator=(const AsnRelativeOid& o) { Set(o); return *this; }
771 operator const char*() const;
772
773 virtual AsnType* Clone() const { return new AsnRelativeOid(*this); }
774 virtual const char* typeName() const { return "AsnRelativeOid"; }
775 size_t Len() const { return octetLen; }
776 const char* Str() const { return oid; }
777
778 bool operator==(const AsnRelativeOid& o) const { return OidEquiv(o); }
779 bool operator==(const char* o) const;
780 bool operator!=(const AsnRelativeOid& o) const { return !operator==(o); }
781 bool operator!=(const char* o) const { return !operator==(o); }
782 bool operator<(const AsnRelativeOid& o) const;
783
784 unsigned long NumArcs() const;
785 void GetOidArray(unsigned long oidArray[]) const;
786
787 void Set(const char* szOidCopy);
788 void Set(const char* encOid, size_t len);
789 void Set(const AsnRelativeOid& o);
790 void Set(unsigned long arcNumArr[], unsigned long arrLength);
791
792 AsnLen BEnc(AsnBuf& b) const;
793 void BDec(const AsnBuf& b, AsnLen& bytesDecoded);
794 AsnLen BEncContent(AsnBuf& b) const;
795 void BDecContent(const AsnBuf& b, AsnTag tagId, AsnLen elmtLen,
796 AsnLen& bytesDecoded);
797
798 AsnLen PEnc(AsnBufBits& b) const;
799 void PDec(AsnBufBits& b, AsnLen& bitsDecoded);
800
801 void Print(std::ostream& os, unsigned short indent = 0) const;
802 void PrintXML(std::ostream& os, const char* lpszTitle = NULL) const;
803
804 #if META
805 static const AsnRelativeOidTypeDesc _desc;
806 const AsnTypeDesc* _getdesc() const;
807
808 #if TCL
809 int TclGetVal(Tcl_Interp* ) const;
810 int TclSetVal(Tcl_Interp* , const char* val);
811 #endif /* TCL */
812 #endif /* META */
813
814 protected:
815 size_t octetLen;
816 char* oid;
817 mutable char* m_lpszOidString;
818 bool m_isRelative;
819
820 private:
821 void Init() { octetLen = 0; oid = NULL; m_lpszOidString = NULL;
822 m_isRelative = true; }
823 bool OidEquiv(const AsnRelativeOid& o) const;
824 void createDottedOidStr() const;
825 };
826
827 //########################################################################
828
829 class SNACCDLL_API AsnOid : public AsnRelativeOid
830 {
831 public:
832 AsnOid();
833 AsnOid(const char* pszOID);
834 AsnOid(const AsnOid &that):AsnRelativeOid(that) {m_isRelative = false;}
835
836 virtual AsnType* Clone() const { return new AsnOid(*this); }
837 virtual const char* typeName() const { return "AsnOid"; }
838
839 // get a copy of the OID's NULL-terminated dotted string notation
840 char* GetChar() const { return strdup(operator const char*()); }
841
842 // set from a number-dot null term string
843 void PutChar(const char* szOidCopy) { Set(szOidCopy); }
844
845 AsnOid operator+(const AsnRelativeOid& ro) const;
846 AsnOid& operator+=(const AsnRelativeOid& ro);
847
848 #if META
849 static const AsnOidTypeDesc _desc;
850 const AsnTypeDesc* _getdesc() const;
851 #endif /* META */
852 };
853
854 //########################################################################
855
856 //hash.h
857 #define TABLESIZE 256
858 #define INDEXMASK 0xFF
859 #define INDEXSHIFT 8
860
861 typedef void *Table[TABLESIZE];
862
863 typedef unsigned int Hash;
864
865 typedef struct HashSlot
866 {
867 int leaf;
868 Hash hash;
869 void *value;
870 Table *table;
871 } HashSlot;
872
873 Hash MakeHash (const char *str, size_t len);
874
875 Table *InitHash();
876
877 int Insert (Table *table, void *element, Hash hash);
878
879 int CheckFor (Table *table, Hash hash);
880
881 int CheckForAndReturnValue (Table *table, Hash hash, void **value);
882
883 //########################################################################
884
885 /* this is put into the hash table with the int or oid as the key */
886 class SNACCDLL_API AnyInfo
887 {
888 public:
889 int anyId; // will be a value from the AnyId enum
890 AsnOid oid; // will be zero len/null if intId is valid
891 AsnIntType intId;
892 AsnType *typeToClone;
893 };
894
895 class SNACCDLL_API AsnAny: public AsnType
896 {
897 public:
898 static Table *oidHashTbl; // all AsnAny class SNACCDLL_API instances
899 static Table *intHashTbl; // share these tables
900 mutable AnyInfo *ai; // points to entry in hash tbl for this type
901 AsnType *value;
902 AsnBuf *anyBuf; // used if ai == null
903
904 AsnAny() { ai = NULL; value = NULL; anyBuf=NULL;}
905 AsnAny(const AsnAny &o) { ai = NULL; value = NULL; anyBuf = NULL; *this = o; }
906 virtual ~AsnAny();
907
908 AsnAny &operator = (const AsnAny &o);
909
910 virtual AsnType* Clone() const { return new AsnAny(*this); }
911 virtual const char* typeName() const { return "AsnAny"; }
912
913 static void AsnAnyDestroyHashTbls();
914
915 // Recursive call to destroy table during destruction
916 static void AsnAnyDestroyHashTbl(Table *&pHashTbl);
917
918 // class SNACCDLL_API level methods
919 static void InstallAnyByInt (AsnIntType intId, int anyId, AsnType *type);
920 static void InstallAnyByOid (AsnOid &oid, int anyId, AsnType *type);
921
922 int GetId() const { return ai ? ai->anyId : -1; }
923 void SetTypeByInt (const AsnInt& id) const;
924 void SetTypeByOid (const AsnOid &id) const;
925
926 AsnLen BEnc (AsnBuf &b) const;
927 void BDec (const AsnBuf &b, AsnLen &bytesDecoded);
928
929 void BDecContent (const AsnBuf &b, AsnTag tag, AsnLen len, AsnLen &bytesDecoded);
930
931 AsnLen PEnc (AsnBufBits &b) const;
932 void PDec (AsnBufBits &b, AsnLen &bitsDecoded);
933
934 void Print(std::ostream& os, unsigned short indent = 0) const;
935 void PrintXML(std::ostream &os, const char *lpszTitle=NULL) const;
936
937 #if TCL
938 int TclGetDesc (Tcl_DString *) const;
939 int TclGetVal (Tcl_DString *) const;
940 int TclSetVal (Tcl_Interp *, const char *val);
941 int TclUnSetVal (Tcl_Interp *, const char *member);
942 #endif /* TCL */
943
944 };
945
946 //########################################################################
947 // SNACC ASN.1 String Types
948 //
949 class SNACCDLL_API AsnString : public std::string, public AsnType, protected PERGeneral
950 {
951 public:
952 AsnString(const char* str = NULL) { operator=(str); }
953 AsnString(const std::string& str) { operator=(str); }
954 AsnString(const AsnString& aStr) : std::string() { operator=(aStr.c_str()); }
955
956 AsnString& operator=(const char* str);
957 AsnString& operator=(const std::string& str) { assign(str); return *this; }
958
959 void Set(const char* str){operator=(str);}
960
961 virtual const SizeConstraint* SizeConstraints(int &sizeList)const { sizeList = 0; return NULL;}
962 virtual const char* PermittedAlphabet(int &sizeAlpha) const;
963
964 int cvt_LDAPtoStr (char *in_string, char **char_ptr);
965 int cvt_StrtoLDAP (wchar_t *in_string, char **char_ptr);
966
967 AsnLen BEnc(AsnBuf &b) const;
968 void BDec(const AsnBuf &b, AsnLen& bytesDecoded);
969 AsnLen BEncContent(AsnBuf &b) const;
970 void BDecContent(const AsnBuf &b, AsnTag tagId, AsnLen elmtLen,
971 AsnLen& bytesDecoded);
972
973 AsnLen PEnc(AsnBufBits &b)const;
974 void PDec(AsnBufBits &b, AsnLen &bitsDecoded);
975
976 int checkConstraints (ConstraintFailList* pConstraintFails)const;
977 const char* checkStringTypPermittedAlpha(const char* m_Alpha, long m_AlphaSize)const;
978
979 // each string type must implement these methods
980 //
981 // tagCode should be implemented to return the ASN.1 tag corresponding to the
982 // character string type.
983 //
984 // the check method should be implemented to enforce any rules imposed on the
985 // character string type.
986 virtual BER_UNIV_CODE tagCode(void) const = 0;
987 virtual bool check() const { return true; }
988
989
990
991 void Print(std::ostream& os, unsigned short indent = 0) const;
992 void PrintXML(std::ostream& os, const char *lpszTitle = NULL) const;
993
994 protected:
995 void Clear() { erase(); }
996 char* getChar(long offset)const;
997 int numBits()const;
998 void putChar(char* seg){append(seg, 1);}
999 int findB2(int B)const;
1000
1001 AsnLen EncodeWithSizeConstraint(AsnBufBits &b)const;
1002 void DecodeWithSizeConstraint(AsnBufBits &b, AsnLen &bitsDecoded);
1003 long FindSizeConstraintBounds(int &iSCLowerBound, int &iSCUpperBound)const;
1004
1005 virtual AsnLen Interpret(AsnBufBits &b, long offset)const;
1006 virtual long lEncLen()const{return length();}
1007 virtual void Deterpret(AsnBufBits &b, AsnLen &bitsDecoded, long offset);
1008 virtual void Allocate(long){/*std::string automatically allocates mem*/};
1009
1010 private:
1011 void BDecConsString(const AsnBuf &b, AsnLen elmtLen, AsnLen &bytesDecoded);
1012 };
1013
1014
1015 class SNACCDLL_API NumericString : public AsnString
1016 {
1017 public:
1018 NumericString(const char* str = NULL) : AsnString(str) { }
1019 NumericString(const std::string& str) : AsnString(str) { }
1020
1021 NumericString& operator=(const char* str)
1022 { AsnString::operator=(str); return *this;}
1023 NumericString& operator=(const std::string& str)
1024 { AsnString::operator=(str); return *this; }
1025
1026 AsnType* Clone() const { return new NumericString(*this); }
1027 const char* typeName() const { return "NumericString"; }
1028 BER_UNIV_CODE tagCode() const { return NUMERICSTRING_TAG_CODE; }
1029
1030 virtual const SizeConstraint* SizeConstraints(int &sizeList)const;
1031
1032 const char* PermittedAlphabet(int &alphaSize) const;
1033
1034 bool check() const; // Enforce string rules
1035 };
1036
1037
1038 class SNACCDLL_API PrintableString : public AsnString
1039 {
1040 public:
1041 PrintableString(const char* str = NULL) : AsnString(str) { }
1042 PrintableString(const std::string& str) : AsnString(str) { }
1043
1044 PrintableString& operator=(const char* str)
1045 { AsnString::operator=(str); return *this;}
1046 PrintableString& operator=(const std::string& str)
1047 { AsnString::operator=(str); return *this; }
1048
1049 AsnType* Clone() const { return new PrintableString(*this); }
1050 const char* typeName() const { return "PrintableString"; }
1051 BER_UNIV_CODE tagCode() const { return PRINTABLESTRING_TAG_CODE; }
1052
1053 virtual const SizeConstraint* SizeConstraints(int &sizeList)const { sizeList = 0; return NULL;}
1054
1055 const char* PermittedAlphabet(int &sizeAlpha) const;
1056
1057 bool check() const; // Enforce string rules
1058 };
1059
1060
1061 class SNACCDLL_API TeletexString : public AsnString
1062 {
1063 public:
1064 TeletexString(const char* str = NULL) : AsnString(str) {}
1065 TeletexString(const std::string& str) : AsnString(str) {}
1066
1067 TeletexString& operator=(const char* str)
1068 { AsnString::operator=(str); return *this;}
1069 TeletexString& operator=(const std::string& str)
1070 { AsnString::operator=(str); return *this; }
1071
1072 AsnType* Clone() const { return new TeletexString(*this); }
1073 const char* typeName() const { return "TeletexString"; }
1074 BER_UNIV_CODE tagCode() const { return TELETEXSTRING_TAG_CODE; }
1075 };
1076
1077 // T61String -- Alternate name for TeletexString
1078 typedef TeletexString T61String;
1079
1080
1081 class SNACCDLL_API VideotexString : public AsnString
1082 {
1083 public:
1084 VideotexString(const char* str = NULL) : AsnString(str) {}
1085 VideotexString(const std::string& str) : AsnString(str) {}
1086
1087 VideotexString& operator=(const char* str)
1088 { AsnString::operator=(str); return *this;}
1089 VideotexString& operator=(const std::string& str)
1090 { AsnString::operator=(str); return *this; }
1091
1092 AsnType* Clone() const { return new VideotexString(*this); }
1093 const char* typeName() const { return "VideotexString"; }
1094 BER_UNIV_CODE tagCode() const { return VIDEOTEXSTRING_TAG_CODE; }
1095 };
1096
1097 class SNACCDLL_API IA5String : public AsnString
1098 {
1099 public:
1100 IA5String(const char* str = NULL) : AsnString(str) { }
1101 IA5String(const std::string& str) : AsnString(str) { }
1102
1103 IA5String& operator=(const char* str)
1104 { AsnString::operator=(str); return *this;}
1105 IA5String& operator=(const std::string& str)
1106 { AsnString::operator=(str); return *this;}
1107
1108 AsnType* Clone() const { return new IA5String(*this); }
1109 const char* typeName() const { return "IA5String"; }
1110 BER_UNIV_CODE tagCode() const { return IA5STRING_TAG_CODE; }
1111
1112 virtual const SizeConstraint* SizeConstraints(int &sizeList)const { sizeList = 0; return NULL;}
1113 const char* PermittedAlphabet(int &sizeAlpha) const;
1114
1115 bool check() const; // Enforce string rules
1116 };
1117
1118
1119 class SNACCDLL_API GraphicString : public AsnString
1120 {
1121 public:
1122 GraphicString(const char* str = NULL) : AsnString(str) {}
1123 GraphicString(const std::string& str) : AsnString(str) {}
1124
1125 GraphicString& operator=(const char* str)
1126 { AsnString::operator=(str); return *this;}
1127 GraphicString& operator=(const std::string& str)
1128 { AsnString::operator=(str); return *this; }
1129
1130 AsnType* Clone() const { return new GraphicString(*this); }
1131 const char* typeName() const { return "GraphicString"; }
1132 BER_UNIV_CODE tagCode() const { return GRAPHICSTRING_TAG_CODE; }
1133 };
1134
1135
1136 class SNACCDLL_API VisibleString : public AsnString
1137 {
1138 public:
1139 VisibleString(const char* str = NULL) : AsnString(str){ }
1140 VisibleString(const std::string& str) : AsnString(str){ }
1141
1142 VisibleString& operator=(const char* str)
1143 { AsnString::operator=(str); return *this;}
1144 VisibleString& operator=(const std::string& str)
1145 { AsnString::operator=(str); return *this; }
1146
1147 AsnType* Clone() const { return new VisibleString(*this); }
1148 const char* typeName() const { return "VisibleString"; }
1149 BER_UNIV_CODE tagCode() const { return VISIBLESTRING_TAG_CODE; }
1150
1151 virtual const SizeConstraint* SizeConstraints(int &sizeList)const { sizeList = 0; return NULL;}
1152 const char* PermittedAlphabet(int &sizeAlpha) const;
1153
1154 bool check() const; // Enforce string rules
1155 };
1156
1157 // ISO646String -- Alternate name for VisibleString
1158 typedef VisibleString ISO646String;
1159
1160
1161 class SNACCDLL_API GeneralString : public AsnString
1162 {
1163 public:
1164 GeneralString(const char* str = NULL) : AsnString(str) {}
1165 GeneralString(const std::string& str) : AsnString(str) {}
1166
1167 GeneralString& operator=(const char* str)
1168 { AsnString::operator=(str); return *this;}
1169 GeneralString& operator=(const std::string& str)
1170 { AsnString::operator=(str); return *this; }
1171
1172 AsnType* Clone() const { return new GeneralString(*this); }
1173 const char* typeName() const { return "GeneralString"; }
1174 BER_UNIV_CODE tagCode() const { return GENERALSTRING_TAG_CODE; }
1175 };
1176
1177
1178 // Multi-byte character based definitions... BMP, Universal, UTF8.
1179 class SNACCDLL_API WideAsnString : public std::wstring, public AsnType, protected PERGeneral
1180 {
1181 public:
1182 WideAsnString(const char* str = NULL) { set(str); }
1183 WideAsnString(const std::string& str) { set(str.c_str()); }
1184 WideAsnString(const std::wstring& wstr) { assign(wstr); }
1185
1186
1187 // each string type must implement these methods
1188 //
1189 // tagCode should be implemented to return the ASN.1 tag corresponding to the
1190 // character string type.
1191 //
1192 // the check method should be implemented to enforce any rules imposed on the
1193 // character string type.
1194 virtual BER_UNIV_CODE tagCode() const = 0;
1195 // virtual bool check() const = 0;
1196
1197 virtual const SizeConstraint* SizeConstraints(int &sizeList)const { sizeList = 0; return NULL;}
1198
1199 AsnLen BEnc(AsnBuf &b) const;
1200 void BDec(const AsnBuf &b, AsnLen &bytesDecoded);
1201 virtual AsnLen BEncContent(AsnBuf &b) const = 0;
1202 virtual void BDecContent(const AsnBuf &b, AsnTag tagId, AsnLen elmtLen,
1203 AsnLen &bytesDecoded) = 0;
1204
1205 AsnLen PEnc(AsnBufBits &b)const;
1206
1207 void PDec(AsnBufBits &b, AsnLen &bitsDecoded);
1208
1209 void Print(std::ostream& os, unsigned short indent = 0) const;
1210 void PrintXML(std::ostream &os, const char *lpszTitle) const;
1211
1212 int checkConstraints (ConstraintFailList* pConstraintFails)const;
1213 const char* checkStringTypPermittedAlpha(const char* m_Alpha, long m_AlphaSize)const;
1214
1215 virtual bool check() const { return true; }
1216 virtual const char* PermittedAlphabet(int &sizeAlpha)const { sizeAlpha = 0; return NULL;};
1217
1218 void set(const char* str);
1219
1220 void getAsUTF8(std::string &utf8String) const;
1221 char* getAsUTF8() const;
1222
1223 protected:
1224 void Clear() { erase(); }
1225 void putWideChar(wchar_t* seg){append(seg, 1);}
1226 long lEncLen()const{return length();}
1227 wchar_t* getWideChar(long offset)const;
1228 virtual AsnLen Interpret(AsnBufBits &b, long offset)const;
1229
1230 virtual void Deterpret(AsnBufBits &b, AsnLen &bitsDecoded, long offset);
1231 virtual void Allocate(long){/*std::string automatically allocates mem*/};
1232
1233 AsnLen CombineConsString(const AsnBuf &b, AsnLen elmtLen, std::string& encStr);
1234 };
1235
1236 class SNACCDLL_API BMPString : public WideAsnString
1237 {
1238 public:
1239 BMPString(const char* str = NULL) : WideAsnString(str) {}
1240 BMPString(const std::string& str) : WideAsnString(str) {}
1241 BMPString(const std::wstring& wstr) : WideAsnString(wstr) {}
1242
1243 BMPString& operator=(const char* str)
1244 { set(str); return *this;}
1245 BMPString& operator=(const std::string& str)
1246 { set(str.c_str()); return *this; }
1247 BMPString& operator=(const std::wstring& wstr)
1248 { assign(wstr); return *this; }
1249
1250 AsnType* Clone() const { return new BMPString(*this); }
1251 const char* typeName() const { return "BMPString"; }
1252 BER_UNIV_CODE tagCode() const { return BMPSTRING_TAG_CODE; }
1253
1254 AsnLen BEncContent(AsnBuf &b) const;
1255 void BDecContent(const AsnBuf &b, AsnTag tagId, AsnLen elmtLen,
1256 AsnLen &bytesDecoded);
1257 };
1258
1259
1260 class SNACCDLL_API UniversalString : public WideAsnString
1261 {
1262 public:
1263 UniversalString(const char* str = NULL) : WideAsnString(str) {}
1264 UniversalString(const std::string& str) : WideAsnString(str) {}
1265 UniversalString(const std::wstring& wstr) : WideAsnString(wstr) {}
1266
1267 UniversalString& operator=(const char* str)
1268 { set(str); return *this;}
1269 UniversalString& operator=(const std::string& str)
1270 { set(str.c_str()); return *this; }
1271 UniversalString& operator=(const std::wstring& wstr)
1272 { assign(wstr); return *this; }
1273
1274 AsnType* Clone() const { return new UniversalString(*this); }
1275 const char* typeName() const { return "UniversalString"; }
1276 BER_UNIV_CODE tagCode() const { return UNIVERSALSTRING_TAG_CODE; }
1277
1278 AsnLen BEncContent(AsnBuf &b) const;
1279 void BDecContent(const AsnBuf &b, AsnTag tagId, AsnLen elmtLen,
1280 AsnLen &bytesDecoded);
1281
1282 /*void PDecConstent(const AsnBuf&b, AsnTag tagId, AsnLen elmtLen,
1283 * AsnLen &bytesDecoded);
1284 */
1285 };
1286
1287
1288 class SNACCDLL_API UTF8String : public WideAsnString
1289 {
1290 public:
1291 UTF8String(const char* str = NULL) : WideAsnString(str) {}
1292 UTF8String(const std::string& str) : WideAsnString(str) {}
1293 UTF8String(const std::wstring& wstr) : WideAsnString(wstr) {}
1294
1295 UTF8String& operator=(const char* str)
1296 { set(str); return *this;}
1297 UTF8String& operator=(const std::string& str)
1298 { set(str.c_str()); return *this; }
1299 UTF8String& operator=(const std::wstring& wstr)
1300 { assign(wstr); return *this; }
1301
1302 AsnType* Clone() const { return new UTF8String(*this); }
1303 const char* typeName() const { return "UTF8String"; }
1304 BER_UNIV_CODE tagCode() const { return UTF8STRING_TAG_CODE; }
1305
1306 AsnLen BEncContent(AsnBuf &b) const;
1307 void BDecContent(const AsnBuf &b, AsnTag tagId, AsnLen elmtLen,
1308 AsnLen &bytesDecoded);
1309 };
1310
1311 //########################################################################
1312
1313 // Time Classes
1314 //
1315 class SNACCDLL_API UTCTime : public VisibleString
1316 {
1317 public:
1318 UTCTime(const char* str = NULL) : VisibleString(str) {}
1319 UTCTime(const std::string& str) : VisibleString(str) {}
1320
1321 UTCTime& operator=(const char* str)
1322 { VisibleString::operator=(str); return *this;}
1323 UTCTime& operator=(const std::string& str)
1324 { VisibleString::operator=(str); return *this; }
1325
1326 AsnType* Clone() const { return new UTCTime(*this); }
1327 const char* typeName() const { return "UTCTime"; }
1328
1329 // ASN.1 tag for the character string
1330 BER_UNIV_CODE tagCode() const { return UTCTIME_TAG_CODE; }
1331 };
1332
1333
1334 class SNACCDLL_API GeneralizedTime : public VisibleString
1335 {
1336 public:
1337 GeneralizedTime(const char* str = NULL) : VisibleString(str) {}
1338 GeneralizedTime(const std::string& str) : VisibleString(str) {}
1339
1340 GeneralizedTime& operator=(const char* str)
1341 { VisibleString::operator=(str); return *this;}
1342 GeneralizedTime& operator=(const std::string& str)
1343 { VisibleString::operator=(str); return *this; }
1344
1345 AsnType* Clone() const { return new GeneralizedTime(*this); }
1346 const char* typeName() const { return "GeneralizedTime"; }
1347 BER_UNIV_CODE tagCode() const { return GENERALIZEDTIME_TAG_CODE; }
1348 };
1349
1350 // Object Descriptor class
1351 class SNACCDLL_API ObjectDescriptor : public GraphicString
1352 {
1353 public:
1354 ObjectDescriptor(const char* str = NULL) : GraphicString(str) {}
1355 ObjectDescriptor(const std::string& str) : GraphicString(str) {}
1356
1357 ObjectDescriptor& operator=(const char* str)
1358 { GraphicString::operator=(str); return *this;}
1359 ObjectDescriptor& operator=(const std::string& str)
1360 { GraphicString::operator=(str); return *this; }
1361
1362 AsnType* Clone() const { return new ObjectDescriptor(*this); }
1363 const char* typeName() const { return "ObjectDescriptor"; }
1364 BER_UNIV_CODE tagCode() const { return OD_TAG_CODE; }
1365 };
1366
1367 //########################################################################
1368
1369 // AnyDefinedBy is currently the same as AsnAny:
1370 typedef AsnAny AsnAnyDefinedBy;
1371
1372 /* JKG -- 01/27/2004
1373 AsnExtension class added in support for ASN.1 Extensibility syntax */
1374 class SNACCDLL_API AsnExtension : public AsnType
1375 {
1376 public:
1377 std::list<AsnAny> extList;
1378
1379 AsnExtension() {}
1380 AsnExtension(const AsnExtension &ext) { operator=(ext);}
1381 ~AsnExtension() {}
1382
1383 AsnType* Clone() const { return new AsnExtension(*this); }
1384 const char* typeName() const { return "AsnExtension"; }
1385
1386 void operator=(const AsnExtension& ext){extList = ext.extList;}
1387
1388 int checkConstraints(ConstraintFailList* ) const { return 0; }
1389
1390 void BDec(const AsnBuf&, AsnLen&) {/* Implemented in generated code */}
1391 void PDec(AsnBufBits&, AsnLen&) {/* Implemented in generated code */}
1392 AsnLen BEnc(AsnBuf& b) const;
1393 AsnLen PEnc(AsnBufBits& b) const;
1394
1395 void Print (std::ostream& os, unsigned short indent = 0) const;
1396 void PrintXML (std::ostream &, const char * = NULL) const {}
1397 };
1398
1399
1400 void SNACCDLL_API threadLock();
1401 void SNACCDLL_API threadUnlock();
1402 void SNACCDLL_API threadDestroy();
1403 extern "C" {
1404 void SNACCDLL_API SNACC_CleanupMemory();
1405 }
1406
1407
1408 //########################################################################
1409 //########################################################################
1410
1411 _END_SNACC_NAMESPACE
1412
1413
1414 // Overload of operator<< to stream out an AsnType
1415 SNACCDLL_API std::ostream& operator<<(std::ostream& os,
1416 const SNACC::AsnType& a);
1417
1418
1419 #include "snaccexcept.h"
1420 #include "asn-usefultypes.h"
1421
1422 #endif