# 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: 24177 $
    00027  * $Author: rjongbloed $
    00028  * $Date: 2010-04-05 06:52:04 -0500 (Mon, 05 Apr 2010) $
    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 true; }
    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 = true) { 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 = false);
    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 = false);
    00211     PASN_Boolean(unsigned tag, TagClass tagClass, PBoolean val = false);
    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 = false,
    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     void SetValueRaw(const PWCharArray & v) { SetValueRaw(v, v.GetSize()); }
    00602     void SetValueRaw(const wchar_t * val, PINDEX len);
    00603
    00604     void SetCharacterSet(ConstraintType ctype, const char * charSet);
    00605     void SetCharacterSet(ConstraintType ctype, const PWCharArray & charSet);
    00606     void SetCharacterSet(ConstraintType ctype, unsigned firstChar, unsigned lastChar);
    00607
    00608     virtual Comparison Compare(const PObject & obj) const;
    00609     virtual PObject * Clone() const;
    00610     virtual void PrintOn(ostream & strm) const;
    00611
    00612     virtual PString GetTypeAsString() const;
    00613     virtual PINDEX GetDataLength() const;
    00614     virtual PBoolean Decode(PASN_Stream &);
    00615     virtual void Encode(PASN_Stream &) const;
    00616
    00617 #ifdef P_INCLUDE_BER
    00618     PBoolean DecodeBER(PBER_Stream & strm, unsigned len);
    00619     void EncodeBER(PBER_Stream & strm) const;
    00620 #endif
    00621
    00622 #ifdef P_INCLUDE_PER
    00623     PBoolean DecodePER(PPER_Stream & strm);
    00624     void EncodePER(PPER_Stream & strm) const;
    00625 #endif
    00626
    00627   protected:
    00628     void Construct();
    00629     PBoolean IsLegalCharacter(WORD ch);
    00630
    00631     PWCharArray value;
    00632     PWCharArray characterSet;
    00633     wchar_t firstChar, lastChar;
    00634     unsigned charSetUnalignedBits;
    00635     unsigned charSetAlignedBits;
    00636 };
    00637
    00638
    00639 class PASN_GeneralisedTime : public PASN_VisibleString
    00640 {
    00641     PCLASSINFO(PASN_GeneralisedTime, PASN_VisibleString);
    00642   public:
    00643     PASN_GeneralisedTime()
    00644       : PASN_VisibleString(UniversalGeneralisedTime, UniversalTagClass) { }
    00645     PASN_GeneralisedTime(const PTime & time)
    00646       : PASN_VisibleString(UniversalGeneralisedTime, UniversalTagClass) { SetValue(time); }
    00647     PASN_GeneralisedTime(unsigned theTag, TagClass theTagClass)
    00648       : PASN_VisibleString(theTag, theTagClass) { }
    00649
    00650     PASN_GeneralisedTime & operator=(const PTime & time);
    00651     void SetValue(const PTime & time) { operator=(time); }
    00652     PTime GetValue() const;
    00653 };
    00654
    00655
    00656 class PASN_UniversalTime : public PASN_VisibleString
    00657 {
    00658     PCLASSINFO(PASN_UniversalTime, PASN_VisibleString);
    00659   public:
    00660     PASN_UniversalTime()
    00661       : PASN_VisibleString(UniversalUTCTime, UniversalTagClass) { }
    00662     PASN_UniversalTime(const PTime & time)
    00663       : PASN_VisibleString(UniversalUTCTime, UniversalTagClass) { SetValue(time); }
    00664     PASN_UniversalTime(unsigned theTag, TagClass theTagClass)
    00665       : PASN_VisibleString(theTag, theTagClass) { }
    00666
    00667     PASN_UniversalTime & operator=(const PTime & time);
    00668     void SetValue(const PTime & time) { operator=(time); }
    00669     PTime GetValue() const;
    00670 };
    00671
    00672
    00673 class PASN_Sequence;
    00674
    00677 class PASN_Choice : public PASN_Object
    00678 {
    00679     PCLASSINFO(PASN_Choice, PASN_Object);
    00680   public:
    00681     ~PASN_Choice();
    00682
    00683     virtual void SetTag(unsigned newTag, TagClass tagClass = DefaultTagClass);
    00684     PString GetTagName() const;
    00685     PASN_Object & GetObject() const;
    00686     PBoolean IsValid() const { return choice != NULL; }
    00687
    00688 #if defined(__GNUC__) && __GNUC__ <= 2 && __GNUC_MINOR__ < 9
    00689
    00690     operator PASN_Null &() const;
    00691     operator PASN_Boolean &() const;
    00692     operator PASN_Integer &() const;
    00693     operator PASN_Enumeration &() const;
    00694     operator PASN_Real &() const;
    00695     operator PASN_ObjectId &() const;
    00696     operator PASN_BitString &() const;
    00697     operator PASN_OctetString &() const;
    00698     operator PASN_NumericString &() const;
    00699     operator PASN_PrintableString &() const;
    00700     operator PASN_VisibleString &() const;
    00701     operator PASN_IA5String &() const;
    00702     operator PASN_GeneralString &() const;
    00703     operator PASN_BMPString &() const;
    00704     operator PASN_Sequence &() const;
    00705
    00706 #else
    00707
    00708     operator PASN_Null &();
    00709     operator PASN_Boolean &();
    00710     operator PASN_Integer &();
    00711     operator PASN_Enumeration &();
    00712     operator PASN_Real &();
    00713     operator PASN_ObjectId &();
    00714     operator PASN_BitString &();
    00715     operator PASN_OctetString &();
    00716     operator PASN_NumericString &();
    00717     operator PASN_PrintableString &();
    00718     operator PASN_VisibleString &();
    00719     operator PASN_IA5String &();
    00720     operator PASN_GeneralString &();
    00721     operator PASN_BMPString &();
    00722     operator PASN_Sequence &();
    00723
    00724     operator const PASN_Null &() const;
    00725     operator const PASN_Boolean &() const;
    00726     operator const PASN_Integer &() const;
    00727     operator const PASN_Enumeration &() const;
    00728     operator const PASN_Real &() const;
    00729     operator const PASN_ObjectId &() const;
    00730     operator const PASN_BitString &() const;
    00731     operator const PASN_OctetString &() const;
    00732     operator const PASN_NumericString &() const;
    00733     operator const PASN_PrintableString &() const;
    00734     operator const PASN_VisibleString &() const;
    00735     operator const PASN_IA5String &() const;
    00736     operator const PASN_GeneralString &() const;
    00737     operator const PASN_BMPString &() const;
    00738     operator const PASN_Sequence &() const;
    00739
    00740 #endif
    00741
    00742     virtual PBoolean CreateObject() = 0;
    00743
    00744     virtual Comparison Compare(const PObject & obj) const;
    00745     virtual void PrintOn(ostream & strm) const;
    00746
    00747     virtual PString GetTypeAsString() const;
    00748     virtual PINDEX GetDataLength() const;
    00749     virtual PBoolean IsPrimitive() const;
    00750     virtual PBoolean Decode(PASN_Stream &);
    00751     virtual void Encode(PASN_Stream &) const;
    00752
    00753 #ifdef P_INCLUDE_PER
    00754     virtual PBoolean DecodePER(PPER_Stream &);
    00755     virtual void EncodePER(PPER_Stream &) const;
    00756 #endif
    00757
    00758 #ifdef P_INCLUDE_XER
    00759     PBoolean DecodeXER(PXER_Stream &);
    00760     void EncodeXER(PXER_Stream &) const;
    00761 #endif
    00762
    00763     PASN_Choice & operator=(const PASN_Choice & other);
    00764
    00765     PINDEX GetValueByName(PString name) const;
    00766   protected:
    00767     PASN_Choice(unsigned nChoices = 0, PBoolean extend = false);
    00768     PASN_Choice(unsigned tag, TagClass tagClass, unsigned nChoices, PBoolean extend);
    00769     PASN_Choice(unsigned tag, TagClass tagClass, unsigned nChoices, PBoolean extend, const PASN_Names * nameSpec,unsigned namesCnt);
    00770
    00771     PASN_Choice(const PASN_Choice & other);
    00772
    00773     PBoolean CheckCreate() const;
    00774
    00775     unsigned numChoices;
    00776     PASN_Object * choice;
    00777     const PASN_Names *names;
    00778     unsigned namesCount;
    00779 };
    00780
    00781
    00782 PARRAY(PASN_ObjectArray, PASN_Object);
    00783
    00784
    00787 class PASN_Sequence : public PASN_Object
    00788 {
    00789     PCLASSINFO(PASN_Sequence, PASN_Object);
    00790   public:
    00791     PASN_Sequence(unsigned tag = UniversalSequence,
    00792                   TagClass tagClass = UniversalTagClass,
    00793                   unsigned nOpts = 0, PBoolean extend = false, unsigned nExtend = 0);
    00794
    00795     PASN_Sequence(const PASN_Sequence & other);
    00796     PASN_Sequence & operator=(const PASN_Sequence & other);
    00797
    00798     PINDEX GetSize() const { return fields.GetSize(); }
    00799     PBoolean SetSize(PINDEX newSize);
    00800     PASN_Object & operator[](PINDEX i) const { return fields[i]; }
    00801
    00802     PBoolean HasOptionalField(PINDEX opt) const;
    00803     void IncludeOptionalField(PINDEX opt);
    00804     void RemoveOptionalField(PINDEX opt);
    00805
    00806     virtual Comparison Compare(const PObject & obj) const;
    00807     virtual PObject * Clone() const;
    00808     virtual void PrintOn(ostream & strm) const;
    00809
    00810     virtual PString GetTypeAsString() const;
    00811     virtual PINDEX GetDataLength() const;
    00812     virtual PBoolean IsPrimitive() const;
    00813     virtual PBoolean Decode(PASN_Stream &);
    00814     virtual void Encode(PASN_Stream &) const;
    00815
    00816     PBoolean PreambleDecode(PASN_Stream & strm);
    00817     void PreambleEncode(PASN_Stream & strm) const;
    00818     PBoolean KnownExtensionDecode(PASN_Stream & strm, PINDEX fld, PASN_Object & field);
    00819     void KnownExtensionEncode(PASN_Stream & strm, PINDEX fld, const PASN_Object & field) const;
    00820     PBoolean UnknownExtensionsDecode(PASN_Stream & strm);
    00821     void UnknownExtensionsEncode(PASN_Stream & strm) const;
    00822
    00823 #ifdef P_INCLUDE_BER
    00824     PBoolean PreambleDecodeBER(PBER_Stream & strm);
    00825     void PreambleEncodeBER(PBER_Stream & strm) const;
    00826     PBoolean KnownExtensionDecodeBER(PBER_Stream & strm, PINDEX fld, PASN_Object & field);
    00827     void KnownExtensionEncodeBER(PBER_Stream & strm, PINDEX fld, const PASN_Object & field) const;
    00828     PBoolean UnknownExtensionsDecodeBER(PBER_Stream & strm);
    00829     void UnknownExtensionsEncodeBER(PBER_Stream & strm) const;
    00830 #endif
    00831
    00832 #ifdef P_INCLUDE_PER
    00833     PBoolean PreambleDecodePER(PPER_Stream & strm);
    00834     void PreambleEncodePER(PPER_Stream & strm) const;
    00835     PBoolean KnownExtensionDecodePER(PPER_Stream & strm, PINDEX fld, PASN_Object & field);
    00836     void KnownExtensionEncodePER(PPER_Stream & strm, PINDEX fld, const PASN_Object & field) const;
    00837     PBoolean UnknownExtensionsDecodePER(PPER_Stream & strm);
    00838     void UnknownExtensionsEncodePER(PPER_Stream & strm) const;
    00839 #endif
    00840
    00841 #ifdef P_INCLUDE_XER
    00842     virtual PBoolean PreambleDecodeXER(PXER_Stream & strm);
    00843     virtual void PreambleEncodeXER(PXER_Stream & strm) const;
    00844     virtual PBoolean KnownExtensionDecodeXER(PXER_Stream & strm, PINDEX fld, PASN_Object & field);
    00845     virtual void KnownExtensionEncodeXER(PXER_Stream & strm, PINDEX fld, const PASN_Object & field) const;
    00846     virtual PBoolean UnknownExtensionsDecodeXER(PXER_Stream & strm);
    00847     virtual void UnknownExtensionsEncodeXER(PXER_Stream & strm) const;
    00848 #endif
    00849
    00850   protected:
    00851     PBoolean NoExtensionsToDecode(PPER_Stream & strm);
    00852     PBoolean NoExtensionsToEncode(PPER_Stream & strm);
    00853
    00854     PASN_ObjectArray fields;
    00855     PASN_BitString optionMap;
    00856     int knownExtensions;
    00857     int totalExtensions;
    00858     PASN_BitString extensionMap;
    00859     PINDEX endBasicEncoding;
    00860 };
    00861
    00862
    00865 class PASN_Set : public PASN_Sequence
    00866 {
    00867     PCLASSINFO(PASN_Set, PASN_Sequence);
    00868   public:
    00869     PASN_Set(unsigned tag = UniversalSet,
    00870              TagClass tagClass = UniversalTagClass,
    00871              unsigned nOpts = 0, PBoolean extend = false, unsigned nExtend = 0);
    00872
    00873     virtual PObject * Clone() const;
    00874     virtual PString GetTypeAsString() const;
    00875 };
    00876
    00877
    00880 class PASN_Array : public PASN_ConstrainedObject
    00881 {
    00882     PCLASSINFO(PASN_Array, PASN_ConstrainedObject);
    00883   public:
    00884     PINDEX GetSize() const { return array.GetSize(); }
    00885     PBoolean SetSize(PINDEX newSize);
    00886     PASN_Object & operator[](PINDEX i) const { return array[i]; }
    00887     void Append(PASN_Object * obj) { array.SetAt(array.GetSize(), obj); }
    00888     void RemoveAt(PINDEX i) { array.RemoveAt(i); }
    00889     void RemoveAll() { array.RemoveAll(); }
    00890
    00891     virtual Comparison Compare(const PObject & obj) const;
    00892     virtual void PrintOn(ostream & strm) const;
    00893
    00894     virtual void SetConstraintBounds(ConstraintType type, int lower, unsigned upper);
    00895     virtual PString GetTypeAsString() const;
    00896     virtual PINDEX GetDataLength() const;
    00897     virtual PBoolean IsPrimitive() const;
    00898     virtual PBoolean Decode(PASN_Stream &);
    00899     virtual void Encode(PASN_Stream &) const;
    00900
    00901     virtual PASN_Object * CreateObject() const = 0;
    00902
    00903     PASN_Array & operator=(const PASN_Array & other);
    00904
    00905   protected:
    00906     PASN_Array(unsigned tag = UniversalSequence,
    00907                TagClass tagClass = UniversalTagClass);
    00908
    00909     PASN_Array(const PASN_Array & other);
    00910
    00911     PASN_ObjectArray array;
    00912 };
    00913
    00914
    00916
    00919 class PASN_Stream : public PBYTEArray
    00920 {
    00921     PCLASSINFO(PASN_Stream, PBYTEArray);
    00922   public:
    00923     PASN_Stream();
    00924     PASN_Stream(const PBYTEArray & bytes);
    00925     PASN_Stream(const BYTE * buf, PINDEX size);
    00926
    00927     void PrintOn(ostream & strm) const;
    00928
    00929     PINDEX GetPosition() const { return byteOffset; }
    00930     void SetPosition(PINDEX newPos);
    00931     PBoolean IsAtEnd() { return byteOffset >= GetSize(); }
    00932     void ResetDecoder();
    00933     void BeginEncoding();
    00934     void CompleteEncoding();
    00935
    00936     virtual PBoolean Read(PChannel & chan) = 0;
    00937     virtual PBoolean Write(PChannel & chan) = 0;
    00938
    00939     virtual PBoolean NullDecode(PASN_Null &) = 0;
    00940     virtual void NullEncode(const PASN_Null &) = 0;
    00941     virtual PBoolean BooleanDecode(PASN_Boolean &) = 0;
    00942     virtual void BooleanEncode(const PASN_Boolean &) = 0;
    00943     virtual PBoolean IntegerDecode(PASN_Integer &) = 0;
    00944     virtual void IntegerEncode(const PASN_Integer &) = 0;
    00945     virtual PBoolean EnumerationDecode(PASN_Enumeration &) = 0;
    00946     virtual void EnumerationEncode(const PASN_Enumeration &) = 0;
    00947     virtual PBoolean RealDecode(PASN_Real &) = 0;
    00948     virtual void RealEncode(const PASN_Real &) = 0;
    00949     virtual PBoolean ObjectIdDecode(PASN_ObjectId &) = 0;
    00950     virtual void ObjectIdEncode(const PASN_ObjectId &) = 0;
    00951     virtual PBoolean BitStringDecode(PASN_BitString &) = 0;
    00952     virtual void BitStringEncode(const PASN_BitString &) = 0;
    00953     virtual PBoolean OctetStringDecode(PASN_OctetString &) = 0;
    00954     virtual void OctetStringEncode(const PASN_OctetString &) = 0;
    00955     virtual PBoolean ConstrainedStringDecode(PASN_ConstrainedString &) = 0;
    00956     virtual void ConstrainedStringEncode(const PASN_ConstrainedString &) = 0;
    00957     virtual PBoolean BMPStringDecode(PASN_BMPString &) = 0;
    00958     virtual void BMPStringEncode(const PASN_BMPString &) = 0;
    00959     virtual PBoolean ChoiceDecode(PASN_Choice &) = 0;
    00960     virtual void ChoiceEncode(const PASN_Choice &) = 0;
    00961     virtual PBoolean ArrayDecode(PASN_Array &) = 0;
    00962     virtual void ArrayEncode(const PASN_Array &) = 0;
    00963     virtual PBoolean SequencePreambleDecode(PASN_Sequence &) = 0;
    00964     virtual void SequencePreambleEncode(const PASN_Sequence &) = 0;
    00965     virtual PBoolean SequenceKnownDecode(PASN_Sequence &, PINDEX, PASN_Object &) = 0;
    00966     virtual void SequenceKnownEncode(const PASN_Sequence &, PINDEX, const PASN_Object &) = 0;
    00967     virtual PBoolean SequenceUnknownDecode(PASN_Sequence &) = 0;
    00968     virtual void SequenceUnknownEncode(const PASN_Sequence &) = 0;
    00969
    00970     BYTE ByteDecode();
    00971     void ByteEncode(unsigned value);
    00972
    00973     unsigned BlockDecode(BYTE * bufptr, unsigned nBytes);
    00974     void BlockEncode(const BYTE * bufptr, PINDEX nBytes);
    00975
    00976     void ByteAlign();
    00977
    00978   protected:
    00979     PINDEX byteOffset;
    00980     unsigned bitOffset;
    00981
    00982   private:
    00983     void Construct();
    00984 };
    00985
    00986 #ifdef  P_INCLUDE_PER
    00987 #include "asnper.h"
    00988 #endif
    00989
    00990 #ifdef  P_INCLUDE_BER
    00991 #include "asnber.h"
    00992 #endif
    00993
    00994 #ifdef  P_INCLUDE_XER
    00995 #include "asnxer.h"
    00996 #endif
    00997
    00998 #endif // PTLIB_ASNER_H
    00999
    01000
    01001 // End Of File ///////////////////////////////////////////////////////////////