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

Generated on Mon Sep 15 01:21:34 2008 for PTLib by  doxygen 1.5.1