Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

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 * $Log: asner.h,v $ 00027 * Revision 1.43 2004/04/18 04:33:35 rjongbloed 00028 * Changed all operators that return BOOL to return standard type bool. This is primarily 00029 * for improved compatibility with std STL usage removing many warnings. 00030 * 00031 * Revision 1.42 2003/12/14 10:21:29 rjongbloed 00032 * Fixed bug in length incorrectlty decoded from ASN and (apparently) rare circumstances. Thanks pangxg@hotmail.com. 00033 * Cleaned up return values to be BOOL rather than int for some functions. 00034 * 00035 * Revision 1.41 2003/08/18 23:32:22 rjongbloed 00036 * Micro optimisation suggested by Chih-Wei Huang 00037 * 00038 * Revision 1.40 2003/08/01 16:00:51 csoutheren 00039 * Changed #if to #ifdef to (maybe) avoid compiler problems with gcc 2.95.2 00040 * 00041 * Revision 1.39 2003/08/01 02:12:34 csoutheren 00042 * Changed to allow easy isolation of PER, BER and XER encoding/decoding routines 00043 * 00044 * Revision 1.38 2003/04/22 23:39:09 craigs 00045 * Changed some functions from protected to public for MacOSX. Thanks to Hugo Santos 00046 * 00047 * Revision 1.37 2003/04/17 14:44:44 craigs 00048 * Removed MacOS specific defines to make some attributes public 00049 * Thanks to Hugo Santos and apologies to Roger Hardiman 00050 * 00051 * Revision 1.36 2003/02/26 01:57:44 robertj 00052 * Added XML encoding rules to ASN system, thanks Federico Pinna 00053 * 00054 * Revision 1.35 2003/02/01 13:25:52 robertj 00055 * Added function to add new elements directly to ASN array. 00056 * 00057 * Revision 1.34 2003/01/24 23:43:43 robertj 00058 * Fixed subtle problems with the use of MAX keyword for unsigned numbers, 00059 * should beUINT_MAX not INT_MAX, thanks Stevie Gray for pointing it out. 00060 * 00061 * Revision 1.33 2002/11/26 23:29:18 robertj 00062 * Added missing const to DecodeSubType() function. 00063 * 00064 * Revision 1.32 2002/11/06 22:47:23 robertj 00065 * Fixed header comment (copyright etc) 00066 * 00067 * Revision 1.31 2002/10/31 05:50:49 robertj 00068 * Changed to use new UTF-8/UCS-2 conversion functions on PString. 00069 * 00070 * Revision 1.30 2002/10/10 14:37:40 rogerh 00071 * In two of the PASN classes make the protected members public. This 00072 * makes OpenH323 compile in Mac OS X 10.2.1 00073 * 00074 * Revision 1.29 2002/09/16 01:08:59 robertj 00075 * Added #define so can select if #pragma interface/implementation is used on 00076 * platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan. 00077 * 00078 * Revision 1.28 2002/05/29 01:22:35 robertj 00079 * Added ability to set object id from unsigned integer arrays. 00080 * 00081 * Revision 1.27 2002/05/21 04:23:40 robertj 00082 * Fixed problem with ASN encoding/decoding unsconstrained negative numbers, 00083 * 00084 * Revision 1.26 2002/05/14 06:59:31 robertj 00085 * Added more bullet proofing so a malformed PDU cannot cause teh decoder 00086 * to try and allocate huge arrays and consume all CPU and memory on a 00087 * system. A configurable limit of 100 is set for things like SEQUENCE OF. 00088 * 00089 * Revision 1.25 2001/12/13 09:13:28 robertj 00090 * Added function get get oid as a string. 00091 * Added functions to compare oid to PString. 00092 * 00093 * Revision 1.24 2001/09/14 01:59:59 robertj 00094 * Fixed problem with incorrectly initialised PASN_Choice sub-object. 00095 * 00096 * Revision 1.23 2001/08/06 01:39:02 robertj 00097 * Added assignement operator with RHS of PASN_BMPString to classes 00098 * descended from PASN_BMPString. 00099 * 00100 * Revision 1.22 2001/06/14 02:14:12 robertj 00101 * Added functions to encode and decode another ASN type that is inside 00102 * an octet string, useful for ANY or EXTERNAL types etc. 00103 * 00104 * Revision 1.21 2001/04/30 06:47:04 robertj 00105 * Fixed problem with en/decoding more than 16 extension fields in a sequence. 00106 * 00107 * Revision 1.20 2001/04/26 08:15:58 robertj 00108 * Fixed problem with ASN compile of single constraints on enumerations. 00109 * 00110 * Revision 1.19 2001/04/23 04:40:14 robertj 00111 * Added ASN standard types GeneralizedTime and UTCTime 00112 * 00113 * Revision 1.18 2001/04/12 03:25:22 robertj 00114 * Fixed PASN_Boolean cosntructor to be compatible with usage in ASN parser. 00115 * Changed all PASN_xxx types so constructor can take real type as only 00116 * parameter. eg PASN_OctetString s = "fred"; 00117 * 00118 * Revision 1.17 2001/03/21 03:32:35 robertj 00119 * Aded ability to get at the data bits buffer in a PASN_BitString 00120 * 00121 * Revision 1.16 2001/01/24 04:36:56 robertj 00122 * Added more bulletproofing to ASN structures to obey constraints. 00123 * 00124 * Revision 1.15 2000/10/26 11:09:07 robertj 00125 * More bullet proofing of PER decoder, changed bit type to be unsigned. 00126 * 00127 * Revision 1.14 2000/10/25 04:05:44 robertj 00128 * More bullet proofing of PER decoder. 00129 * 00130 * Revision 1.13 2000/07/11 18:23:03 robertj 00131 * Added ability to set/get BMP string data as PWORDArray. 00132 * 00133 * Revision 1.12 2000/04/10 17:30:42 robertj 00134 * Added [] operator for char access on ASN string classes. 00135 * 00136 * Revision 1.11 2000/02/29 06:32:12 robertj 00137 * Added ability to remove optional field in sequence, thanks Dave Harvey. 00138 * 00139 * Revision 1.10 1999/08/09 13:02:45 robertj 00140 * dded ASN compiler #defines for backward support of pre GCC 2.9 compilers. 00141 * Added ASN compiler #defines to reduce its memory footprint. 00142 * 00143 * Revision 1.9 1999/07/22 06:48:51 robertj 00144 * Added comparison operation to base ASN classes and compiled ASN code. 00145 * Added support for ANY type in ASN parser. 00146 * 00147 * Revision 1.8 1999/03/09 09:34:05 robertj 00148 * Fixed typo's. 00149 * 00150 * Revision 1.7 1999/03/09 08:01:46 robertj 00151 * Changed comments for doc++ support (more to come). 00152 * 00153 * Revision 1.6 1998/09/23 06:19:21 robertj 00154 * Added open source copyright license. 00155 * 00156 * Revision 1.5 1998/05/21 04:26:53 robertj 00157 * Fixed numerous PER problems. 00158 * 00159 * Revision 1.4 1998/05/07 05:19:28 robertj 00160 * Fixed problems with using copy constructor/assignment oeprator on PASN_Objects. 00161 * 00162 * Revision 1.3 1997/12/18 05:08:13 robertj 00163 * Added function to get choice discriminat`or name. 00164 * 00165 * Revision 1.2 1997/12/11 10:35:42 robertj 00166 * Support for new ASN file parser. 00167 * 00168 */ 00169 00170 #ifndef _ASNER_H 00171 #define _ASNER_H 00172 00173 #ifdef P_USE_PRAGMA 00174 #pragma interface 00175 #endif 00176 00177 // provide options to omit vertain encodings, if needed 00178 #define P_INCLUDE_PER 00179 #define P_INCLUDE_BER 00180 #define P_INCLUDE_XER 00181 00182 class PASN_Stream; 00183 class PBER_Stream; 00184 class PPER_Stream; 00185 00186 #if P_EXPAT 00187 class PXER_Stream; 00188 class PXMLElement; 00189 #else 00190 #undef P_INCLUDE_XER 00191 #endif 00192 00193 00195 00198 class PASN_Object : public PObject 00199 { 00200 PCLASSINFO(PASN_Object, PObject); 00201 public: 00203 virtual PString GetTypeAsString() const = 0; 00204 00205 PINDEX GetObjectLength() const; 00206 virtual PINDEX GetDataLength() const = 0; 00207 virtual BOOL IsPrimitive() const { return TRUE; } 00208 00209 virtual BOOL Decode(PASN_Stream &) = 0; 00210 virtual void Encode(PASN_Stream &) const = 0; 00211 00212 BOOL IsExtendable() const { return extendable; } 00213 void SetExtendable(BOOL ext = TRUE) { extendable = ext; } 00214 00215 enum TagClass { 00216 UniversalTagClass, 00217 ApplicationTagClass, 00218 ContextSpecificTagClass, 00219 PrivateTagClass, 00220 DefaultTagClass 00221 }; 00222 TagClass GetTagClass() const { return tagClass; } 00223 00224 enum UniversalTags { 00225 InvalidUniversalTag, 00226 UniversalBoolean, 00227 UniversalInteger, 00228 UniversalBitString, 00229 UniversalOctetString, 00230 UniversalNull, 00231 UniversalObjectId, 00232 UniversalObjectDescriptor, 00233 UniversalExternalType, 00234 UniversalReal, 00235 UniversalEnumeration, 00236 UniversalEmbeddedPDV, 00237 UniversalSequence = 16, 00238 UniversalSet, 00239 UniversalNumericString, 00240 UniversalPrintableString, 00241 UniversalTeletexString, 00242 UniversalVideotexString, 00243 UniversalIA5String, 00244 UniversalUTCTime, 00245 UniversalGeneralisedTime, 00246 UniversalGeneralizedTime = UniversalGeneralisedTime, 00247 UniversalGraphicString, 00248 UniversalVisibleString, 00249 UniversalGeneralString, 00250 UniversalUniversalString, 00251 UniversalBMPString = 30 00252 }; 00253 00254 unsigned GetTag() const { return tag; } 00255 virtual void SetTag(unsigned newTag, TagClass tagClass = DefaultTagClass); 00256 00257 enum ConstraintType { 00258 Unconstrained, 00259 PartiallyConstrained, 00260 FixedConstraint, 00261 ExtendableConstraint 00262 }; 00263 00264 enum MinimumValueTag { MinimumValue = INT_MIN }; 00265 enum MaximumValueTag { MaximumValue = INT_MAX }; 00266 void SetConstraints(ConstraintType type, int value) 00267 { SetConstraintBounds(type, value, value); } 00268 void SetConstraints(ConstraintType, int lower, MaximumValueTag /*upper*/) 00269 { SetConstraintBounds(PartiallyConstrained, (int)lower, lower < 0 ? INT_MAX : UINT_MAX); } 00270 void SetConstraints(ConstraintType, MinimumValueTag lower, unsigned upper) 00271 { SetConstraintBounds(PartiallyConstrained, (int)lower, (unsigned)upper); } 00272 void SetConstraints(ConstraintType, MinimumValueTag lower, MaximumValueTag upper) 00273 { SetConstraintBounds(PartiallyConstrained, (int)lower, (unsigned)upper); } 00274 void SetConstraints(ConstraintType type, int lower, unsigned upper) 00275 { SetConstraintBounds(type, lower, upper); } 00276 00277 virtual void SetConstraintBounds(ConstraintType type, int lower, unsigned upper); 00278 virtual void SetCharacterSet(ConstraintType ctype, const char * charSet); 00279 virtual void SetCharacterSet(ConstraintType ctype, unsigned firstChar, unsigned lastChar); 00280 00281 static PINDEX GetMaximumArraySize(); 00282 static void SetMaximumArraySize(PINDEX sz); 00283 static PINDEX GetMaximumStringSize(); 00284 static void SetMaximumStringSize(PINDEX sz); 00285 00286 protected: 00287 PASN_Object(unsigned tag, TagClass tagClass, BOOL extend = FALSE); 00288 00290 BOOL extendable; 00292 TagClass tagClass; 00294 unsigned tag; 00295 }; 00296 00297 00300 class PASN_ConstrainedObject : public PASN_Object 00301 { 00302 PCLASSINFO(PASN_ConstrainedObject, PASN_Object); 00303 public: 00304 BOOL IsConstrained() const { return constraint != Unconstrained; } 00305 int GetLowerLimit() const { return lowerLimit; } 00306 unsigned GetUpperLimit() const { return upperLimit; } 00307 00308 BOOL ConstrainedLengthDecode(PPER_Stream & strm, unsigned & length); 00309 void ConstrainedLengthEncode(PPER_Stream & strm, unsigned length) const; 00310 00311 BOOL ConstraintEncode(PPER_Stream & strm, unsigned value) const; 00312 00313 protected: 00314 virtual void SetConstraintBounds(ConstraintType type, int lower, unsigned upper); 00315 PASN_ConstrainedObject(unsigned tag, TagClass tagClass); 00316 00317 ConstraintType constraint; 00318 int lowerLimit; 00319 unsigned upperLimit; 00320 }; 00321 00322 00325 class PASN_Null : public PASN_Object 00326 { 00327 PCLASSINFO(PASN_Null, PASN_Object); 00328 public: 00329 PASN_Null(unsigned tag = UniversalNull, 00330 TagClass tagClass = UniversalTagClass); 00331 00332 virtual Comparison Compare(const PObject & obj) const; 00333 virtual PObject * Clone() const; 00334 virtual void PrintOn(ostream & strm) const; 00335 00336 virtual PString GetTypeAsString() const; 00337 virtual PINDEX GetDataLength() const; 00338 virtual BOOL Decode(PASN_Stream &); 00339 virtual void Encode(PASN_Stream &) const; 00340 }; 00341 00342 00345 class PASN_Boolean : public PASN_Object 00346 { 00347 PCLASSINFO(PASN_Boolean, PASN_Object); 00348 public: 00349 PASN_Boolean(BOOL val = FALSE); 00350 PASN_Boolean(unsigned tag, TagClass tagClass, BOOL val = FALSE); 00351 00352 PASN_Boolean & operator=(BOOL v) { value = v; return *this; } 00353 operator BOOL() const { return value; } 00354 BOOL GetValue() const { return value; } 00355 void SetValue(BOOL v) { value = v; } 00356 00357 virtual Comparison Compare(const PObject & obj) const; 00358 virtual PObject * Clone() const; 00359 virtual void PrintOn(ostream & strm) const; 00360 00361 virtual PString GetTypeAsString() const; 00362 virtual PINDEX GetDataLength() const; 00363 virtual BOOL Decode(PASN_Stream &); 00364 virtual void Encode(PASN_Stream &) const; 00365 00366 protected: 00367 BOOL value; 00368 }; 00369 00370 00373 class PASN_Integer : public PASN_ConstrainedObject 00374 { 00375 PCLASSINFO(PASN_Integer, PASN_ConstrainedObject); 00376 public: 00377 PASN_Integer(unsigned val = 0); 00378 PASN_Integer(unsigned tag, TagClass tagClass, unsigned val = 0); 00379 00380 PASN_Integer & operator=(unsigned value); 00381 operator unsigned() const { return value; } 00382 unsigned GetValue() const { return value; } 00383 void SetValue(unsigned v) { operator=(v); } 00384 00385 virtual Comparison Compare(const PObject & obj) const; 00386 virtual PObject * Clone() const; 00387 virtual void PrintOn(ostream & strm) const; 00388 00389 virtual void SetConstraintBounds(ConstraintType type, int lower, unsigned upper); 00390 virtual PString GetTypeAsString() const; 00391 virtual PINDEX GetDataLength() const; 00392 virtual BOOL Decode(PASN_Stream &); 00393 virtual void Encode(PASN_Stream &) const; 00394 00395 #ifdef P_INCLUDE_PER 00396 BOOL DecodePER(PPER_Stream & strm); 00397 void EncodePER(PPER_Stream & strm) const; 00398 #endif 00399 00400 BOOL IsUnsigned() const; 00401 00402 protected: 00403 unsigned value; 00404 }; 00405 00406 00409 class PASN_Enumeration : public PASN_Object 00410 { 00411 PCLASSINFO(PASN_Enumeration, PASN_Object); 00412 public: 00413 PASN_Enumeration(unsigned val = 0); 00414 PASN_Enumeration(unsigned tag, 00415 TagClass tagClass, 00416 unsigned nEnums = P_MAX_INDEX, 00417 BOOL extendable = FALSE, 00418 unsigned val = 0); 00419 PASN_Enumeration(unsigned tag, 00420 TagClass tagClass, 00421 unsigned nEnums, 00422 BOOL extendable, 00423 const PString & nameSpec, 00424 unsigned val = 0); 00425 00426 PASN_Enumeration & operator=(unsigned v) { value = v; return *this; } 00427 operator unsigned() const { return value; } 00428 unsigned GetValue() const { return value; } 00429 void SetValue(unsigned v) { value = v; } 00430 00431 unsigned GetMaximum() const { return maxEnumValue; } 00432 00433 virtual Comparison Compare(const PObject & obj) const; 00434 virtual PObject * Clone() const; 00435 virtual void PrintOn(ostream & strm) const; 00436 00437 virtual PString GetTypeAsString() const; 00438 virtual PINDEX GetDataLength() const; 00439 virtual BOOL Decode(PASN_Stream &); 00440 virtual void Encode(PASN_Stream &) const; 00441 00442 #ifdef P_INCLUDE_PER 00443 BOOL DecodePER(PPER_Stream & strm); 00444 void EncodePER(PPER_Stream & strm) const; 00445 #endif 00446 00447 #ifdef P_INCLUDE_XER 00448 virtual BOOL DecodeXER(PXER_Stream & strm); 00449 virtual void EncodeXER(PXER_Stream & strm) const; 00450 #endif 00451 00452 protected: 00453 unsigned maxEnumValue; 00454 unsigned value; 00455 POrdinalToString names; 00456 }; 00457 00458 00461 class PASN_Real : public PASN_Object 00462 { 00463 PCLASSINFO(PASN_Real, PASN_Object); 00464 public: 00465 PASN_Real(double val = 0); 00466 PASN_Real(unsigned tag, TagClass tagClass, double val = 0); 00467 00468 PASN_Real & operator=(double val) { value = val; return *this; } 00469 operator double() const { return value; } 00470 double GetValue() const { return value; } 00471 void SetValue(double v) { value = v; } 00472 00473 virtual Comparison Compare(const PObject & obj) const; 00474 virtual PObject * Clone() const; 00475 virtual void PrintOn(ostream & strm) const; 00476 00477 virtual PString GetTypeAsString() const; 00478 virtual PINDEX GetDataLength() const; 00479 virtual BOOL Decode(PASN_Stream &); 00480 virtual void Encode(PASN_Stream &) const; 00481 00482 protected: 00483 double value; 00484 }; 00485 00486 00489 class PASN_ObjectId : public PASN_Object 00490 { 00491 PCLASSINFO(PASN_ObjectId, PASN_Object); 00492 public: 00493 PASN_ObjectId(const char * dotstr = NULL); 00494 PASN_ObjectId(unsigned tag, TagClass tagClass); 00495 00496 PASN_ObjectId(const PASN_ObjectId & other); 00497 PASN_ObjectId & operator=(const PASN_ObjectId & other); 00498 00499 PASN_ObjectId & operator=(const char * dotstr); 00500 PASN_ObjectId & operator=(const PString & dotstr); 00501 PASN_ObjectId & operator=(const PUnsignedArray & numbers); 00502 void SetValue(const PString & dotstr); 00503 void SetValue(const PUnsignedArray & numbers) { value = numbers; } 00504 void SetValue(const unsigned * numbers, PINDEX size); 00505 00506 bool operator==(const char * dotstr) const; 00507 bool operator!=(const char * dotstr) const { return !operator==(dotstr); } 00508 bool operator==(const PString & dotstr) const { return operator==((const char *)dotstr); } 00509 bool operator!=(const PString & dotstr) const { return !operator==((const char *)dotstr); } 00510 bool operator==(const PASN_ObjectId & id) const { return value == id.value; } 00511 00512 PINDEX GetSize() const { return value.GetSize(); } 00513 unsigned operator[](PINDEX idx) const { return value[idx]; } 00514 const PUnsignedArray & GetValue() const { return value; } 00515 PString AsString() const; 00516 00517 virtual Comparison Compare(const PObject & obj) const; 00518 virtual PObject * Clone() const; 00519 virtual void PrintOn(ostream & strm) const; 00520 00521 virtual PString GetTypeAsString() const; 00522 virtual PINDEX GetDataLength() const; 00523 virtual BOOL Decode(PASN_Stream &); 00524 virtual void Encode(PASN_Stream &) const; 00525 00526 BOOL CommonDecode(PASN_Stream & strm, unsigned dataLen); 00527 void CommonEncode(PBYTEArray & eObjId) const; 00528 00529 protected: 00530 PUnsignedArray value; 00531 }; 00532 00533 00536 class PASN_BitString : public PASN_ConstrainedObject 00537 { 00538 PCLASSINFO(PASN_BitString, PASN_ConstrainedObject); 00539 public: 00540 PASN_BitString(unsigned nBits = 0, const BYTE * buf = NULL); 00541 PASN_BitString(unsigned tag, TagClass tagClass, unsigned nBits = 0); 00542 00543 PASN_BitString(const PASN_BitString & other); 00544 PASN_BitString & operator=(const PASN_BitString & other); 00545 00546 void SetData(unsigned nBits, const PBYTEArray & bytes); 00547 void SetData(unsigned nBits, const BYTE * buf, PINDEX size = 0); 00548 00549 const BYTE * GetDataPointer() const { return bitData; } 00550 00551 unsigned GetSize() const { return totalBits; } 00552 BOOL SetSize(unsigned nBits); 00553 00554 bool operator[](PINDEX bit) const; 00555 void Set(unsigned bit); 00556 void Clear(unsigned bit); 00557 void Invert(unsigned bit); 00558 00559 virtual Comparison Compare(const PObject & obj) const; 00560 virtual PObject * Clone() const; 00561 virtual void PrintOn(ostream & strm) const; 00562 00563 virtual void SetConstraintBounds(ConstraintType type, int lower, unsigned upper); 00564 virtual PString GetTypeAsString() const; 00565 virtual PINDEX GetDataLength() const; 00566 virtual BOOL Decode(PASN_Stream &); 00567 virtual void Encode(PASN_Stream &) const; 00568 00569 #ifdef P_INCLUDE_BER 00570 BOOL DecodeBER(PBER_Stream & strm, unsigned len); 00571 void EncodeBER(PBER_Stream & strm) const; 00572 #endif 00573 00574 #ifdef P_INCLUDE_PER 00575 BOOL DecodePER(PPER_Stream & strm); 00576 void EncodePER(PPER_Stream & strm) const; 00577 #endif 00578 00579 BOOL DecodeSequenceExtensionBitmap(PPER_Stream & strm); 00580 void EncodeSequenceExtensionBitmap(PPER_Stream & strm) const; 00581 00582 protected: 00583 unsigned totalBits; 00584 PBYTEArray bitData; 00585 }; 00586 00587 00590 class PASN_OctetString : public PASN_ConstrainedObject 00591 { 00592 PCLASSINFO(PASN_OctetString, PASN_ConstrainedObject); 00593 public: 00594 PASN_OctetString(const char * str = NULL, PINDEX size = 0); 00595 PASN_OctetString(unsigned tag, TagClass tagClass); 00596 00597 PASN_OctetString(const PASN_OctetString & other); 00598 PASN_OctetString & operator=(const PASN_OctetString & other); 00599 00600 PASN_OctetString & operator=(const char * str); 00601 PASN_OctetString & operator=(const PString & str); 00602 PASN_OctetString & operator=(const PBYTEArray & arr); 00603 void SetValue(const char * str) { operator=(str); } 00604 void SetValue(const PString & str) { operator=(str); } 00605 void SetValue(const PBYTEArray & arr) { operator=(arr); } 00606 void SetValue(const BYTE * data, PINDEX len); 00607 const PBYTEArray & GetValue() const { return value; } 00608 operator const PBYTEArray &() const { return value; } 00609 operator const BYTE *() const { return value; } 00610 PString AsString() const; 00611 BYTE operator[](PINDEX i) const { return value[i]; } 00612 BYTE & operator[](PINDEX i) { return value[i]; } 00613 BYTE * GetPointer(PINDEX sz = 0) { return value.GetPointer(sz); } 00614 PINDEX GetSize() const { return value.GetSize(); } 00615 BOOL SetSize(PINDEX newSize); 00616 00617 virtual Comparison Compare(const PObject & obj) const; 00618 virtual PObject * Clone() const; 00619 virtual void PrintOn(ostream & strm) const; 00620 00621 virtual void SetConstraintBounds(ConstraintType type, int lower, unsigned upper); 00622 virtual PString GetTypeAsString() const; 00623 virtual PINDEX GetDataLength() const; 00624 virtual BOOL Decode(PASN_Stream &); 00625 virtual void Encode(PASN_Stream &) const; 00626 00627 #ifdef P_INCLUDE_PER 00628 BOOL DecodePER(PPER_Stream & strm); 00629 void EncodePER(PPER_Stream & strm) const; 00630 #endif 00631 00632 BOOL DecodeSubType(PASN_Object &) const; 00633 void EncodeSubType(const PASN_Object &); 00634 00635 protected: 00636 PBYTEArray value; 00637 }; 00638 00639 00642 class PASN_ConstrainedString : public PASN_ConstrainedObject 00643 { 00644 PCLASSINFO(PASN_ConstrainedString, PASN_ConstrainedObject); 00645 public: 00646 PASN_ConstrainedString & operator=(const char * str); 00647 PASN_ConstrainedString & operator=(const PString & str) { return operator=((const char *)str); } 00648 operator const PString &() const { return value; } 00649 const PString & GetValue() const { return value; } 00650 void SetValue(const char * v) { operator=(v); } 00651 void SetValue(const PString & v) { operator=(v); } 00652 char operator[](PINDEX idx) const { return value[idx]; } 00653 00654 void SetCharacterSet(ConstraintType ctype, const char * charSet); 00655 void SetCharacterSet(ConstraintType ctype, unsigned firstChar = 0, unsigned lastChar = 255); 00656 void SetCharacterSet(const char * charSet, PINDEX size, ConstraintType ctype); 00657 00658 virtual Comparison Compare(const PObject & obj) const; 00659 virtual void PrintOn(ostream & strm) const; 00660 00661 virtual void SetConstraintBounds(ConstraintType type, int lower, unsigned upper); 00662 virtual PINDEX GetDataLength() const; 00663 virtual BOOL Decode(PASN_Stream &); 00664 virtual void Encode(PASN_Stream &) const; 00665 00666 #ifdef P_INCLUDE_BER 00667 BOOL DecodeBER(PBER_Stream & strm, unsigned len); 00668 void EncodeBER(PBER_Stream & strm) const; 00669 #endif 00670 00671 #ifdef P_INCLUDE_PER 00672 BOOL DecodePER(PPER_Stream & strm); 00673 void EncodePER(PPER_Stream & strm) const; 00674 #endif 00675 00676 protected: 00677 PASN_ConstrainedString(const char * canonicalSet, PINDEX setSize, 00678 unsigned tag, TagClass tagClass); 00679 00680 PString value; 00681 PCharArray characterSet; 00682 const char * canonicalSet; 00683 PINDEX canonicalSetSize; 00684 unsigned canonicalSetBits; 00685 unsigned charSetUnalignedBits; 00686 unsigned charSetAlignedBits; 00687 }; 00688 00689 00690 #define DECLARE_STRING_CLASS(name) \ 00691 class PASN_##name##String : public PASN_ConstrainedString { \ 00692 PCLASSINFO(PASN_##name##String, PASN_ConstrainedString); \ 00693 public: \ 00694 PASN_##name##String(const char * str = NULL); \ 00695 PASN_##name##String(unsigned tag, TagClass tagClass); \ 00696 PASN_##name##String & operator=(const char * str); \ 00697 PASN_##name##String & operator=(const PString & str); \ 00698 virtual PObject * Clone() const; \ 00699 virtual PString GetTypeAsString() const; \ 00700 } 00701 00702 DECLARE_STRING_CLASS(Numeric); 00703 DECLARE_STRING_CLASS(Printable); 00704 DECLARE_STRING_CLASS(Visible); 00705 DECLARE_STRING_CLASS(IA5); 00706 DECLARE_STRING_CLASS(General); 00707 00708 00711 class PASN_BMPString : public PASN_ConstrainedObject 00712 { 00713 PCLASSINFO(PASN_BMPString, PASN_ConstrainedObject); 00714 public: 00715 PASN_BMPString(const char * str = NULL); 00716 PASN_BMPString(const PWORDArray & wstr); 00717 PASN_BMPString(unsigned tag, TagClass tagClass); 00718 00719 PASN_BMPString(const PASN_BMPString & other); 00720 PASN_BMPString & operator=(const PASN_BMPString & other); 00721 00722 PASN_BMPString & operator=(const char * v) { return operator=(PString(v).AsUCS2()); } 00723 PASN_BMPString & operator=(const PString & v) { return operator=(v.AsUCS2()); } 00724 PASN_BMPString & operator=(const PWORDArray & v); 00725 operator PString() const { return GetValue(); } 00726 operator PWORDArray() const { return value; } 00727 PString GetValue() const { return value; } 00728 void GetValue(PWORDArray & v) const { v = value; } 00729 void SetValue(const char * v) { operator=(PString(v).AsUCS2()); } 00730 void SetValue(const PString & v) { operator=(v.AsUCS2()); } 00731 void SetValue(const PWORDArray & v) { operator=(v); } 00732 void SetValue(const PASN_BMPString & v) { operator=(v.value); } 00733 00734 void SetCharacterSet(ConstraintType ctype, const char * charSet); 00735 void SetCharacterSet(ConstraintType ctype, const PWORDArray & charSet); 00736 void SetCharacterSet(ConstraintType ctype, unsigned firstChar, unsigned lastChar); 00737 00738 virtual Comparison Compare(const PObject & obj) const; 00739 virtual PObject * Clone() const; 00740 virtual void PrintOn(ostream & strm) const; 00741 00742 virtual PString GetTypeAsString() const; 00743 virtual PINDEX GetDataLength() const; 00744 virtual BOOL Decode(PASN_Stream &); 00745 virtual void Encode(PASN_Stream &) const; 00746 00747 #ifdef P_INCLUDE_BER 00748 BOOL DecodeBER(PBER_Stream & strm, unsigned len); 00749 void EncodeBER(PBER_Stream & strm) const; 00750 #endif 00751 00752 #ifdef P_INCLUDE_PER 00753 BOOL DecodePER(PPER_Stream & strm); 00754 void EncodePER(PPER_Stream & strm) const; 00755 #endif 00756 00757 protected: 00758 void Construct(); 00759 BOOL IsLegalCharacter(WORD ch); 00760 00761 PWORDArray value; 00762 PWORDArray characterSet; 00763 WORD firstChar, lastChar; 00764 unsigned charSetUnalignedBits; 00765 unsigned charSetAlignedBits; 00766 }; 00767 00768 00769 class PASN_GeneralisedTime : public PASN_VisibleString 00770 { 00771 PCLASSINFO(PASN_GeneralisedTime, PASN_VisibleString); 00772 public: 00773 PASN_GeneralisedTime() 00774 : PASN_VisibleString(UniversalGeneralisedTime, UniversalTagClass) { } 00775 PASN_GeneralisedTime(const PTime & time) 00776 : PASN_VisibleString(UniversalGeneralisedTime, UniversalTagClass) { SetValue(time); } 00777 PASN_GeneralisedTime(unsigned tag, TagClass tagClass) 00778 : PASN_VisibleString(tag, tagClass) { } 00779 00780 PASN_GeneralisedTime & operator=(const PTime & time); 00781 void SetValue(const PTime & time) { operator=(time); } 00782 PTime GetValue() const; 00783 }; 00784 00785 00786 class PASN_UniversalTime : public PASN_VisibleString 00787 { 00788 PCLASSINFO(PASN_UniversalTime, PASN_VisibleString); 00789 public: 00790 PASN_UniversalTime() 00791 : PASN_VisibleString(UniversalUTCTime, UniversalTagClass) { } 00792 PASN_UniversalTime(const PTime & time) 00793 : PASN_VisibleString(UniversalUTCTime, UniversalTagClass) { SetValue(time); } 00794 PASN_UniversalTime(unsigned tag, TagClass tagClass) 00795 : PASN_VisibleString(tag, tagClass) { } 00796 00797 PASN_UniversalTime & operator=(const PTime & time); 00798 void SetValue(const PTime & time) { operator=(time); } 00799 PTime GetValue() const; 00800 }; 00801 00802 00803 class PASN_Sequence; 00804 00807 class PASN_Choice : public PASN_Object 00808 { 00809 PCLASSINFO(PASN_Choice, PASN_Object); 00810 public: 00811 ~PASN_Choice(); 00812 00813 virtual void SetTag(unsigned newTag, TagClass tagClass = DefaultTagClass); 00814 PString GetTagName() const; 00815 PASN_Object & GetObject() const; 00816 BOOL IsValid() const { return choice != NULL; } 00817 00818 #if defined(__GNUC__) && __GNUC__ <= 2 && __GNUC_MINOR__ < 9 00819 00820 operator PASN_Null &() const; 00821 operator PASN_Boolean &() const; 00822 operator PASN_Integer &() const; 00823 operator PASN_Enumeration &() const; 00824 operator PASN_Real &() const; 00825 operator PASN_ObjectId &() const; 00826 operator PASN_BitString &() const; 00827 operator PASN_OctetString &() const; 00828 operator PASN_NumericString &() const; 00829 operator PASN_PrintableString &() const; 00830 operator PASN_VisibleString &() const; 00831 operator PASN_IA5String &() const; 00832 operator PASN_GeneralString &() const; 00833 operator PASN_BMPString &() const; 00834 operator PASN_Sequence &() const; 00835 00836 #else 00837 00838 operator PASN_Null &(); 00839 operator PASN_Boolean &(); 00840 operator PASN_Integer &(); 00841 operator PASN_Enumeration &(); 00842 operator PASN_Real &(); 00843 operator PASN_ObjectId &(); 00844 operator PASN_BitString &(); 00845 operator PASN_OctetString &(); 00846 operator PASN_NumericString &(); 00847 operator PASN_PrintableString &(); 00848 operator PASN_VisibleString &(); 00849 operator PASN_IA5String &(); 00850 operator PASN_GeneralString &(); 00851 operator PASN_BMPString &(); 00852 operator PASN_Sequence &(); 00853 00854 operator const PASN_Null &() const; 00855 operator const PASN_Boolean &() const; 00856 operator const PASN_Integer &() const; 00857 operator const PASN_Enumeration &() const; 00858 operator const PASN_Real &() const; 00859 operator const PASN_ObjectId &() const; 00860 operator const PASN_BitString &() const; 00861 operator const PASN_OctetString &() const; 00862 operator const PASN_NumericString &() const; 00863 operator const PASN_PrintableString &() const; 00864 operator const PASN_VisibleString &() const; 00865 operator const PASN_IA5String &() const; 00866 operator const PASN_GeneralString &() const; 00867 operator const PASN_BMPString &() const; 00868 operator const PASN_Sequence &() const; 00869 00870 #endif 00871 00872 virtual BOOL CreateObject() = 0; 00873 00874 virtual Comparison Compare(const PObject & obj) const; 00875 virtual void PrintOn(ostream & strm) const; 00876 00877 virtual PString GetTypeAsString() const; 00878 virtual PINDEX GetDataLength() const; 00879 virtual BOOL IsPrimitive() const; 00880 virtual BOOL Decode(PASN_Stream &); 00881 virtual void Encode(PASN_Stream &) const; 00882 00883 #ifdef P_INCLUDE_PER 00884 virtual BOOL DecodePER(PPER_Stream &); 00885 virtual void EncodePER(PPER_Stream &) const; 00886 #endif 00887 00888 #ifdef P_INCLUDE_XER 00889 BOOL DecodeXER(PXER_Stream &); 00890 void EncodeXER(PXER_Stream &) const; 00891 #endif 00892 00893 PASN_Choice & operator=(const PASN_Choice & other); 00894 00895 protected: 00896 PASN_Choice(unsigned nChoices = 0, BOOL extend = FALSE); 00897 PASN_Choice(unsigned tag, TagClass tagClass, unsigned nChoices, BOOL extend); 00898 PASN_Choice(unsigned tag, TagClass tagClass, unsigned nChoices, BOOL extend, const PString & nameSpec); 00899 00900 PASN_Choice(const PASN_Choice & other); 00901 00902 BOOL CheckCreate() const; 00903 00904 unsigned numChoices; 00905 PASN_Object * choice; 00906 POrdinalToString names; 00907 }; 00908 00909 00910 PARRAY(PASN_ObjectArray, PASN_Object); 00911 00912 00915 class PASN_Sequence : public PASN_Object 00916 { 00917 PCLASSINFO(PASN_Sequence, PASN_Object); 00918 public: 00919 PASN_Sequence(unsigned tag = UniversalSequence, 00920 TagClass tagClass = UniversalTagClass, 00921 unsigned nOpts = 0, BOOL extend = FALSE, unsigned nExtend = 0); 00922 00923 PASN_Sequence(const PASN_Sequence & other); 00924 PASN_Sequence & operator=(const PASN_Sequence & other); 00925 00926 PINDEX GetSize() const { return fields.GetSize(); } 00927 BOOL SetSize(PINDEX newSize); 00928 PASN_Object & operator[](PINDEX i) const { return fields[i]; } 00929 00930 BOOL HasOptionalField(PINDEX opt) const; 00931 void IncludeOptionalField(PINDEX opt); 00932 void RemoveOptionalField(PINDEX opt); 00933 00934 virtual Comparison Compare(const PObject & obj) const; 00935 virtual PObject * Clone() const; 00936 virtual void PrintOn(ostream & strm) const; 00937 00938 virtual PString GetTypeAsString() const; 00939 virtual PINDEX GetDataLength() const; 00940 virtual BOOL IsPrimitive() const; 00941 virtual BOOL Decode(PASN_Stream &); 00942 virtual void Encode(PASN_Stream &) const; 00943 00944 BOOL PreambleDecode(PASN_Stream & strm); 00945 void PreambleEncode(PASN_Stream & strm) const; 00946 BOOL KnownExtensionDecode(PASN_Stream & strm, PINDEX fld, PASN_Object & field); 00947 void KnownExtensionEncode(PASN_Stream & strm, PINDEX fld, const PASN_Object & field) const; 00948 BOOL UnknownExtensionsDecode(PASN_Stream & strm); 00949 void UnknownExtensionsEncode(PASN_Stream & strm) const; 00950 00951 #ifdef P_INCLUDE_BER 00952 BOOL PreambleDecodeBER(PBER_Stream & strm); 00953 void PreambleEncodeBER(PBER_Stream & strm) const; 00954 BOOL KnownExtensionDecodeBER(PBER_Stream & strm, PINDEX fld, PASN_Object & field); 00955 void KnownExtensionEncodeBER(PBER_Stream & strm, PINDEX fld, const PASN_Object & field) const; 00956 BOOL UnknownExtensionsDecodeBER(PBER_Stream & strm); 00957 void UnknownExtensionsEncodeBER(PBER_Stream & strm) const; 00958 #endif 00959 00960 #ifdef P_INCLUDE_PER 00961 BOOL PreambleDecodePER(PPER_Stream & strm); 00962 void PreambleEncodePER(PPER_Stream & strm) const; 00963 BOOL KnownExtensionDecodePER(PPER_Stream & strm, PINDEX fld, PASN_Object & field); 00964 void KnownExtensionEncodePER(PPER_Stream & strm, PINDEX fld, const PASN_Object & field) const; 00965 BOOL UnknownExtensionsDecodePER(PPER_Stream & strm); 00966 void UnknownExtensionsEncodePER(PPER_Stream & strm) const; 00967 #endif 00968 00969 #ifdef P_INCLUDE_XER 00970 virtual BOOL PreambleDecodeXER(PXER_Stream & strm); 00971 virtual void PreambleEncodeXER(PXER_Stream & strm) const; 00972 virtual BOOL KnownExtensionDecodeXER(PXER_Stream & strm, PINDEX fld, PASN_Object & field); 00973 virtual void KnownExtensionEncodeXER(PXER_Stream & strm, PINDEX fld, const PASN_Object & field) const; 00974 virtual BOOL UnknownExtensionsDecodeXER(PXER_Stream & strm); 00975 virtual void UnknownExtensionsEncodeXER(PXER_Stream & strm) const; 00976 #endif 00977 00978 protected: 00979 BOOL NoExtensionsToDecode(PPER_Stream & strm); 00980 BOOL NoExtensionsToEncode(PPER_Stream & strm); 00981 00982 PASN_ObjectArray fields; 00983 PASN_BitString optionMap; 00984 int knownExtensions; 00985 int totalExtensions; 00986 PASN_BitString extensionMap; 00987 PINDEX endBasicEncoding; 00988 }; 00989 00990 00993 class PASN_Set : public PASN_Sequence 00994 { 00995 PCLASSINFO(PASN_Set, PASN_Sequence); 00996 public: 00997 PASN_Set(unsigned tag = UniversalSet, 00998 TagClass tagClass = UniversalTagClass, 00999 unsigned nOpts = 0, BOOL extend = FALSE, unsigned nExtend = 0); 01000 01001 virtual PObject * Clone() const; 01002 virtual PString GetTypeAsString() const; 01003 }; 01004 01005 01008 class PASN_Array : public PASN_ConstrainedObject 01009 { 01010 PCLASSINFO(PASN_Array, PASN_ConstrainedObject); 01011 public: 01012 PINDEX GetSize() const { return array.GetSize(); } 01013 BOOL SetSize(PINDEX newSize); 01014 PASN_Object & operator[](PINDEX i) const { return array[i]; } 01015 void Append(PASN_Object * obj) { array.SetAt(array.GetSize(), obj); } 01016 void RemoveAt(PINDEX i) { array.RemoveAt(i); } 01017 void RemoveAll() { array.RemoveAll(); } 01018 01019 virtual Comparison Compare(const PObject & obj) const; 01020 virtual void PrintOn(ostream & strm) const; 01021 01022 virtual void SetConstraintBounds(ConstraintType type, int lower, unsigned upper); 01023 virtual PString GetTypeAsString() const; 01024 virtual PINDEX GetDataLength() const; 01025 virtual BOOL IsPrimitive() const; 01026 virtual BOOL Decode(PASN_Stream &); 01027 virtual void Encode(PASN_Stream &) const; 01028 01029 virtual PASN_Object * CreateObject() const = 0; 01030 01031 PASN_Array & operator=(const PASN_Array & other); 01032 01033 protected: 01034 PASN_Array(unsigned tag = UniversalSequence, 01035 TagClass tagClass = UniversalTagClass); 01036 01037 PASN_Array(const PASN_Array & other); 01038 01039 PASN_ObjectArray array; 01040 }; 01041 01042 01044 01047 class PASN_Stream : public PBYTEArray 01048 { 01049 PCLASSINFO(PASN_Stream, PBYTEArray); 01050 public: 01051 PASN_Stream(); 01052 PASN_Stream(const PBYTEArray & bytes); 01053 PASN_Stream(const BYTE * buf, PINDEX size); 01054 01055 void PrintOn(ostream & strm) const; 01056 01057 PINDEX GetPosition() const { return byteOffset; } 01058 void SetPosition(PINDEX newPos); 01059 BOOL IsAtEnd() { return byteOffset >= GetSize(); } 01060 void ResetDecoder(); 01061 void BeginEncoding(); 01062 void CompleteEncoding(); 01063 01064 virtual BOOL Read(PChannel & chan) = 0; 01065 virtual BOOL Write(PChannel & chan) = 0; 01066 01067 virtual BOOL NullDecode(PASN_Null &) = 0; 01068 virtual void NullEncode(const PASN_Null &) = 0; 01069 virtual BOOL BooleanDecode(PASN_Boolean &) = 0; 01070 virtual void BooleanEncode(const PASN_Boolean &) = 0; 01071 virtual BOOL IntegerDecode(PASN_Integer &) = 0; 01072 virtual void IntegerEncode(const PASN_Integer &) = 0; 01073 virtual BOOL EnumerationDecode(PASN_Enumeration &) = 0; 01074 virtual void EnumerationEncode(const PASN_Enumeration &) = 0; 01075 virtual BOOL RealDecode(PASN_Real &) = 0; 01076 virtual void RealEncode(const PASN_Real &) = 0; 01077 virtual BOOL ObjectIdDecode(PASN_ObjectId &) = 0; 01078 virtual void ObjectIdEncode(const PASN_ObjectId &) = 0; 01079 virtual BOOL BitStringDecode(PASN_BitString &) = 0; 01080 virtual void BitStringEncode(const PASN_BitString &) = 0; 01081 virtual BOOL OctetStringDecode(PASN_OctetString &) = 0; 01082 virtual void OctetStringEncode(const PASN_OctetString &) = 0; 01083 virtual BOOL ConstrainedStringDecode(PASN_ConstrainedString &) = 0; 01084 virtual void ConstrainedStringEncode(const PASN_ConstrainedString &) = 0; 01085 virtual BOOL BMPStringDecode(PASN_BMPString &) = 0; 01086 virtual void BMPStringEncode(const PASN_BMPString &) = 0; 01087 virtual BOOL ChoiceDecode(PASN_Choice &) = 0; 01088 virtual void ChoiceEncode(const PASN_Choice &) = 0; 01089 virtual BOOL ArrayDecode(PASN_Array &) = 0; 01090 virtual void ArrayEncode(const PASN_Array &) = 0; 01091 virtual BOOL SequencePreambleDecode(PASN_Sequence &) = 0; 01092 virtual void SequencePreambleEncode(const PASN_Sequence &) = 0; 01093 virtual BOOL SequenceKnownDecode(PASN_Sequence &, PINDEX, PASN_Object &) = 0; 01094 virtual void SequenceKnownEncode(const PASN_Sequence &, PINDEX, const PASN_Object &) = 0; 01095 virtual BOOL SequenceUnknownDecode(PASN_Sequence &) = 0; 01096 virtual void SequenceUnknownEncode(const PASN_Sequence &) = 0; 01097 01098 BYTE ByteDecode(); 01099 void ByteEncode(unsigned value); 01100 01101 unsigned BlockDecode(BYTE * bufptr, unsigned nBytes); 01102 void BlockEncode(const BYTE * bufptr, PINDEX nBytes); 01103 01104 void ByteAlign(); 01105 01106 protected: 01107 PINDEX byteOffset; 01108 unsigned bitOffset; 01109 01110 private: 01111 void Construct(); 01112 }; 01113 01114 #ifdef P_INCLUDE_PER 01115 #include "asnper.h" 01116 #endif 01117 01118 #ifdef P_INCLUDE_BER 01119 #include "asnber.h" 01120 #endif 01121 01122 #ifdef P_INCLUDE_XER 01123 #include "asnxer.h" 01124 #endif 01125 01126 #endif // _ASNER_H

Generated on Sat Jul 24 15:35:56 2004 for PWLib by doxygen 1.3.7