asner.h

Go to the documentation of this file.
00001 /*
00002  * asner.h
00003  *
00004  * Abstract Syntax Notation Encoding Rules classes
00005  *
00006  * Portable Windows Library
00007  *
00008  * Copyright (c) 1993-2002 Equivalence Pty. Ltd.
00009  *
00010  * The contents of this file are subject to the Mozilla Public License
00011  * Version 1.0 (the "License"); you may not use this file except in
00012  * compliance with the License. You may obtain a copy of the License at
00013  * http://www.mozilla.org/MPL/
00014  *
00015  * Software distributed under the License is distributed on an "AS IS"
00016  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00017  * the License for the specific language governing rights and limitations
00018  * under the License.
00019  *
00020  * The Original Code is Portable Windows Library.
00021  *
00022  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
00023  *
00024  * Contributor(s): ______________________________________.
00025  *
00026  * $Revision: 21788 $
00027  * $Author: rjongbloed $
00028  * $Date: 2008-12-11 23:42:13 -0600 (Thu, 11 Dec 2008) $
00029  */
00030 
00031 #ifndef PTLIB_ASNER_H
00032 #define PTLIB_ASNER_H
00033 
00034 #ifdef P_USE_PRAGMA
00035 #pragma interface
00036 #endif
00037 
00038 // provide options to omit vertain encodings, if needed
00039 #define     P_INCLUDE_PER
00040 #define     P_INCLUDE_BER
00041 #define     P_INCLUDE_XER
00042 
00043 class PASN_Stream;
00044 class PBER_Stream;
00045 class PPER_Stream;
00046 
00047 #ifdef P_EXPAT
00048 class PXER_Stream;
00049 class PXMLElement;
00050 #else
00051 #undef      P_INCLUDE_XER
00052 #endif
00053 
00054 
00056 
00059 class PASN_Object : public PObject
00060 {
00061     PCLASSINFO(PASN_Object, PObject);
00062   public:
00064     virtual PString GetTypeAsString() const = 0;
00065 
00066     PINDEX GetObjectLength() const;
00067     virtual PINDEX GetDataLength() const = 0;
00068     virtual PBoolean IsPrimitive() const { return PTrue; }
00069 
00070     virtual PBoolean Decode(PASN_Stream &) = 0;
00071     virtual void Encode(PASN_Stream &) const = 0;
00072 
00073     PBoolean IsExtendable() const { return extendable; }
00074     void SetExtendable(PBoolean ext = PTrue) { extendable = ext; }
00075 
00076     enum TagClass {
00077       UniversalTagClass,
00078       ApplicationTagClass,
00079       ContextSpecificTagClass,
00080       PrivateTagClass,
00081       DefaultTagClass
00082     };
00083     TagClass GetTagClass() const { return tagClass; }
00084 
00085     enum UniversalTags {
00086       InvalidUniversalTag,
00087       UniversalBoolean,
00088       UniversalInteger,
00089       UniversalBitString,
00090       UniversalOctetString,
00091       UniversalNull,
00092       UniversalObjectId,
00093       UniversalObjectDescriptor,
00094       UniversalExternalType,
00095       UniversalReal,
00096       UniversalEnumeration,
00097       UniversalEmbeddedPDV,
00098       UniversalSequence = 16,
00099       UniversalSet,
00100       UniversalNumericString,
00101       UniversalPrintableString,
00102       UniversalTeletexString,
00103       UniversalVideotexString,
00104       UniversalIA5String,
00105       UniversalUTCTime,
00106       UniversalGeneralisedTime,
00107       UniversalGeneralizedTime = UniversalGeneralisedTime,
00108       UniversalGraphicString,
00109       UniversalVisibleString,
00110       UniversalGeneralString,
00111       UniversalUniversalString,
00112       UniversalBMPString = 30
00113     };
00114 
00115     unsigned GetTag() const  { return tag; }
00116     virtual void SetTag(unsigned newTag, TagClass tagClass = DefaultTagClass);
00117 
00118     enum ConstraintType {
00119       Unconstrained,
00120       PartiallyConstrained,
00121       FixedConstraint,
00122       ExtendableConstraint
00123     };
00124 
00125     enum MinimumValueTag { MinimumValue = INT_MIN };
00126     enum MaximumValueTag { MaximumValue = INT_MAX };
00127     void SetConstraints(ConstraintType type, int value)
00128       { SetConstraintBounds(type, value, value); }
00129     void SetConstraints(ConstraintType, int lower, MaximumValueTag /*upper*/)
00130       { SetConstraintBounds(PartiallyConstrained, (int)lower, lower < 0 ? INT_MAX : UINT_MAX); }
00131     void SetConstraints(ConstraintType, MinimumValueTag lower, unsigned upper)
00132       { SetConstraintBounds(PartiallyConstrained, (int)lower, (unsigned)upper); }
00133     void SetConstraints(ConstraintType, MinimumValueTag lower, MaximumValueTag upper)
00134       { SetConstraintBounds(PartiallyConstrained, (int)lower, (unsigned)upper); }
00135     void SetConstraints(ConstraintType type, int lower, unsigned upper)
00136       { SetConstraintBounds(type, lower, upper); }
00137 
00138     virtual void SetConstraintBounds(ConstraintType type, int lower, unsigned upper);
00139     virtual void SetCharacterSet(ConstraintType ctype, const char * charSet);
00140     virtual void SetCharacterSet(ConstraintType ctype, unsigned firstChar, unsigned lastChar);
00141 
00142     static PINDEX GetMaximumArraySize();
00143     static void SetMaximumArraySize(PINDEX sz);
00144     static PINDEX GetMaximumStringSize();
00145     static void SetMaximumStringSize(PINDEX sz);
00146 
00147   protected:
00148     PASN_Object(unsigned tag, TagClass tagClass, PBoolean extend = PFalse);
00149 
00151     PBoolean extendable;
00153     TagClass tagClass;
00155     unsigned tag;
00156 };
00157 
00158 
00161 class PASN_ConstrainedObject : public PASN_Object
00162 {
00163     PCLASSINFO(PASN_ConstrainedObject, PASN_Object);
00164   public:
00165     PBoolean IsConstrained() const { return constraint != Unconstrained; }
00166     int GetLowerLimit() const { return lowerLimit; }
00167     unsigned GetUpperLimit() const { return upperLimit; }
00168 
00169     PBoolean ConstrainedLengthDecode(PPER_Stream & strm, unsigned & length);
00170     void ConstrainedLengthEncode(PPER_Stream & strm, unsigned length) const;
00171 
00172     PBoolean ConstraintEncode(PPER_Stream & strm, unsigned value) const;
00173 
00174   protected:
00175     virtual void SetConstraintBounds(ConstraintType type, int lower, unsigned upper);
00176     PASN_ConstrainedObject(unsigned tag, TagClass tagClass);
00177 
00178     ConstraintType constraint;
00179     int lowerLimit;
00180     unsigned upperLimit;
00181 };
00182 
00183 
00186 class PASN_Null : public PASN_Object
00187 {
00188     PCLASSINFO(PASN_Null, PASN_Object);
00189   public:
00190     PASN_Null(unsigned tag = UniversalNull,
00191               TagClass tagClass = UniversalTagClass);
00192 
00193     virtual Comparison Compare(const PObject & obj) const;
00194     virtual PObject * Clone() const;
00195     virtual void PrintOn(ostream & strm) const;
00196 
00197     virtual PString GetTypeAsString() const;
00198     virtual PINDEX GetDataLength() const;
00199     virtual PBoolean Decode(PASN_Stream &);
00200     virtual void Encode(PASN_Stream &) const;
00201 };
00202 
00203 
00206 class PASN_Boolean : public PASN_Object
00207 {
00208     PCLASSINFO(PASN_Boolean, PASN_Object);
00209   public:
00210     PASN_Boolean(PBoolean val = PFalse);
00211     PASN_Boolean(unsigned tag, TagClass tagClass, PBoolean val = PFalse);
00212 
00213     PASN_Boolean & operator=(PBoolean v) { value = v; return *this; }
00214     operator PBoolean() const { return value; }
00215     PBoolean GetValue() const { return value; }
00216     void SetValue(PBoolean v) { value = v; }
00217 
00218     virtual Comparison Compare(const PObject & obj) const;
00219     virtual PObject * Clone() const;
00220     virtual void PrintOn(ostream & strm) const;
00221 
00222     virtual PString GetTypeAsString() const;
00223     virtual PINDEX GetDataLength() const;
00224     virtual PBoolean Decode(PASN_Stream &);
00225     virtual void Encode(PASN_Stream &) const;
00226 
00227   protected:
00228     PBoolean value;
00229 };
00230 
00231 
00234 class PASN_Integer : public PASN_ConstrainedObject
00235 {
00236     PCLASSINFO(PASN_Integer, PASN_ConstrainedObject);
00237   public:
00238     PASN_Integer(unsigned val = 0);
00239     PASN_Integer(unsigned tag, TagClass tagClass, unsigned val = 0);
00240 
00241     PASN_Integer & operator=(unsigned value);
00242     operator unsigned() const { return value; }
00243     unsigned GetValue() const { return value; }
00244     void SetValue(unsigned v) { operator=(v); }
00245 
00246     virtual Comparison Compare(const PObject & obj) const;
00247     virtual PObject * Clone() const;
00248     virtual void PrintOn(ostream & strm) const;
00249 
00250     virtual void SetConstraintBounds(ConstraintType type, int lower, unsigned upper);
00251     virtual PString GetTypeAsString() const;
00252     virtual PINDEX GetDataLength() const;
00253     virtual PBoolean Decode(PASN_Stream &);
00254     virtual void Encode(PASN_Stream &) const;
00255 
00256 #ifdef P_INCLUDE_PER
00257     PBoolean DecodePER(PPER_Stream & strm);
00258     void EncodePER(PPER_Stream & strm) const;
00259 #endif
00260 
00261     PBoolean IsUnsigned() const;
00262 
00263   protected:
00264     unsigned value;
00265 };
00266 
00267 struct PASN_Names{
00268     const char * name;
00269     PINDEX value; 
00270 };
00271 
00274 class PASN_Enumeration : public PASN_Object
00275 {
00276     PCLASSINFO(PASN_Enumeration, PASN_Object);
00277   public:
00278     PASN_Enumeration(unsigned val = 0);
00279     PASN_Enumeration(unsigned tag,
00280                      TagClass tagClass,
00281                      unsigned nEnums = P_MAX_INDEX,
00282                      PBoolean extendable = PFalse,
00283                      unsigned val = 0);
00284     PASN_Enumeration(unsigned tag,
00285                      TagClass tagClass,
00286                      unsigned nEnums,
00287                      PBoolean extendable,
00288                      const PASN_Names * nameSpec,
00289                      unsigned namesCnt,
00290                      unsigned val = 0);
00291 
00292     PASN_Enumeration & operator=(unsigned v) { value = v; return *this; }
00293     operator unsigned() const { return value; }
00294     unsigned GetValue() const { return value; }
00295     void SetValue(unsigned v) { value = v; }
00296 
00297     unsigned GetMaximum() const { return maxEnumValue; }
00298 
00299     virtual Comparison Compare(const PObject & obj) const;
00300     virtual PObject * Clone() const;
00301     virtual void PrintOn(ostream & strm) const;
00302 
00303     virtual PString GetTypeAsString() const;
00304     virtual PINDEX GetDataLength() const;
00305     virtual PBoolean Decode(PASN_Stream &);
00306     virtual void Encode(PASN_Stream &) const;
00307 
00308 #ifdef P_INCLUDE_PER
00309     PBoolean DecodePER(PPER_Stream & strm);
00310     void EncodePER(PPER_Stream & strm) const;
00311 #endif
00312 
00313 #ifdef P_INCLUDE_XER
00314     virtual PBoolean DecodeXER(PXER_Stream & strm);
00315     virtual void EncodeXER(PXER_Stream & strm) const;
00316 #endif
00317 
00318     PINDEX GetValueByName(PString name) const;
00319   protected:
00320     unsigned maxEnumValue;
00321     unsigned value;
00322     const PASN_Names *names;
00323     unsigned namesCount;   
00324 };
00325 
00326 
00329 class PASN_Real : public PASN_Object
00330 {
00331     PCLASSINFO(PASN_Real, PASN_Object);
00332   public:
00333     PASN_Real(double val = 0);
00334     PASN_Real(unsigned tag, TagClass tagClass, double val = 0);
00335 
00336     PASN_Real & operator=(double val) { value = val; return *this; }
00337     operator double() const { return value; }
00338     double GetValue() const { return value; }
00339     void SetValue(double v) { value = v; }
00340 
00341     virtual Comparison Compare(const PObject & obj) const;
00342     virtual PObject * Clone() const;
00343     virtual void PrintOn(ostream & strm) const;
00344 
00345     virtual PString GetTypeAsString() const;
00346     virtual PINDEX GetDataLength() const;
00347     virtual PBoolean Decode(PASN_Stream &);
00348     virtual void Encode(PASN_Stream &) const;
00349 
00350   protected:
00351     double value;
00352 };
00353 
00354 
00357 class PASN_ObjectId : public PASN_Object
00358 {
00359     PCLASSINFO(PASN_ObjectId, PASN_Object);
00360   public:
00361     PASN_ObjectId(const char * dotstr = NULL);
00362     PASN_ObjectId(unsigned tag, TagClass tagClass);
00363 
00364     PASN_ObjectId(const PASN_ObjectId & other);
00365     PASN_ObjectId & operator=(const PASN_ObjectId & other);
00366 
00367     PASN_ObjectId & operator=(const char * dotstr);
00368     PASN_ObjectId & operator=(const PString & dotstr);
00369     PASN_ObjectId & operator=(const PUnsignedArray & numbers);
00370     void SetValue(const PString & dotstr);
00371     void SetValue(const PUnsignedArray & numbers) { value = numbers; }
00372     void SetValue(const unsigned * numbers, PINDEX size);
00373 
00374     bool operator==(const char * dotstr) const;
00375     bool operator!=(const char * dotstr) const      { return !operator==(dotstr); }
00376     bool operator==(const PString & dotstr) const   { return  operator==((const char *)dotstr); }
00377     bool operator!=(const PString & dotstr) const   { return !operator==((const char *)dotstr); }
00378     bool operator==(const PASN_ObjectId & id) const { return value == id.value; }
00379 
00380     PINDEX GetSize() const { return value.GetSize(); }
00381     unsigned operator[](PINDEX idx) const { return value[idx]; }
00382     const PUnsignedArray & GetValue() const { return value; }
00383     PString AsString() const;
00384 
00385     virtual Comparison Compare(const PObject & obj) const;
00386     virtual PObject * Clone() const;
00387     virtual void PrintOn(ostream & strm) const;
00388 
00389     virtual PString GetTypeAsString() const;
00390     virtual PINDEX GetDataLength() const;
00391     virtual PBoolean Decode(PASN_Stream &);
00392     virtual void Encode(PASN_Stream &) const;
00393 
00394     PBoolean CommonDecode(PASN_Stream & strm, unsigned dataLen);
00395     void CommonEncode(PBYTEArray & eObjId) const;
00396 
00397   protected:
00398     PUnsignedArray value;
00399 };
00400 
00401 
00404 class PASN_BitString : public PASN_ConstrainedObject
00405 {
00406     PCLASSINFO(PASN_BitString, PASN_ConstrainedObject);
00407   public:
00408     PASN_BitString(unsigned nBits = 0, const BYTE * buf = NULL);
00409     PASN_BitString(unsigned tag, TagClass tagClass, unsigned nBits = 0);
00410 
00411     PASN_BitString(const PASN_BitString & other);
00412     PASN_BitString & operator=(const PASN_BitString & other);
00413 
00414     void SetData(unsigned nBits, const PBYTEArray & bytes);
00415     void SetData(unsigned nBits, const BYTE * buf, PINDEX size = 0);
00416 
00417     const BYTE * GetDataPointer() const { return bitData; }
00418 
00419     unsigned GetSize() const { return totalBits; }
00420     PBoolean SetSize(unsigned nBits);
00421 
00422     bool operator[](PINDEX bit) const;
00423     void Set(unsigned bit);
00424     void Clear(unsigned bit);
00425     void Invert(unsigned bit);
00426 
00427     virtual Comparison Compare(const PObject & obj) const;
00428     virtual PObject * Clone() const;
00429     virtual void PrintOn(ostream & strm) const;
00430 
00431     virtual void SetConstraintBounds(ConstraintType type, int lower, unsigned upper);
00432     virtual PString GetTypeAsString() const;
00433     virtual PINDEX GetDataLength() const;
00434     virtual PBoolean Decode(PASN_Stream &);
00435     virtual void Encode(PASN_Stream &) const;
00436 
00437 #ifdef P_INCLUDE_BER
00438     PBoolean DecodeBER(PBER_Stream & strm, unsigned len);
00439     void EncodeBER(PBER_Stream & strm) const;
00440 #endif
00441 
00442 #ifdef P_INCLUDE_PER
00443     PBoolean DecodePER(PPER_Stream & strm);
00444     void EncodePER(PPER_Stream & strm) const;
00445 #endif
00446 
00447     PBoolean DecodeSequenceExtensionBitmap(PPER_Stream & strm);
00448     void EncodeSequenceExtensionBitmap(PPER_Stream & strm) const;
00449 
00450   protected:
00451     unsigned totalBits;
00452     PBYTEArray bitData;
00453 };
00454 
00455 
00458 class PASN_OctetString : public PASN_ConstrainedObject
00459 {
00460     PCLASSINFO(PASN_OctetString, PASN_ConstrainedObject);
00461   public:
00462     PASN_OctetString(const char * str = NULL, PINDEX size = 0);
00463     PASN_OctetString(unsigned tag, TagClass tagClass);
00464 
00465     PASN_OctetString(const PASN_OctetString & other);
00466     PASN_OctetString & operator=(const PASN_OctetString & other);
00467 
00468     PASN_OctetString & operator=(const char * str);
00469     PASN_OctetString & operator=(const PString & str);
00470     PASN_OctetString & operator=(const PBYTEArray & arr);
00471     void SetValue(const char * str) { operator=(str); }
00472     void SetValue(const PString & str) { operator=(str); }
00473     void SetValue(const PBYTEArray & arr) { operator=(arr); }
00474     void SetValue(const BYTE * data, PINDEX len);
00475     const PBYTEArray & GetValue() const { return value; }
00476     operator const PBYTEArray &() const { return value; }
00477     operator const BYTE *() const { return value; }
00478     PString AsString() const;
00479     BYTE operator[](PINDEX i) const { return value[i]; }
00480     BYTE & operator[](PINDEX i) { return value[i]; }
00481     BYTE * GetPointer(PINDEX sz = 0) { return value.GetPointer(sz); }
00482     PINDEX GetSize() const { return value.GetSize(); }
00483     PBoolean SetSize(PINDEX newSize);
00484 
00485     virtual Comparison Compare(const PObject & obj) const;
00486     virtual PObject * Clone() const;
00487     virtual void PrintOn(ostream & strm) const;
00488 
00489     virtual void SetConstraintBounds(ConstraintType type, int lower, unsigned upper);
00490     virtual PString GetTypeAsString() const;
00491     virtual PINDEX GetDataLength() const;
00492     virtual PBoolean Decode(PASN_Stream &);
00493     virtual void Encode(PASN_Stream &) const;
00494 
00495 #ifdef P_INCLUDE_PER
00496     PBoolean DecodePER(PPER_Stream & strm);
00497     void EncodePER(PPER_Stream & strm) const;
00498 #endif
00499 
00500     PBoolean DecodeSubType(PASN_Object &) const;
00501     void EncodeSubType(const PASN_Object &);
00502 
00503   protected:
00504     PBYTEArray value;
00505 };
00506 
00507 
00510 class PASN_ConstrainedString : public PASN_ConstrainedObject
00511 {
00512     PCLASSINFO(PASN_ConstrainedString, PASN_ConstrainedObject);
00513   public:
00514     PASN_ConstrainedString & operator=(const char * str);
00515     PASN_ConstrainedString & operator=(const PString & str) { return operator=((const char *)str); }
00516     operator const PString &() const { return value; }
00517     const PString & GetValue() const { return value; }
00518     void SetValue(const char * v) { operator=(v); }
00519     void SetValue(const PString & v) { operator=(v); }
00520     char operator[](PINDEX idx) const { return value[idx]; }
00521 
00522     void SetCharacterSet(ConstraintType ctype, const char * charSet);
00523     void SetCharacterSet(ConstraintType ctype, unsigned firstChar = 0, unsigned lastChar = 255);
00524     void SetCharacterSet(const char * charSet, PINDEX size, ConstraintType ctype);
00525 
00526     virtual Comparison Compare(const PObject & obj) const;
00527     virtual void PrintOn(ostream & strm) const;
00528 
00529     virtual void SetConstraintBounds(ConstraintType type, int lower, unsigned upper);
00530     virtual PINDEX GetDataLength() const;
00531     virtual PBoolean Decode(PASN_Stream &);
00532     virtual void Encode(PASN_Stream &) const;
00533 
00534 #ifdef P_INCLUDE_BER
00535     PBoolean DecodeBER(PBER_Stream & strm, unsigned len);
00536     void EncodeBER(PBER_Stream & strm) const;
00537 #endif
00538 
00539 #ifdef P_INCLUDE_PER
00540     PBoolean DecodePER(PPER_Stream & strm);
00541     void EncodePER(PPER_Stream & strm) const;
00542 #endif
00543 
00544   protected:
00545     PASN_ConstrainedString(const char * canonicalSet, PINDEX setSize,
00546                            unsigned tag, TagClass tagClass);
00547 
00548     PString value;
00549     PCharArray characterSet;
00550     const char * canonicalSet;
00551     PINDEX canonicalSetSize;
00552     unsigned canonicalSetBits;
00553     unsigned charSetUnalignedBits;
00554     unsigned charSetAlignedBits;
00555 };
00556 
00557 
00558 #define DECLARE_STRING_CLASS(name) \
00559   class PASN_##name##String : public PASN_ConstrainedString { \
00560     PCLASSINFO(PASN_##name##String, PASN_ConstrainedString); \
00561     public: \
00562       PASN_##name##String(const char * str = NULL); \
00563       PASN_##name##String(unsigned tag, TagClass tagClass); \
00564       PASN_##name##String & operator=(const char * str); \
00565       PASN_##name##String & operator=(const PString & str); \
00566       virtual PObject * Clone() const; \
00567       virtual PString GetTypeAsString() const; \
00568   }
00569 
00570 DECLARE_STRING_CLASS(Numeric);
00571 DECLARE_STRING_CLASS(Printable);
00572 DECLARE_STRING_CLASS(Visible);
00573 DECLARE_STRING_CLASS(IA5);
00574 DECLARE_STRING_CLASS(General);
00575 
00576 
00579 class PASN_BMPString : public PASN_ConstrainedObject
00580 {
00581     PCLASSINFO(PASN_BMPString, PASN_ConstrainedObject);
00582   public:
00583     PASN_BMPString(const char * str = NULL);
00584     PASN_BMPString(const PWCharArray & wstr);
00585     PASN_BMPString(unsigned tag, TagClass tagClass);
00586 
00587     PASN_BMPString(const PASN_BMPString & other);
00588     PASN_BMPString & operator=(const PASN_BMPString & other);
00589 
00590     PASN_BMPString & operator=(const char * v) { return operator=(PString(v).AsUCS2()); }
00591     PASN_BMPString & operator=(const PString & v) { return operator=(v.AsUCS2()); }
00592     PASN_BMPString & operator=(const PWCharArray & v);
00593     operator PString() const { return GetValue(); }
00594     operator PWCharArray() const { return value; }
00595     PString GetValue() const { return value; }
00596     void GetValue(PWCharArray & v) const { v = value; }
00597     void SetValue(const char * v) { operator=(PString(v).AsUCS2()); }
00598     void SetValue(const PString & v) { operator=(v.AsUCS2()); }
00599     void SetValue(const PWCharArray & v) { operator=(v); }
00600     void SetValue(const PASN_BMPString & v) { operator=(v.value); }
00601 
00602     void SetCharacterSet(ConstraintType ctype, const char * charSet);
00603     void SetCharacterSet(ConstraintType ctype, const PWCharArray & charSet);
00604     void SetCharacterSet(ConstraintType ctype, unsigned firstChar, unsigned lastChar);
00605 
00606     virtual Comparison Compare(const PObject & obj) const;
00607     virtual PObject * Clone() const;
00608     virtual void PrintOn(ostream & strm) const;
00609 
00610     virtual PString GetTypeAsString() const;
00611     virtual PINDEX GetDataLength() const;
00612     virtual PBoolean Decode(PASN_Stream &);
00613     virtual void Encode(PASN_Stream &) const;
00614 
00615 #ifdef P_INCLUDE_BER
00616     PBoolean DecodeBER(PBER_Stream & strm, unsigned len);
00617     void EncodeBER(PBER_Stream & strm) const;
00618 #endif
00619 
00620 #ifdef P_INCLUDE_PER
00621     PBoolean DecodePER(PPER_Stream & strm);
00622     void EncodePER(PPER_Stream & strm) const;
00623 #endif
00624 
00625   protected:
00626     void Construct();
00627     PBoolean IsLegalCharacter(WORD ch);
00628 
00629     PWCharArray value;
00630     PWCharArray characterSet;
00631     wchar_t firstChar, lastChar;
00632     unsigned charSetUnalignedBits;
00633     unsigned charSetAlignedBits;
00634 };
00635 
00636 
00637 class PASN_GeneralisedTime : public PASN_VisibleString
00638 {
00639     PCLASSINFO(PASN_GeneralisedTime, PASN_VisibleString);
00640   public:
00641     PASN_GeneralisedTime()
00642       : PASN_VisibleString(UniversalGeneralisedTime, UniversalTagClass) { }
00643     PASN_GeneralisedTime(const PTime & time)
00644       : PASN_VisibleString(UniversalGeneralisedTime, UniversalTagClass) { SetValue(time); }
00645     PASN_GeneralisedTime(unsigned tag, TagClass tagClass)
00646       : PASN_VisibleString(tag, tagClass) { }
00647 
00648     PASN_GeneralisedTime & operator=(const PTime & time);
00649     void SetValue(const PTime & time) { operator=(time); }
00650     PTime GetValue() const;
00651 };
00652 
00653 
00654 class PASN_UniversalTime : public PASN_VisibleString
00655 {
00656     PCLASSINFO(PASN_UniversalTime, PASN_VisibleString);
00657   public:
00658     PASN_UniversalTime()
00659       : PASN_VisibleString(UniversalUTCTime, UniversalTagClass) { }
00660     PASN_UniversalTime(const PTime & time)
00661       : PASN_VisibleString(UniversalUTCTime, UniversalTagClass) { SetValue(time); }
00662     PASN_UniversalTime(unsigned tag, TagClass tagClass)
00663       : PASN_VisibleString(tag, tagClass) { }
00664 
00665     PASN_UniversalTime & operator=(const PTime & time);
00666     void SetValue(const PTime & time) { operator=(time); }
00667     PTime GetValue() const;
00668 };
00669 
00670 
00671 class PASN_Sequence;
00672 
00675 class PASN_Choice : public PASN_Object
00676 {
00677     PCLASSINFO(PASN_Choice, PASN_Object);
00678   public:
00679     ~PASN_Choice();
00680 
00681     virtual void SetTag(unsigned newTag, TagClass tagClass = DefaultTagClass);
00682     PString GetTagName() const;
00683     PASN_Object & GetObject() const;
00684     PBoolean IsValid() const { return choice != NULL; }
00685 
00686 #if defined(__GNUC__) && __GNUC__ <= 2 && __GNUC_MINOR__ < 9
00687 
00688     operator PASN_Null &() const;
00689     operator PASN_Boolean &() const;
00690     operator PASN_Integer &() const;
00691     operator PASN_Enumeration &() const;
00692     operator PASN_Real &() const;
00693     operator PASN_ObjectId &() const;
00694     operator PASN_BitString &() const;
00695     operator PASN_OctetString &() const;
00696     operator PASN_NumericString &() const;
00697     operator PASN_PrintableString &() const;
00698     operator PASN_VisibleString &() const;
00699     operator PASN_IA5String &() const;
00700     operator PASN_GeneralString &() const;
00701     operator PASN_BMPString &() const;
00702     operator PASN_Sequence &() const;
00703 
00704 #else
00705 
00706     operator PASN_Null &();
00707     operator PASN_Boolean &();
00708     operator PASN_Integer &();
00709     operator PASN_Enumeration &();
00710     operator PASN_Real &();
00711     operator PASN_ObjectId &();
00712     operator PASN_BitString &();
00713     operator PASN_OctetString &();
00714     operator PASN_NumericString &();
00715     operator PASN_PrintableString &();
00716     operator PASN_VisibleString &();
00717     operator PASN_IA5String &();
00718     operator PASN_GeneralString &();
00719     operator PASN_BMPString &();
00720     operator PASN_Sequence &();
00721 
00722     operator const PASN_Null &() const;
00723     operator const PASN_Boolean &() const;
00724     operator const PASN_Integer &() const;
00725     operator const PASN_Enumeration &() const;
00726     operator const PASN_Real &() const;
00727     operator const PASN_ObjectId &() const;
00728     operator const PASN_BitString &() const;
00729     operator const PASN_OctetString &() const;
00730     operator const PASN_NumericString &() const;
00731     operator const PASN_PrintableString &() const;
00732     operator const PASN_VisibleString &() const;
00733     operator const PASN_IA5String &() const;
00734     operator const PASN_GeneralString &() const;
00735     operator const PASN_BMPString &() const;
00736     operator const PASN_Sequence &() const;
00737 
00738 #endif
00739 
00740     virtual PBoolean CreateObject() = 0;
00741 
00742     virtual Comparison Compare(const PObject & obj) const;
00743     virtual void PrintOn(ostream & strm) const;
00744 
00745     virtual PString GetTypeAsString() const;
00746     virtual PINDEX GetDataLength() const;
00747     virtual PBoolean IsPrimitive() const;
00748     virtual PBoolean Decode(PASN_Stream &);
00749     virtual void Encode(PASN_Stream &) const;
00750 
00751 #ifdef P_INCLUDE_PER
00752     virtual PBoolean DecodePER(PPER_Stream &);
00753     virtual void EncodePER(PPER_Stream &) const;
00754 #endif
00755 
00756 #ifdef P_INCLUDE_XER
00757     PBoolean DecodeXER(PXER_Stream &);
00758     void EncodeXER(PXER_Stream &) const;
00759 #endif
00760 
00761     PASN_Choice & operator=(const PASN_Choice & other);
00762 
00763     PINDEX GetValueByName(PString name) const;
00764   protected:
00765     PASN_Choice(unsigned nChoices = 0, PBoolean extend = PFalse);
00766     PASN_Choice(unsigned tag, TagClass tagClass, unsigned nChoices, PBoolean extend);
00767     PASN_Choice(unsigned tag, TagClass tagClass, unsigned nChoices, PBoolean extend, const PASN_Names * nameSpec,unsigned namesCnt);
00768 
00769     PASN_Choice(const PASN_Choice & other);
00770 
00771     PBoolean CheckCreate() const;
00772 
00773     unsigned numChoices;
00774     PASN_Object * choice;
00775     const PASN_Names *names;
00776     unsigned namesCount;
00777 };
00778 
00779 
00780 PARRAY(PASN_ObjectArray, PASN_Object);
00781 
00782 
00785 class PASN_Sequence : public PASN_Object
00786 {
00787     PCLASSINFO(PASN_Sequence, PASN_Object);
00788   public:
00789     PASN_Sequence(unsigned tag = UniversalSequence,
00790                   TagClass tagClass = UniversalTagClass,
00791                   unsigned nOpts = 0, PBoolean extend = PFalse, unsigned nExtend = 0);
00792 
00793     PASN_Sequence(const PASN_Sequence & other);
00794     PASN_Sequence & operator=(const PASN_Sequence & other);
00795 
00796     PINDEX GetSize() const { return fields.GetSize(); }
00797     PBoolean SetSize(PINDEX newSize);
00798     PASN_Object & operator[](PINDEX i) const { return fields[i]; }
00799 
00800     PBoolean HasOptionalField(PINDEX opt) const;
00801     void IncludeOptionalField(PINDEX opt);
00802     void RemoveOptionalField(PINDEX opt);
00803 
00804     virtual Comparison Compare(const PObject & obj) const;
00805     virtual PObject * Clone() const;
00806     virtual void PrintOn(ostream & strm) const;
00807 
00808     virtual PString GetTypeAsString() const;
00809     virtual PINDEX GetDataLength() const;
00810     virtual PBoolean IsPrimitive() const;
00811     virtual PBoolean Decode(PASN_Stream &);
00812     virtual void Encode(PASN_Stream &) const;
00813 
00814     PBoolean PreambleDecode(PASN_Stream & strm);
00815     void PreambleEncode(PASN_Stream & strm) const;
00816     PBoolean KnownExtensionDecode(PASN_Stream & strm, PINDEX fld, PASN_Object & field);
00817     void KnownExtensionEncode(PASN_Stream & strm, PINDEX fld, const PASN_Object & field) const;
00818     PBoolean UnknownExtensionsDecode(PASN_Stream & strm);
00819     void UnknownExtensionsEncode(PASN_Stream & strm) const;
00820 
00821 #ifdef P_INCLUDE_BER
00822     PBoolean PreambleDecodeBER(PBER_Stream & strm);
00823     void PreambleEncodeBER(PBER_Stream & strm) const;
00824     PBoolean KnownExtensionDecodeBER(PBER_Stream & strm, PINDEX fld, PASN_Object & field);
00825     void KnownExtensionEncodeBER(PBER_Stream & strm, PINDEX fld, const PASN_Object & field) const;
00826     PBoolean UnknownExtensionsDecodeBER(PBER_Stream & strm);
00827     void UnknownExtensionsEncodeBER(PBER_Stream & strm) const;
00828 #endif
00829 
00830 #ifdef P_INCLUDE_PER
00831     PBoolean PreambleDecodePER(PPER_Stream & strm);
00832     void PreambleEncodePER(PPER_Stream & strm) const;
00833     PBoolean KnownExtensionDecodePER(PPER_Stream & strm, PINDEX fld, PASN_Object & field);
00834     void KnownExtensionEncodePER(PPER_Stream & strm, PINDEX fld, const PASN_Object & field) const;
00835     PBoolean UnknownExtensionsDecodePER(PPER_Stream & strm);
00836     void UnknownExtensionsEncodePER(PPER_Stream & strm) const;
00837 #endif
00838 
00839 #ifdef P_INCLUDE_XER
00840     virtual PBoolean PreambleDecodeXER(PXER_Stream & strm);
00841     virtual void PreambleEncodeXER(PXER_Stream & strm) const;
00842     virtual PBoolean KnownExtensionDecodeXER(PXER_Stream & strm, PINDEX fld, PASN_Object & field);
00843     virtual void KnownExtensionEncodeXER(PXER_Stream & strm, PINDEX fld, const PASN_Object & field) const;
00844     virtual PBoolean UnknownExtensionsDecodeXER(PXER_Stream & strm);
00845     virtual void UnknownExtensionsEncodeXER(PXER_Stream & strm) const;
00846 #endif
00847 
00848   protected:
00849     PBoolean NoExtensionsToDecode(PPER_Stream & strm);
00850     PBoolean NoExtensionsToEncode(PPER_Stream & strm);
00851 
00852     PASN_ObjectArray fields;
00853     PASN_BitString optionMap;
00854     int knownExtensions;
00855     int totalExtensions;
00856     PASN_BitString extensionMap;
00857     PINDEX endBasicEncoding;
00858 };
00859 
00860 
00863 class PASN_Set : public PASN_Sequence
00864 {
00865     PCLASSINFO(PASN_Set, PASN_Sequence);
00866   public:
00867     PASN_Set(unsigned tag = UniversalSet,
00868              TagClass tagClass = UniversalTagClass,
00869              unsigned nOpts = 0, PBoolean extend = PFalse, unsigned nExtend = 0);
00870 
00871     virtual PObject * Clone() const;
00872     virtual PString GetTypeAsString() const;
00873 };
00874 
00875 
00878 class PASN_Array : public PASN_ConstrainedObject
00879 {
00880     PCLASSINFO(PASN_Array, PASN_ConstrainedObject);
00881   public:
00882     PINDEX GetSize() const { return array.GetSize(); }
00883     PBoolean SetSize(PINDEX newSize);
00884     PASN_Object & operator[](PINDEX i) const { return array[i]; }
00885     void Append(PASN_Object * obj) { array.SetAt(array.GetSize(), obj); }
00886     void RemoveAt(PINDEX i) { array.RemoveAt(i); }
00887     void RemoveAll() { array.RemoveAll(); }
00888 
00889     virtual Comparison Compare(const PObject & obj) const;
00890     virtual void PrintOn(ostream & strm) const;
00891 
00892     virtual void SetConstraintBounds(ConstraintType type, int lower, unsigned upper);
00893     virtual PString GetTypeAsString() const;
00894     virtual PINDEX GetDataLength() const;
00895     virtual PBoolean IsPrimitive() const;
00896     virtual PBoolean Decode(PASN_Stream &);
00897     virtual void Encode(PASN_Stream &) const;
00898 
00899     virtual PASN_Object * CreateObject() const = 0;
00900 
00901     PASN_Array & operator=(const PASN_Array & other);
00902 
00903   protected:
00904     PASN_Array(unsigned tag = UniversalSequence,
00905                TagClass tagClass = UniversalTagClass);
00906 
00907     PASN_Array(const PASN_Array & other);
00908 
00909     PASN_ObjectArray array;
00910 };
00911 
00912 
00914 
00917 class PASN_Stream : public PBYTEArray
00918 {
00919     PCLASSINFO(PASN_Stream, PBYTEArray);
00920   public:
00921     PASN_Stream();
00922     PASN_Stream(const PBYTEArray & bytes);
00923     PASN_Stream(const BYTE * buf, PINDEX size);
00924 
00925     void PrintOn(ostream & strm) const;
00926 
00927     PINDEX GetPosition() const { return byteOffset; }
00928     void SetPosition(PINDEX newPos);
00929     PBoolean IsAtEnd() { return byteOffset >= GetSize(); }
00930     void ResetDecoder();
00931     void BeginEncoding();
00932     void CompleteEncoding();
00933 
00934     virtual PBoolean Read(PChannel & chan) = 0;
00935     virtual PBoolean Write(PChannel & chan) = 0;
00936 
00937     virtual PBoolean NullDecode(PASN_Null &) = 0;
00938     virtual void NullEncode(const PASN_Null &) = 0;
00939     virtual PBoolean BooleanDecode(PASN_Boolean &) = 0;
00940     virtual void BooleanEncode(const PASN_Boolean &) = 0;
00941     virtual PBoolean IntegerDecode(PASN_Integer &) = 0;
00942     virtual void IntegerEncode(const PASN_Integer &) = 0;
00943     virtual PBoolean EnumerationDecode(PASN_Enumeration &) = 0;
00944     virtual void EnumerationEncode(const PASN_Enumeration &) = 0;
00945     virtual PBoolean RealDecode(PASN_Real &) = 0;
00946     virtual void RealEncode(const PASN_Real &) = 0;
00947     virtual PBoolean ObjectIdDecode(PASN_ObjectId &) = 0;
00948     virtual void ObjectIdEncode(const PASN_ObjectId &) = 0;
00949     virtual PBoolean BitStringDecode(PASN_BitString &) = 0;
00950     virtual void BitStringEncode(const PASN_BitString &) = 0;
00951     virtual PBoolean OctetStringDecode(PASN_OctetString &) = 0;
00952     virtual void OctetStringEncode(const PASN_OctetString &) = 0;
00953     virtual PBoolean ConstrainedStringDecode(PASN_ConstrainedString &) = 0;
00954     virtual void ConstrainedStringEncode(const PASN_ConstrainedString &) = 0;
00955     virtual PBoolean BMPStringDecode(PASN_BMPString &) = 0;
00956     virtual void BMPStringEncode(const PASN_BMPString &) = 0;
00957     virtual PBoolean ChoiceDecode(PASN_Choice &) = 0;
00958     virtual void ChoiceEncode(const PASN_Choice &) = 0;
00959     virtual PBoolean ArrayDecode(PASN_Array &) = 0;
00960     virtual void ArrayEncode(const PASN_Array &) = 0;
00961     virtual PBoolean SequencePreambleDecode(PASN_Sequence &) = 0;
00962     virtual void SequencePreambleEncode(const PASN_Sequence &) = 0;
00963     virtual PBoolean SequenceKnownDecode(PASN_Sequence &, PINDEX, PASN_Object &) = 0;
00964     virtual void SequenceKnownEncode(const PASN_Sequence &, PINDEX, const PASN_Object &) = 0;
00965     virtual PBoolean SequenceUnknownDecode(PASN_Sequence &) = 0;
00966     virtual void SequenceUnknownEncode(const PASN_Sequence &) = 0;
00967 
00968     BYTE ByteDecode();
00969     void ByteEncode(unsigned value);
00970 
00971     unsigned BlockDecode(BYTE * bufptr, unsigned nBytes);
00972     void BlockEncode(const BYTE * bufptr, PINDEX nBytes);
00973 
00974     void ByteAlign();
00975 
00976   protected:
00977     PINDEX byteOffset;
00978     unsigned bitOffset;
00979 
00980   private:
00981     void Construct();
00982 };
00983 
00984 #ifdef  P_INCLUDE_PER
00985 #include "asnper.h"
00986 #endif
00987 
00988 #ifdef  P_INCLUDE_BER
00989 #include "asnber.h"
00990 #endif
00991 
00992 #ifdef  P_INCLUDE_XER
00993 #include "asnxer.h"
00994 #endif
00995 
00996 #endif // PTLIB_ASNER_H
00997 
00998 
00999 // End Of File ///////////////////////////////////////////////////////////////

Generated on Thu May 27 01:36:47 2010 for PTLib by  doxygen 1.4.7