PTLib  Version 2.10.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
asner.h
Go to the documentation of this file.
1 /*
2  * asner.h
3  *
4  * Abstract Syntax Notation Encoding Rules classes
5  *
6  * Portable Windows Library
7  *
8  * Copyright (c) 1993-2002 Equivalence Pty. Ltd.
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Portable Windows Library.
21  *
22  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23  *
24  * Contributor(s): ______________________________________.
25  *
26  * $Revision: 24177 $
27  * $Author: rjongbloed $
28  * $Date: 2010-04-05 06:52:04 -0500 (Mon, 05 Apr 2010) $
29  */
30 
31 #ifndef PTLIB_ASNER_H
32 #define PTLIB_ASNER_H
33 
34 #ifdef P_USE_PRAGMA
35 #pragma interface
36 #endif
37 
38 // provide options to omit vertain encodings, if needed
39 #define P_INCLUDE_PER
40 #define P_INCLUDE_BER
41 #define P_INCLUDE_XER
42 
43 class PASN_Stream;
44 class PBER_Stream;
45 class PPER_Stream;
46 
47 #ifdef P_EXPAT
48 class PXER_Stream;
49 class PXMLElement;
50 #else
51 #undef P_INCLUDE_XER
52 #endif
53 
54 
56 
59 class PASN_Object : public PObject
60 {
61  PCLASSINFO(PASN_Object, PObject);
62  public:
64  virtual PString GetTypeAsString() const = 0;
65 
66  PINDEX GetObjectLength() const;
67  virtual PINDEX GetDataLength() const = 0;
68  virtual PBoolean IsPrimitive() const { return true; }
69 
70  virtual PBoolean Decode(PASN_Stream &) = 0;
71  virtual void Encode(PASN_Stream &) const = 0;
72 
73  PBoolean IsExtendable() const { return extendable; }
74  void SetExtendable(PBoolean ext = true) { extendable = ext; }
75 
76  enum TagClass {
82  };
83  TagClass GetTagClass() const { return tagClass; }
84 
113  };
114 
115  unsigned GetTag() const { return tag; }
116  virtual void SetTag(unsigned newTag, TagClass tagClass = DefaultTagClass);
117 
123  };
124 
125  enum MinimumValueTag { MinimumValue = INT_MIN };
126  enum MaximumValueTag { MaximumValue = INT_MAX };
127  void SetConstraints(ConstraintType type, int value)
128  { SetConstraintBounds(type, value, value); }
129  void SetConstraints(ConstraintType, int lower, MaximumValueTag /*upper*/)
130  { SetConstraintBounds(PartiallyConstrained, (int)lower, lower < 0 ? INT_MAX : UINT_MAX); }
131  void SetConstraints(ConstraintType, MinimumValueTag lower, unsigned upper)
132  { SetConstraintBounds(PartiallyConstrained, (int)lower, (unsigned)upper); }
134  { SetConstraintBounds(PartiallyConstrained, (int)lower, (unsigned)upper); }
135  void SetConstraints(ConstraintType type, int lower, unsigned upper)
136  { SetConstraintBounds(type, lower, upper); }
137 
138  virtual void SetConstraintBounds(ConstraintType type, int lower, unsigned upper);
139  virtual void SetCharacterSet(ConstraintType ctype, const char * charSet);
140  virtual void SetCharacterSet(ConstraintType ctype, unsigned firstChar, unsigned lastChar);
141 
142  static PINDEX GetMaximumArraySize();
143  static void SetMaximumArraySize(PINDEX sz);
144  static PINDEX GetMaximumStringSize();
145  static void SetMaximumStringSize(PINDEX sz);
146 
147  protected:
148  PASN_Object(unsigned tag, TagClass tagClass, PBoolean extend = false);
149 
155  unsigned tag;
156 };
157 
158 
162 {
163  PCLASSINFO(PASN_ConstrainedObject, PASN_Object);
164  public:
166  int GetLowerLimit() const { return lowerLimit; }
167  unsigned GetUpperLimit() const { return upperLimit; }
168 
169  PBoolean ConstrainedLengthDecode(PPER_Stream & strm, unsigned & length);
170  void ConstrainedLengthEncode(PPER_Stream & strm, unsigned length) const;
171 
172  PBoolean ConstraintEncode(PPER_Stream & strm, unsigned value) const;
173 
174  protected:
175  virtual void SetConstraintBounds(ConstraintType type, int lower, unsigned upper);
177 
180  unsigned upperLimit;
181 };
182 
183 
186 class PASN_Null : public PASN_Object
187 {
188  PCLASSINFO(PASN_Null, PASN_Object);
189  public:
190  PASN_Null(unsigned tag = UniversalNull,
192 
193  virtual Comparison Compare(const PObject & obj) const;
194  virtual PObject * Clone() const;
195  virtual void PrintOn(ostream & strm) const;
196 
197  virtual PString GetTypeAsString() const;
198  virtual PINDEX GetDataLength() const;
199  virtual PBoolean Decode(PASN_Stream &);
200  virtual void Encode(PASN_Stream &) const;
201 };
202 
203 
206 class PASN_Boolean : public PASN_Object
207 {
208  PCLASSINFO(PASN_Boolean, PASN_Object);
209  public:
210  PASN_Boolean(PBoolean val = false);
211  PASN_Boolean(unsigned tag, TagClass tagClass, PBoolean val = false);
212 
213  PASN_Boolean & operator=(PBoolean v) { value = v; return *this; }
214  operator PBoolean() const { return value; }
215  PBoolean GetValue() const { return value; }
216  void SetValue(PBoolean v) { value = v; }
217 
218  virtual Comparison Compare(const PObject & obj) const;
219  virtual PObject * Clone() const;
220  virtual void PrintOn(ostream & strm) const;
221 
222  virtual PString GetTypeAsString() const;
223  virtual PINDEX GetDataLength() const;
224  virtual PBoolean Decode(PASN_Stream &);
225  virtual void Encode(PASN_Stream &) const;
226 
227  protected:
229 };
230 
231 
235 {
237  public:
238  PASN_Integer(unsigned val = 0);
239  PASN_Integer(unsigned tag, TagClass tagClass, unsigned val = 0);
240 
241  PASN_Integer & operator=(unsigned value);
242  operator unsigned() const { return value; }
243  unsigned GetValue() const { return value; }
244  void SetValue(unsigned v) { operator=(v); }
245 
246  virtual Comparison Compare(const PObject & obj) const;
247  virtual PObject * Clone() const;
248  virtual void PrintOn(ostream & strm) const;
249 
250  virtual void SetConstraintBounds(ConstraintType type, int lower, unsigned upper);
251  virtual PString GetTypeAsString() const;
252  virtual PINDEX GetDataLength() const;
253  virtual PBoolean Decode(PASN_Stream &);
254  virtual void Encode(PASN_Stream &) const;
255 
256 #ifdef P_INCLUDE_PER
257  PBoolean DecodePER(PPER_Stream & strm);
258  void EncodePER(PPER_Stream & strm) const;
259 #endif
260 
261  PBoolean IsUnsigned() const;
262 
263  protected:
264  unsigned value;
265 };
266 
267 struct PASN_Names{
268  const char * name;
269  PINDEX value;
270 };
271 
275 {
276  PCLASSINFO(PASN_Enumeration, PASN_Object);
277  public:
278  PASN_Enumeration(unsigned val = 0);
279  PASN_Enumeration(unsigned tag,
281  unsigned nEnums = P_MAX_INDEX,
282  PBoolean extendable = false,
283  unsigned val = 0);
284  PASN_Enumeration(unsigned tag,
285  TagClass tagClass,
286  unsigned nEnums,
288  const PASN_Names * nameSpec,
289  unsigned namesCnt,
290  unsigned val = 0);
291 
292  PASN_Enumeration & operator=(unsigned v) { value = v; return *this; }
293  operator unsigned() const { return value; }
294  unsigned GetValue() const { return value; }
295  void SetValue(unsigned v) { value = v; }
296 
297  unsigned GetMaximum() const { return maxEnumValue; }
298 
299  virtual Comparison Compare(const PObject & obj) const;
300  virtual PObject * Clone() const;
301  virtual void PrintOn(ostream & strm) const;
302 
303  virtual PString GetTypeAsString() const;
304  virtual PINDEX GetDataLength() const;
305  virtual PBoolean Decode(PASN_Stream &);
306  virtual void Encode(PASN_Stream &) const;
307 
308 #ifdef P_INCLUDE_PER
309  PBoolean DecodePER(PPER_Stream & strm);
310  void EncodePER(PPER_Stream & strm) const;
311 #endif
312 
313 #ifdef P_INCLUDE_XER
314  virtual PBoolean DecodeXER(PXER_Stream & strm);
315  virtual void EncodeXER(PXER_Stream & strm) const;
316 #endif
317 
318  PINDEX GetValueByName(PString name) const;
319  protected:
320  unsigned maxEnumValue;
321  unsigned value;
323  unsigned namesCount;
324 };
325 
326 
329 class PASN_Real : public PASN_Object
330 {
331  PCLASSINFO(PASN_Real, PASN_Object);
332  public:
333  PASN_Real(double val = 0);
334  PASN_Real(unsigned tag, TagClass tagClass, double val = 0);
335 
336  PASN_Real & operator=(double val) { value = val; return *this; }
337  operator double() const { return value; }
338  double GetValue() const { return value; }
339  void SetValue(double v) { value = v; }
340 
341  virtual Comparison Compare(const PObject & obj) const;
342  virtual PObject * Clone() const;
343  virtual void PrintOn(ostream & strm) const;
344 
345  virtual PString GetTypeAsString() const;
346  virtual PINDEX GetDataLength() const;
347  virtual PBoolean Decode(PASN_Stream &);
348  virtual void Encode(PASN_Stream &) const;
349 
350  protected:
351  double value;
352 };
353 
354 
358 {
359  PCLASSINFO(PASN_ObjectId, PASN_Object);
360  public:
361  PASN_ObjectId(const char * dotstr = NULL);
362  PASN_ObjectId(unsigned tag, TagClass tagClass);
363 
364  PASN_ObjectId(const PASN_ObjectId & other);
365  PASN_ObjectId & operator=(const PASN_ObjectId & other);
366 
367  PASN_ObjectId & operator=(const char * dotstr);
368  PASN_ObjectId & operator=(const PString & dotstr);
369  PASN_ObjectId & operator=(const PUnsignedArray & numbers);
370  void SetValue(const PString & dotstr);
371  void SetValue(const PUnsignedArray & numbers) { value = numbers; }
372  void SetValue(const unsigned * numbers, PINDEX size);
373 
374  bool operator==(const char * dotstr) const;
375  bool operator!=(const char * dotstr) const { return !operator==(dotstr); }
376  bool operator==(const PString & dotstr) const { return operator==((const char *)dotstr); }
377  bool operator!=(const PString & dotstr) const { return !operator==((const char *)dotstr); }
378  bool operator==(const PASN_ObjectId & id) const { return value == id.value; }
379 
380  PINDEX GetSize() const { return value.GetSize(); }
381  unsigned operator[](PINDEX idx) const { return value[idx]; }
382  const PUnsignedArray & GetValue() const { return value; }
383  PString AsString() const;
384 
385  virtual Comparison Compare(const PObject & obj) const;
386  virtual PObject * Clone() const;
387  virtual void PrintOn(ostream & strm) const;
388 
389  virtual PString GetTypeAsString() const;
390  virtual PINDEX GetDataLength() const;
391  virtual PBoolean Decode(PASN_Stream &);
392  virtual void Encode(PASN_Stream &) const;
393 
394  PBoolean CommonDecode(PASN_Stream & strm, unsigned dataLen);
395  void CommonEncode(PBYTEArray & eObjId) const;
396 
397  protected:
399 };
400 
401 
405 {
407  public:
408  PASN_BitString(unsigned nBits = 0, const BYTE * buf = NULL);
409  PASN_BitString(unsigned tag, TagClass tagClass, unsigned nBits = 0);
410 
411  PASN_BitString(const PASN_BitString & other);
412  PASN_BitString & operator=(const PASN_BitString & other);
413 
414  void SetData(unsigned nBits, const PBYTEArray & bytes);
415  void SetData(unsigned nBits, const BYTE * buf, PINDEX size = 0);
416 
417  const BYTE * GetDataPointer() const { return bitData; }
418 
419  unsigned GetSize() const { return totalBits; }
420  PBoolean SetSize(unsigned nBits);
421 
422  bool operator[](PINDEX bit) const;
423  void Set(unsigned bit);
424  void Clear(unsigned bit);
425  void Invert(unsigned bit);
426 
427  virtual Comparison Compare(const PObject & obj) const;
428  virtual PObject * Clone() const;
429  virtual void PrintOn(ostream & strm) const;
430 
431  virtual void SetConstraintBounds(ConstraintType type, int lower, unsigned upper);
432  virtual PString GetTypeAsString() const;
433  virtual PINDEX GetDataLength() const;
434  virtual PBoolean Decode(PASN_Stream &);
435  virtual void Encode(PASN_Stream &) const;
436 
437 #ifdef P_INCLUDE_BER
438  PBoolean DecodeBER(PBER_Stream & strm, unsigned len);
439  void EncodeBER(PBER_Stream & strm) const;
440 #endif
441 
442 #ifdef P_INCLUDE_PER
443  PBoolean DecodePER(PPER_Stream & strm);
444  void EncodePER(PPER_Stream & strm) const;
445 #endif
446 
447  PBoolean DecodeSequenceExtensionBitmap(PPER_Stream & strm);
448  void EncodeSequenceExtensionBitmap(PPER_Stream & strm) const;
449 
450  protected:
451  unsigned totalBits;
453 };
454 
455 
459 {
461  public:
462  PASN_OctetString(const char * str = NULL, PINDEX size = 0);
464 
465  PASN_OctetString(const PASN_OctetString & other);
467 
468  PASN_OctetString & operator=(const char * str);
469  PASN_OctetString & operator=(const PString & str);
470  PASN_OctetString & operator=(const PBYTEArray & arr);
471  void SetValue(const char * str) { operator=(str); }
472  void SetValue(const PString & str) { operator=(str); }
473  void SetValue(const PBYTEArray & arr) { operator=(arr); }
474  void SetValue(const BYTE * data, PINDEX len);
475  const PBYTEArray & GetValue() const { return value; }
476  operator const PBYTEArray &() const { return value; }
477  operator const BYTE *() const { return value; }
478  PString AsString() const;
479  BYTE operator[](PINDEX i) const { return value[i]; }
480  BYTE & operator[](PINDEX i) { return value[i]; }
481  BYTE * GetPointer(PINDEX sz = 0) { return value.GetPointer(sz); }
482  PINDEX GetSize() const { return value.GetSize(); }
483  PBoolean SetSize(PINDEX newSize);
484 
485  virtual Comparison Compare(const PObject & obj) const;
486  virtual PObject * Clone() const;
487  virtual void PrintOn(ostream & strm) const;
488 
489  virtual void SetConstraintBounds(ConstraintType type, int lower, unsigned upper);
490  virtual PString GetTypeAsString() const;
491  virtual PINDEX GetDataLength() const;
492  virtual PBoolean Decode(PASN_Stream &);
493  virtual void Encode(PASN_Stream &) const;
494 
495 #ifdef P_INCLUDE_PER
496  PBoolean DecodePER(PPER_Stream & strm);
497  void EncodePER(PPER_Stream & strm) const;
498 #endif
499 
501  void EncodeSubType(const PASN_Object &);
502 
503  protected:
505 };
506 
507 
511 {
513  public:
514  PASN_ConstrainedString & operator=(const char * str);
515  PASN_ConstrainedString & operator=(const PString & str) { return operator=((const char *)str); }
516  operator const PString &() const { return value; }
517  const PString & GetValue() const { return value; }
518  void SetValue(const char * v) { operator=(v); }
519  void SetValue(const PString & v) { operator=(v); }
520  char operator[](PINDEX idx) const { return value[idx]; }
521 
522  void SetCharacterSet(ConstraintType ctype, const char * charSet);
523  void SetCharacterSet(ConstraintType ctype, unsigned firstChar = 0, unsigned lastChar = 255);
524  void SetCharacterSet(const char * charSet, PINDEX size, ConstraintType ctype);
525 
526  virtual Comparison Compare(const PObject & obj) const;
527  virtual void PrintOn(ostream & strm) const;
528 
529  virtual void SetConstraintBounds(ConstraintType type, int lower, unsigned upper);
530  virtual PINDEX GetDataLength() const;
531  virtual PBoolean Decode(PASN_Stream &);
532  virtual void Encode(PASN_Stream &) const;
533 
534 #ifdef P_INCLUDE_BER
535  PBoolean DecodeBER(PBER_Stream & strm, unsigned len);
536  void EncodeBER(PBER_Stream & strm) const;
537 #endif
538 
539 #ifdef P_INCLUDE_PER
540  PBoolean DecodePER(PPER_Stream & strm);
541  void EncodePER(PPER_Stream & strm) const;
542 #endif
543 
544  protected:
545  PASN_ConstrainedString(const char * canonicalSet, PINDEX setSize,
546  unsigned tag, TagClass tagClass);
547 
550  const char * canonicalSet;
555 };
556 
557 
558 #define DECLARE_STRING_CLASS(name) \
559  class PASN_##name##String : public PASN_ConstrainedString { \
560  PCLASSINFO(PASN_##name##String, PASN_ConstrainedString); \
561  public: \
562  PASN_##name##String(const char * str = NULL); \
563  PASN_##name##String(unsigned tag, TagClass tagClass); \
564  PASN_##name##String & operator=(const char * str); \
565  PASN_##name##String & operator=(const PString & str); \
566  virtual PObject * Clone() const; \
567  virtual PString GetTypeAsString() const; \
568  }
569 
570 DECLARE_STRING_CLASS(Numeric);
571 DECLARE_STRING_CLASS(Printable);
572 DECLARE_STRING_CLASS(Visible);
574 DECLARE_STRING_CLASS(General);
575 
576 
580 {
582  public:
583  PASN_BMPString(const char * str = NULL);
584  PASN_BMPString(const PWCharArray & wstr);
585  PASN_BMPString(unsigned tag, TagClass tagClass);
586 
587  PASN_BMPString(const PASN_BMPString & other);
588  PASN_BMPString & operator=(const PASN_BMPString & other);
589 
590  PASN_BMPString & operator=(const char * v) { return operator=(PString(v).AsUCS2()); }
591  PASN_BMPString & operator=(const PString & v) { return operator=(v.AsUCS2()); }
592  PASN_BMPString & operator=(const PWCharArray & v);
593  operator PString() const { return GetValue(); }
594  operator PWCharArray() const { return value; }
595  PString GetValue() const { return value; }
596  void GetValue(PWCharArray & v) const { v = value; }
597  void SetValue(const char * v) { operator=(PString(v).AsUCS2()); }
598  void SetValue(const PString & v) { operator=(v.AsUCS2()); }
599  void SetValue(const PWCharArray & v) { operator=(v); }
600  void SetValue(const PASN_BMPString & v) { operator=(v.value); }
601  void SetValueRaw(const PWCharArray & v) { SetValueRaw(v, v.GetSize()); }
602  void SetValueRaw(const wchar_t * val, PINDEX len);
603 
604  void SetCharacterSet(ConstraintType ctype, const char * charSet);
605  void SetCharacterSet(ConstraintType ctype, const PWCharArray & charSet);
606  void SetCharacterSet(ConstraintType ctype, unsigned firstChar, unsigned lastChar);
607 
608  virtual Comparison Compare(const PObject & obj) const;
609  virtual PObject * Clone() const;
610  virtual void PrintOn(ostream & strm) const;
611 
612  virtual PString GetTypeAsString() const;
613  virtual PINDEX GetDataLength() const;
614  virtual PBoolean Decode(PASN_Stream &);
615  virtual void Encode(PASN_Stream &) const;
616 
617 #ifdef P_INCLUDE_BER
618  PBoolean DecodeBER(PBER_Stream & strm, unsigned len);
619  void EncodeBER(PBER_Stream & strm) const;
620 #endif
621 
622 #ifdef P_INCLUDE_PER
623  PBoolean DecodePER(PPER_Stream & strm);
624  void EncodePER(PPER_Stream & strm) const;
625 #endif
626 
627  protected:
628  void Construct();
629  PBoolean IsLegalCharacter(WORD ch);
630 
631  PWCharArray value;
632  PWCharArray characterSet;
633  wchar_t firstChar, lastChar;
636 };
637 
638 
639 class PASN_GeneralisedTime : public PASN_VisibleString
640 {
641  PCLASSINFO(PASN_GeneralisedTime, PASN_VisibleString);
642  public:
644  : PASN_VisibleString(UniversalGeneralisedTime, UniversalTagClass) { }
646  : PASN_VisibleString(UniversalGeneralisedTime, UniversalTagClass) { SetValue(time); }
647  PASN_GeneralisedTime(unsigned theTag, TagClass theTagClass)
648  : PASN_VisibleString(theTag, theTagClass) { }
649 
650  PASN_GeneralisedTime & operator=(const PTime & time);
651  void SetValue(const PTime & time) { operator=(time); }
652  PTime GetValue() const;
653 };
654 
655 
656 class PASN_UniversalTime : public PASN_VisibleString
657 {
658  PCLASSINFO(PASN_UniversalTime, PASN_VisibleString);
659  public:
661  : PASN_VisibleString(UniversalUTCTime, UniversalTagClass) { }
662  PASN_UniversalTime(const PTime & time)
663  : PASN_VisibleString(UniversalUTCTime, UniversalTagClass) { SetValue(time); }
664  PASN_UniversalTime(unsigned theTag, TagClass theTagClass)
665  : PASN_VisibleString(theTag, theTagClass) { }
666 
667  PASN_UniversalTime & operator=(const PTime & time);
668  void SetValue(const PTime & time) { operator=(time); }
669  PTime GetValue() const;
670 };
671 
672 
673 class PASN_Sequence;
674 
677 class PASN_Choice : public PASN_Object
678 {
679  PCLASSINFO(PASN_Choice, PASN_Object);
680  public:
681  ~PASN_Choice();
682 
683  virtual void SetTag(unsigned newTag, TagClass tagClass = DefaultTagClass);
684  PString GetTagName() const;
685  PASN_Object & GetObject() const;
686  PBoolean IsValid() const { return choice != NULL; }
687 
688 #if defined(__GNUC__) && __GNUC__ <= 2 && __GNUC_MINOR__ < 9
689 
690  operator PASN_Null &() const;
691  operator PASN_Boolean &() const;
692  operator PASN_Integer &() const;
693  operator PASN_Enumeration &() const;
694  operator PASN_Real &() const;
695  operator PASN_ObjectId &() const;
696  operator PASN_BitString &() const;
697  operator PASN_OctetString &() const;
698  operator PASN_NumericString &() const;
699  operator PASN_PrintableString &() const;
700  operator PASN_VisibleString &() const;
701  operator PASN_IA5String &() const;
702  operator PASN_GeneralString &() const;
703  operator PASN_BMPString &() const;
704  operator PASN_Sequence &() const;
705 
706 #else
707 
708  operator PASN_Null &();
709  operator PASN_Boolean &();
710  operator PASN_Integer &();
711  operator PASN_Enumeration &();
712  operator PASN_Real &();
713  operator PASN_ObjectId &();
714  operator PASN_BitString &();
715  operator PASN_OctetString &();
716  operator PASN_NumericString &();
717  operator PASN_PrintableString &();
718  operator PASN_VisibleString &();
719  operator PASN_IA5String &();
720  operator PASN_GeneralString &();
721  operator PASN_BMPString &();
722  operator PASN_Sequence &();
723 
724  operator const PASN_Null &() const;
725  operator const PASN_Boolean &() const;
726  operator const PASN_Integer &() const;
727  operator const PASN_Enumeration &() const;
728  operator const PASN_Real &() const;
729  operator const PASN_ObjectId &() const;
730  operator const PASN_BitString &() const;
731  operator const PASN_OctetString &() const;
732  operator const PASN_NumericString &() const;
733  operator const PASN_PrintableString &() const;
734  operator const PASN_VisibleString &() const;
735  operator const PASN_IA5String &() const;
736  operator const PASN_GeneralString &() const;
737  operator const PASN_BMPString &() const;
738  operator const PASN_Sequence &() const;
739 
740 #endif
741 
742  virtual PBoolean CreateObject() = 0;
743 
744  virtual Comparison Compare(const PObject & obj) const;
745  virtual void PrintOn(ostream & strm) const;
746 
747  virtual PString GetTypeAsString() const;
748  virtual PINDEX GetDataLength() const;
749  virtual PBoolean IsPrimitive() const;
750  virtual PBoolean Decode(PASN_Stream &);
751  virtual void Encode(PASN_Stream &) const;
752 
753 #ifdef P_INCLUDE_PER
754  virtual PBoolean DecodePER(PPER_Stream &);
755  virtual void EncodePER(PPER_Stream &) const;
756 #endif
757 
758 #ifdef P_INCLUDE_XER
759  PBoolean DecodeXER(PXER_Stream &);
760  void EncodeXER(PXER_Stream &) const;
761 #endif
762 
763  PASN_Choice & operator=(const PASN_Choice & other);
764 
765  PINDEX GetValueByName(PString name) const;
766  protected:
767  PASN_Choice(unsigned nChoices = 0, PBoolean extend = false);
768  PASN_Choice(unsigned tag, TagClass tagClass, unsigned nChoices, PBoolean extend);
769  PASN_Choice(unsigned tag, TagClass tagClass, unsigned nChoices, PBoolean extend, const PASN_Names * nameSpec,unsigned namesCnt);
770 
771  PASN_Choice(const PASN_Choice & other);
772 
773  PBoolean CheckCreate() const;
774 
775  unsigned numChoices;
778  unsigned namesCount;
779 };
780 
781 
782 PARRAY(PASN_ObjectArray, PASN_Object);
783 
784 
788 {
789  PCLASSINFO(PASN_Sequence, PASN_Object);
790  public:
793  unsigned nOpts = 0, PBoolean extend = false, unsigned nExtend = 0);
794 
795  PASN_Sequence(const PASN_Sequence & other);
796  PASN_Sequence & operator=(const PASN_Sequence & other);
797 
798  PINDEX GetSize() const { return fields.GetSize(); }
799  PBoolean SetSize(PINDEX newSize);
800  PASN_Object & operator[](PINDEX i) const { return fields[i]; }
801 
802  PBoolean HasOptionalField(PINDEX opt) const;
803  void IncludeOptionalField(PINDEX opt);
804  void RemoveOptionalField(PINDEX opt);
805 
806  virtual Comparison Compare(const PObject & obj) const;
807  virtual PObject * Clone() const;
808  virtual void PrintOn(ostream & strm) const;
809 
810  virtual PString GetTypeAsString() const;
811  virtual PINDEX GetDataLength() const;
812  virtual PBoolean IsPrimitive() const;
813  virtual PBoolean Decode(PASN_Stream &);
814  virtual void Encode(PASN_Stream &) const;
815 
817  void PreambleEncode(PASN_Stream & strm) const;
818  PBoolean KnownExtensionDecode(PASN_Stream & strm, PINDEX fld, PASN_Object & field);
819  void KnownExtensionEncode(PASN_Stream & strm, PINDEX fld, const PASN_Object & field) const;
821  void UnknownExtensionsEncode(PASN_Stream & strm) const;
822 
823 #ifdef P_INCLUDE_BER
824  PBoolean PreambleDecodeBER(PBER_Stream & strm);
825  void PreambleEncodeBER(PBER_Stream & strm) const;
826  PBoolean KnownExtensionDecodeBER(PBER_Stream & strm, PINDEX fld, PASN_Object & field);
827  void KnownExtensionEncodeBER(PBER_Stream & strm, PINDEX fld, const PASN_Object & field) const;
828  PBoolean UnknownExtensionsDecodeBER(PBER_Stream & strm);
829  void UnknownExtensionsEncodeBER(PBER_Stream & strm) const;
830 #endif
831 
832 #ifdef P_INCLUDE_PER
833  PBoolean PreambleDecodePER(PPER_Stream & strm);
834  void PreambleEncodePER(PPER_Stream & strm) const;
835  PBoolean KnownExtensionDecodePER(PPER_Stream & strm, PINDEX fld, PASN_Object & field);
836  void KnownExtensionEncodePER(PPER_Stream & strm, PINDEX fld, const PASN_Object & field) const;
837  PBoolean UnknownExtensionsDecodePER(PPER_Stream & strm);
838  void UnknownExtensionsEncodePER(PPER_Stream & strm) const;
839 #endif
840 
841 #ifdef P_INCLUDE_XER
842  virtual PBoolean PreambleDecodeXER(PXER_Stream & strm);
843  virtual void PreambleEncodeXER(PXER_Stream & strm) const;
844  virtual PBoolean KnownExtensionDecodeXER(PXER_Stream & strm, PINDEX fld, PASN_Object & field);
845  virtual void KnownExtensionEncodeXER(PXER_Stream & strm, PINDEX fld, const PASN_Object & field) const;
846  virtual PBoolean UnknownExtensionsDecodeXER(PXER_Stream & strm);
847  virtual void UnknownExtensionsEncodeXER(PXER_Stream & strm) const;
848 #endif
849 
850  protected:
851  PBoolean NoExtensionsToDecode(PPER_Stream & strm);
852  PBoolean NoExtensionsToEncode(PPER_Stream & strm);
853 
854  PASN_ObjectArray fields;
860 };
861 
862 
865 class PASN_Set : public PASN_Sequence
866 {
867  PCLASSINFO(PASN_Set, PASN_Sequence);
868  public:
869  PASN_Set(unsigned tag = UniversalSet,
871  unsigned nOpts = 0, PBoolean extend = false, unsigned nExtend = 0);
872 
873  virtual PObject * Clone() const;
874  virtual PString GetTypeAsString() const;
875 };
876 
877 
881 {
882  PCLASSINFO(PASN_Array, PASN_ConstrainedObject);
883  public:
884  PINDEX GetSize() const { return array.GetSize(); }
885  PBoolean SetSize(PINDEX newSize);
886  PASN_Object & operator[](PINDEX i) const { return array[i]; }
887  void Append(PASN_Object * obj) { array.SetAt(array.GetSize(), obj); }
888  void RemoveAt(PINDEX i) { array.RemoveAt(i); }
889  void RemoveAll() { array.RemoveAll(); }
890 
891  virtual Comparison Compare(const PObject & obj) const;
892  virtual void PrintOn(ostream & strm) const;
893 
894  virtual void SetConstraintBounds(ConstraintType type, int lower, unsigned upper);
895  virtual PString GetTypeAsString() const;
896  virtual PINDEX GetDataLength() const;
897  virtual PBoolean IsPrimitive() const;
898  virtual PBoolean Decode(PASN_Stream &);
899  virtual void Encode(PASN_Stream &) const;
900 
901  virtual PASN_Object * CreateObject() const = 0;
902 
903  PASN_Array & operator=(const PASN_Array & other);
904 
905  protected:
906  PASN_Array(unsigned tag = UniversalSequence,
908 
909  PASN_Array(const PASN_Array & other);
910 
911  PASN_ObjectArray array;
912 };
913 
914 
916 
919 class PASN_Stream : public PBYTEArray
920 {
921  PCLASSINFO(PASN_Stream, PBYTEArray);
922  public:
923  PASN_Stream();
924  PASN_Stream(const PBYTEArray & bytes);
925  PASN_Stream(const BYTE * buf, PINDEX size);
926 
927  void PrintOn(ostream & strm) const;
928 
929  PINDEX GetPosition() const { return byteOffset; }
930  void SetPosition(PINDEX newPos);
931  PBoolean IsAtEnd() { return byteOffset >= GetSize(); }
932  void ResetDecoder();
933  void BeginEncoding();
934  void CompleteEncoding();
935 
936  virtual PBoolean Read(PChannel & chan) = 0;
937  virtual PBoolean Write(PChannel & chan) = 0;
938 
939  virtual PBoolean NullDecode(PASN_Null &) = 0;
940  virtual void NullEncode(const PASN_Null &) = 0;
941  virtual PBoolean BooleanDecode(PASN_Boolean &) = 0;
942  virtual void BooleanEncode(const PASN_Boolean &) = 0;
943  virtual PBoolean IntegerDecode(PASN_Integer &) = 0;
944  virtual void IntegerEncode(const PASN_Integer &) = 0;
946  virtual void EnumerationEncode(const PASN_Enumeration &) = 0;
947  virtual PBoolean RealDecode(PASN_Real &) = 0;
948  virtual void RealEncode(const PASN_Real &) = 0;
949  virtual PBoolean ObjectIdDecode(PASN_ObjectId &) = 0;
950  virtual void ObjectIdEncode(const PASN_ObjectId &) = 0;
951  virtual PBoolean BitStringDecode(PASN_BitString &) = 0;
952  virtual void BitStringEncode(const PASN_BitString &) = 0;
954  virtual void OctetStringEncode(const PASN_OctetString &) = 0;
956  virtual void ConstrainedStringEncode(const PASN_ConstrainedString &) = 0;
957  virtual PBoolean BMPStringDecode(PASN_BMPString &) = 0;
958  virtual void BMPStringEncode(const PASN_BMPString &) = 0;
959  virtual PBoolean ChoiceDecode(PASN_Choice &) = 0;
960  virtual void ChoiceEncode(const PASN_Choice &) = 0;
961  virtual PBoolean ArrayDecode(PASN_Array &) = 0;
962  virtual void ArrayEncode(const PASN_Array &) = 0;
964  virtual void SequencePreambleEncode(const PASN_Sequence &) = 0;
965  virtual PBoolean SequenceKnownDecode(PASN_Sequence &, PINDEX, PASN_Object &) = 0;
966  virtual void SequenceKnownEncode(const PASN_Sequence &, PINDEX, const PASN_Object &) = 0;
968  virtual void SequenceUnknownEncode(const PASN_Sequence &) = 0;
969 
970  BYTE ByteDecode();
971  void ByteEncode(unsigned value);
972 
973  unsigned BlockDecode(BYTE * bufptr, unsigned nBytes);
974  void BlockEncode(const BYTE * bufptr, PINDEX nBytes);
975 
976  void ByteAlign();
977 
978  protected:
979  PINDEX byteOffset;
980  unsigned bitOffset;
981 
982  private:
983  void Construct();
984 };
985 
986 #ifdef P_INCLUDE_PER
987 #include "asnper.h"
988 #endif
989 
990 #ifdef P_INCLUDE_BER
991 #include "asnber.h"
992 #endif
993 
994 #ifdef P_INCLUDE_XER
995 #include "asnxer.h"
996 #endif
997 
998 #endif // PTLIB_ASNER_H
999 
1000 
1001 // End Of File ///////////////////////////////////////////////////////////////