1/*
2 * Python bindings.
3 *
4 * Open Phone Abstraction Library (OPAL)
5 *
6 * Copyright (c) 2011 Demetrius Cassidy
7 *
8 * The contents of this file are subject to the Mozilla Public License
9 * Version 1.0 (the "License"); you may not use this file except in
10 * compliance with the License. You may obtain a copy of the License at
11 * http://www.mozilla.org/MPL/
12 *
13 * Software distributed under the License is distributed on an "AS IS"
14 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
15 * the License for the specific language governing rights and limitations
16 * under the License.
17 *
18 * The Original Code is Open Phone Abstraction Library (OPAL)
19 *
20 * The Initial Developer of the Original Code is Demetrius Cassidy
21 *
22 * Contributor(s): ______________________________________.
23 *
24 * $Revision: 26117 $
25 * $Author: rjongbloed $
26 * $Date: 2011-07-04 22:45:05 -0500 (Mon, 04 Jul 2011) $
27 */
28
29/////////////////////////////////////////////////////////////////////////////
30
31/** Base class for ASN encoding/decoding.
32*/
33class PASN_Object : PObject /Abstract/
34{
35
36  public:
37    /** Return a string giving the type of the object */
38    virtual PString GetTypeAsString() const = 0;
39
40    PINDEX GetObjectLength() const;
41    virtual PINDEX GetDataLength() const = 0;
42    virtual PBoolean IsPrimitive() const;
43
44    virtual PBoolean Decode(PASN_Stream &) = 0;
45    virtual void Encode(PASN_Stream &) const = 0;
46
47    PBoolean IsExtendable() const;
48    void SetExtendable(PBoolean ext = PTrue);
49
50    enum TagClass {
51      UniversalTagClass,
52      ApplicationTagClass,
53      ContextSpecificTagClass,
54      PrivateTagClass,
55      DefaultTagClass
56    };
57
58    TagClass GetTagClass() const;
59
60    enum UniversalTags {
61      InvalidUniversalTag,
62      UniversalBoolean,
63      UniversalInteger,
64      UniversalBitString,
65      UniversalOctetString,
66      UniversalNull,
67      UniversalObjectId,
68      UniversalObjectDescriptor,
69      UniversalExternalType,
70      UniversalReal,
71      UniversalEnumeration,
72      UniversalEmbeddedPDV,
73      UniversalSequence = 16,
74      UniversalSet,
75      UniversalNumericString,
76      UniversalPrintableString,
77      UniversalTeletexString,
78      UniversalVideotexString,
79      UniversalIA5String,
80      UniversalUTCTime,
81      UniversalGeneralisedTime,
82      UniversalGeneralizedTime = UniversalGeneralisedTime,
83      UniversalGraphicString,
84      UniversalVisibleString,
85      UniversalGeneralString,
86      UniversalUniversalString,
87      UniversalBMPString = 30
88    };
89
90    unsigned GetTag() const;
91    virtual void SetTag(unsigned newTag, TagClass tagClass = DefaultTagClass);
92
93    enum ConstraintType {
94      Unconstrained,
95      PartiallyConstrained,
96      FixedConstraint,
97      ExtendableConstraint
98    };
99
100    enum MinimumValueTag { MinimumValue = INT_MIN };
101    enum MaximumValueTag { MaximumValue = INT_MAX };
102    // void SetConstraints(ConstraintType type, int value);
103    // void SetConstraints(ConstraintType, int lower, MaximumValueTag /*upper*/);
104    // void SetConstraints(ConstraintType, MinimumValueTag lower, unsigned upper);
105    // void SetConstraints(ConstraintType, MinimumValueTag lower, MaximumValueTag upper);
106    void SetConstraints(ConstraintType type, int lower, unsigned upper);
107
108    virtual void SetConstraintBounds(ConstraintType type, int lower, unsigned upper);
109    virtual void SetCharacterSet(ConstraintType ctype, const char * charSet);
110    // virtual void SetCharacterSet(ConstraintType ctype, unsigned firstChar, unsigned lastChar);
111
112    static PINDEX GetMaximumArraySize();
113    static void SetMaximumArraySize(PINDEX sz);
114    static PINDEX GetMaximumStringSize();
115    static void SetMaximumStringSize(PINDEX sz);
116
117  protected:
118    PASN_Object(unsigned tag, TagClass tagClass, PBoolean extend = PFalse);
119
120};
121
122
123/** Base class for constrained ASN encoding/decoding.
124*/
125class PASN_ConstrainedObject : PASN_Object
126{
127
128  public:
129    PBoolean IsConstrained() const;
130    int GetLowerLimit() const;
131    unsigned GetUpperLimit() const;
132
133    PBoolean ConstrainedLengthDecode(PPER_Stream & strm, unsigned & length);
134    void ConstrainedLengthEncode(PPER_Stream & strm, unsigned length) const;
135
136    PBoolean ConstraintEncode(PPER_Stream & strm, unsigned value) const;
137
138  protected:
139    virtual void SetConstraintBounds(ConstraintType type, int lower, unsigned upper);
140    PASN_ConstrainedObject(unsigned tag, PASN_Object::TagClass tagClass);
141
142};
143
144
145/** Class for ASN Null type.
146*/
147class PASN_Null : PASN_Object
148{
149
150  public:
151    PASN_Null(unsigned tag = UniversalNull,
152              PASN_Object::TagClass tagClass = UniversalTagClass);
153
154    virtual Comparison Compare(const PObject & obj) const;
155    virtual PObject * Clone() const;
156
157
158    virtual PString GetTypeAsString() const;
159    virtual PINDEX GetDataLength() const;
160    virtual PBoolean Decode(PASN_Stream &);
161    virtual void Encode(PASN_Stream &) const;
162};
163
164
165/** Class for ASN Boolean type.
166*/
167class PASN_Boolean : PASN_Object
168{
169
170  public:
171    PASN_Boolean(PBoolean val = PFalse);
172    PASN_Boolean(unsigned tag, PASN_Object::TagClass tagClass, PBoolean val = PFalse);
173
174    operator PBoolean() const;
175    PBoolean GetValue() const;
176    void SetValue(PBoolean v);
177
178    virtual Comparison Compare(const PObject & obj) const;
179    virtual PObject * Clone() const;
180
181
182    virtual PString GetTypeAsString() const;
183    virtual PINDEX GetDataLength() const;
184    virtual PBoolean Decode(PASN_Stream &);
185    virtual void Encode(PASN_Stream &) const;
186
187};
188
189
190/** Class for ASN Integer type.
191*/
192class PASN_Integer : PASN_ConstrainedObject
193{
194
195  public:
196    PASN_Integer(unsigned val = 0);
197    PASN_Integer(unsigned tag, PASN_Object::TagClass tagClass, unsigned val = 0);
198
199    operator unsigned() const;
200    unsigned GetValue() const;
201    void SetValue(unsigned v);
202
203    virtual Comparison Compare(const PObject & obj) const;
204    virtual PObject * Clone() const;
205
206
207    virtual void SetConstraintBounds(ConstraintType type, int lower, unsigned upper);
208    virtual PString GetTypeAsString() const;
209    virtual PINDEX GetDataLength() const;
210    virtual PBoolean Decode(PASN_Stream &);
211    virtual void Encode(PASN_Stream &) const;
212
213    PBoolean DecodePER(PPER_Stream & strm);
214    void EncodePER(PPER_Stream & strm) const;
215
216    PBoolean IsUnsigned() const;
217
218};
219
220struct PASN_Names{
221    const char * name;
222    PINDEX value;
223};
224
225/** Class for ASN Enumerated type.
226*/
227class PASN_Enumeration : PASN_Object
228{
229
230  public:
231    PASN_Enumeration(unsigned val = 0);
232    PASN_Enumeration(unsigned tag,
233                     PASN_Object::TagClass tagClass,
234                     unsigned nEnums = P_MAX_INDEX,
235                     PBoolean extendable = PFalse,
236                     unsigned val = 0);
237    PASN_Enumeration(unsigned tag,
238                     PASN_Object::TagClass tagClass,
239                     unsigned nEnums,
240                     PBoolean extendable,
241                     const PASN_Names * nameSpec,
242                     unsigned namesCnt,
243                     unsigned val = 0);
244
245
246    operator unsigned() const;
247    unsigned GetValue() const;
248    void SetValue(unsigned v);
249
250    unsigned GetMaximum() const;
251
252    virtual Comparison Compare(const PObject & obj) const;
253    virtual PObject * Clone() const;
254
255
256    virtual PString GetTypeAsString() const;
257    virtual PINDEX GetDataLength() const;
258    virtual PBoolean Decode(PASN_Stream &);
259    virtual void Encode(PASN_Stream &) const;
260
261    PBoolean DecodePER(PPER_Stream & strm);
262    void EncodePER(PPER_Stream & strm) const;
263
264
265    PINDEX GetValueByName(PString name) const;
266};
267
268
269/** Class for ASN floating point type.
270*/
271class PASN_Real : PASN_Object
272{
273
274  public:
275    PASN_Real(double val = 0);
276    PASN_Real(unsigned tag, PASN_Object::TagClass tagClass, double val = 0);
277
278    operator double() const;
279    double GetValue() const;
280    void SetValue(double v);
281
282    virtual Comparison Compare(const PObject & obj) const;
283    virtual PObject * Clone() const;
284
285
286    virtual PString GetTypeAsString() const;
287    virtual PINDEX GetDataLength() const;
288    virtual PBoolean Decode(PASN_Stream &);
289    virtual void Encode(PASN_Stream &) const;
290
291};
292
293
294/** Class for ASN Object Identifier type.
295*/
296class PASN_ObjectId : PASN_Object
297{
298
299  public:
300    PASN_ObjectId(const char * dotstr = NULL);
301    PASN_ObjectId(unsigned tag, PASN_Object::TagClass tagClass);
302
303    PASN_ObjectId(const PASN_ObjectId & other);
304
305    //void SetValue(const PString & dotstr);
306    void SetValue(const PUnsignedArray & numbers);
307
308    bool operator==(const char * dotstr) const;
309    bool operator!=(const char * dotstr) const;
310    bool operator==(const PString & dotstr) const;
311    bool operator!=(const PString & dotstr) const;
312    bool operator==(const PASN_ObjectId & id) const;
313
314    PINDEX GetSize() const;
315    unsigned operator[](PINDEX idx) const;
316    const PUnsignedArray & GetValue() const;
317    PString AsString() const;
318
319    virtual Comparison Compare(const PObject & obj) const;
320    virtual PObject * Clone() const;
321
322
323    virtual PString GetTypeAsString() const;
324    virtual PINDEX GetDataLength() const;
325    virtual PBoolean Decode(PASN_Stream &);
326    virtual void Encode(PASN_Stream &) const;
327
328    PBoolean CommonDecode(PASN_Stream & strm, unsigned dataLen);
329    void CommonEncode(PBYTEArray & eObjId) const;
330
331};
332
333
334/** Class for ASN Bit String type.
335*/
336class PASN_BitString : PASN_ConstrainedObject
337{
338
339  public:
340    PASN_BitString(unsigned nBits = 0, const BYTE * buf = NULL);
341    PASN_BitString(unsigned tag, PASN_Object::TagClass tagClass, unsigned nBits = 0);
342
343    PASN_BitString(const PASN_BitString & other);
344
345    void SetData(unsigned nBits, const PBYTEArray & bytes);
346    void SetData(unsigned nBits, const BYTE * buf, PINDEX size = 0);
347
348    const BYTE * GetDataPointer() const;
349
350    unsigned GetSize() const;
351    PBoolean SetSize(unsigned nBits);
352
353    bool operator[](PINDEX bit) const;
354    void Set(unsigned bit);
355    void Clear(unsigned bit);
356    void Invert(unsigned bit);
357
358    virtual Comparison Compare(const PObject & obj) const;
359    virtual PObject * Clone() const;
360
361    virtual void SetConstraintBounds(ConstraintType type, int lower, unsigned upper);
362    virtual PString GetTypeAsString() const;
363    virtual PINDEX GetDataLength() const;
364    virtual PBoolean Decode(PASN_Stream &);
365    virtual void Encode(PASN_Stream &) const;
366
367    PBoolean DecodeBER(PBER_Stream & strm, unsigned len);
368    void EncodeBER(PBER_Stream & strm) const;
369
370    PBoolean DecodePER(PPER_Stream & strm);
371    void EncodePER(PPER_Stream & strm) const;
372
373
374    PBoolean DecodeSequenceExtensionBitmap(PPER_Stream & strm);
375    void EncodeSequenceExtensionBitmap(PPER_Stream & strm) const;
376
377};
378
379
380/** Class for ASN Octet String type.
381*/
382class PASN_OctetString : PASN_ConstrainedObject
383{
384
385  public:
386    PASN_OctetString(const char * str = NULL, PINDEX size = 0);
387    PASN_OctetString(unsigned tag, PASN_Object::TagClass tagClass);
388
389    PASN_OctetString(const PASN_OctetString & other);
390
391
392    void SetValue(const char * str);
393    void SetValue(const PString & str);
394    void SetValue(const PBYTEArray & arr);
395    void SetValue(const BYTE * data, PINDEX len);
396	PString AsString() const;
397    const PBYTEArray & GetValue() const;
398
399    BYTE operator[](PINDEX i) const;
400
401    //BYTE & operator[](PINDEX i);
402
403    BYTE * GetPointer(PINDEX sz = 0);
404    PINDEX GetSize() const;
405    PBoolean SetSize(PINDEX newSize);
406
407    virtual Comparison Compare(const PObject & obj) const;
408    virtual PObject * Clone() const;
409
410    virtual void SetConstraintBounds(ConstraintType type, int lower, unsigned upper);
411    virtual PString GetTypeAsString() const;
412    virtual PINDEX GetDataLength() const;
413    virtual PBoolean Decode(PASN_Stream &);
414    virtual void Encode(PASN_Stream &) const;
415
416    PBoolean DecodePER(PPER_Stream & strm);
417    void EncodePER(PPER_Stream & strm) const;
418
419    PBoolean DecodeSubType(PASN_Object &) const;
420    void EncodeSubType(const PASN_Object &);
421
422};
423
424
425/** Base class for ASN String types.
426*/
427class PASN_ConstrainedString : PASN_ConstrainedObject
428{
429
430  public:
431
432    const PString & GetValue() const;
433    void SetValue(const char * v);
434    void SetValue(const PString & v);
435
436    char operator[](PINDEX idx) const;
437
438    void SetCharacterSet(ConstraintType ctype, const char * charSet);
439    void SetCharacterSet(ConstraintType ctype, unsigned firstChar = 0, unsigned lastChar = 255);
440    void SetCharacterSet(const char * charSet, PINDEX size, ConstraintType ctype);
441
442    virtual Comparison Compare(const PObject & obj) const;
443
444    virtual void SetConstraintBounds(ConstraintType type, int lower, unsigned upper);
445    virtual PINDEX GetDataLength() const;
446    virtual PBoolean Decode(PASN_Stream &);
447    virtual void Encode(PASN_Stream &) const;
448
449
450    PBoolean DecodeBER(PBER_Stream & strm, unsigned len);
451    void EncodeBER(PBER_Stream & strm) const;
452
453    PBoolean DecodePER(PPER_Stream & strm);
454    void EncodePER(PPER_Stream & strm) const;
455
456
457  protected:
458    PASN_ConstrainedString(const char * canonicalSet, PINDEX setSize,
459                           unsigned tag, PASN_Object::TagClass tagClass);
460};
461
462
463class PASN_NumericString : PASN_ConstrainedString
464{
465
466public:
467  PASN_NumericString(const char * str = NULL);
468  PASN_NumericString(unsigned tag, PASN_Object::TagClass tagClass);
469
470  virtual PObject * Clone() const;
471  virtual PString GetTypeAsString() const;
472};
473
474class PASN_PrintableString : PASN_ConstrainedString
475{
476public:
477  PASN_PrintableString(const char * str = NULL);
478  PASN_PrintableString(unsigned tag, PASN_Object::TagClass tagClass);
479
480  virtual PObject * Clone() const;
481  virtual PString GetTypeAsString() const;
482};
483
484class PASN_VisibleString : PASN_ConstrainedString {
485
486public:
487  PASN_VisibleString(const char * str = NULL);
488  PASN_VisibleString(unsigned tag, PASN_Object::TagClass tagClass);
489
490  virtual PObject * Clone() const;
491  virtual PString GetTypeAsString() const;
492};
493
494class PASN_IA5String : PASN_ConstrainedString {
495
496public:
497  PASN_IA5String(const char * str = NULL);
498  PASN_IA5String(unsigned tag, PASN_Object::TagClass tagClass);
499
500  virtual PObject * Clone() const;
501  virtual PString GetTypeAsString() const;
502};
503
504class PASN_GeneralString : PASN_ConstrainedString {
505
506public:
507  PASN_GeneralString(const char * str = NULL);
508  PASN_GeneralString(unsigned tag, PASN_Object::TagClass tagClass);
509
510  virtual PObject * Clone() const;
511  virtual PString GetTypeAsString() const;
512};
513
514
515/** Class for ASN BMP (16 bit) String type.
516*/
517class PASN_BMPString : PASN_ConstrainedObject
518{
519
520  public:
521    PASN_BMPString(const char * str = NULL);
522    PASN_BMPString(const PWCharArray & wstr);
523	PASN_BMPString(unsigned tag, PASN_Object::PASN_Object::TagClass tagClass);
524
525    PASN_BMPString(const PASN_BMPString & other);
526
527    PString GetValue() const;
528
529    void GetValue(PWCharArray & v) const;
530    void SetValue(const char * v);
531    void SetValue(const PString & v);
532    void SetValue(const PWCharArray & v);
533    void SetValue(const PASN_BMPString & v);
534    void SetValueRaw(const PWCharArray & v);
535    void SetValueRaw(const wchar_t * val, PINDEX len);
536
537    void SetCharacterSet(ConstraintType ctype, const char * charSet);
538    void SetCharacterSet(ConstraintType ctype, const PWCharArray & charSet);
539    void SetCharacterSet(ConstraintType ctype, unsigned firstChar, unsigned lastChar);
540
541    virtual Comparison Compare(const PObject & obj) const;
542    virtual PObject * Clone() const;
543
544    virtual PString GetTypeAsString() const;
545    virtual PINDEX GetDataLength() const;
546    virtual PBoolean Decode(PASN_Stream &);
547    virtual void Encode(PASN_Stream &) const;
548
549    PBoolean DecodeBER(PBER_Stream & strm, unsigned len);
550    void EncodeBER(PBER_Stream & strm) const;
551
552    PBoolean DecodePER(PPER_Stream & strm);
553    void EncodePER(PPER_Stream & strm) const;
554
555
556  protected:
557    void Construct();
558    PBoolean IsLegalCharacter(WORD ch);
559
560};
561
562
563class PASN_GeneralisedTime : PASN_VisibleString
564{
565
566  public:
567    PASN_GeneralisedTime();
568    PASN_GeneralisedTime(const PTime & time);
569    PASN_GeneralisedTime(unsigned theTag, PASN_Object::PASN_Object theTagClass);
570
571
572    void SetValue(const PTime & time);
573    PTime GetValue() const;
574};
575
576
577class PASN_UniversalTime : PASN_VisibleString
578{
579
580  public:
581    PASN_UniversalTime();
582    PASN_UniversalTime(const PTime & time);
583    PASN_UniversalTime(unsigned theTag, PASN_Object::PASN_Object theTagClass);
584
585    void SetValue(const PTime & time);
586    PTime GetValue() const;
587};
588
589
590/** Class for ASN Choice type.
591*/
592class PASN_Choice : PASN_Object /Abstract/
593{
594
595  public:
596    ~PASN_Choice();
597
598    virtual void SetTag(unsigned newTag, PASN_Object::TagClass tagClass = DefaultTagClass);
599    PString GetTagName() const;
600    PASN_Object & GetObject() const;
601    PBoolean IsValid() const;
602
603
604    operator PASN_Null &();
605    operator PASN_Boolean &();
606    operator PASN_Integer &();
607    operator PASN_Enumeration &();
608    operator PASN_Real &();
609    operator PASN_ObjectId &();
610    operator PASN_BitString &();
611    operator PASN_OctetString &();
612    operator PASN_NumericString &();
613    operator PASN_PrintableString &();
614    operator PASN_VisibleString &();
615    operator PASN_IA5String &();
616    operator PASN_GeneralString &();
617    operator PASN_BMPString &();
618    operator PASN_Sequence &();
619
620
621    virtual PBoolean CreateObject() = 0;
622
623    virtual Comparison Compare(const PObject & obj) const;
624
625
626    virtual PString GetTypeAsString() const;
627    virtual PINDEX GetDataLength() const;
628    virtual PBoolean IsPrimitive() const;
629    virtual PBoolean Decode(PASN_Stream &);
630    virtual void Encode(PASN_Stream &) const;
631
632    virtual PBoolean DecodePER(PPER_Stream &);
633    virtual void EncodePER(PPER_Stream &) const;
634
635    PINDEX GetValueByName(PString name) const;
636
637  protected:
638    PASN_Choice(unsigned nChoices = 0, PBoolean extend = PFalse);
639    PASN_Choice(unsigned tag, PASN_Object::TagClass tagClass, unsigned nChoices, PBoolean extend);
640    PASN_Choice(unsigned tag, PASN_Object::TagClass tagClass, unsigned nChoices, PBoolean extend, const PASN_Names * nameSpec,unsigned namesCnt);
641
642    PASN_Choice(const PASN_Choice & other);
643
644    PBoolean CheckCreate() const;
645
646};
647
648
649typedef PArray<PASN_Object> PASN_ObjectArray;
650
651
652/** Class for ASN Sequence type.
653*/
654class PASN_Sequence : PASN_Object
655{
656
657  public:
658    PASN_Sequence(unsigned tag = UniversalSequence,
659                  PASN_Object::TagClass tagClass = UniversalTagClass,
660                  unsigned nOpts = 0, PBoolean extend = PFalse, unsigned nExtend = 0);
661
662    PASN_Sequence(const PASN_Sequence & other);
663
664    PINDEX GetSize() const;
665    PBoolean SetSize(PINDEX newSize);
666    PASN_Object & operator[](PINDEX i) const;
667
668    PBoolean HasOptionalField(PINDEX opt) const;
669    void IncludeOptionalField(PINDEX opt);
670    void RemoveOptionalField(PINDEX opt);
671
672    virtual Comparison Compare(const PObject & obj) const;
673    virtual PObject * Clone() const;
674
675
676    virtual PString GetTypeAsString() const;
677    virtual PINDEX GetDataLength() const;
678    virtual PBoolean IsPrimitive() const;
679    virtual PBoolean Decode(PASN_Stream &);
680    virtual void Encode(PASN_Stream &) const;
681
682    PBoolean PreambleDecode(PASN_Stream & strm);
683    void PreambleEncode(PASN_Stream & strm) const;
684    PBoolean KnownExtensionDecode(PASN_Stream & strm, PINDEX fld, PASN_Object & field);
685    void KnownExtensionEncode(PASN_Stream & strm, PINDEX fld, const PASN_Object & field) const;
686    PBoolean UnknownExtensionsDecode(PASN_Stream & strm);
687    void UnknownExtensionsEncode(PASN_Stream & strm) const;
688
689    PBoolean PreambleDecodeBER(PBER_Stream & strm);
690    void PreambleEncodeBER(PBER_Stream & strm) const;
691    PBoolean KnownExtensionDecodeBER(PBER_Stream & strm, PINDEX fld, PASN_Object & field);
692    void KnownExtensionEncodeBER(PBER_Stream & strm, PINDEX fld, const PASN_Object & field) const;
693    PBoolean UnknownExtensionsDecodeBER(PBER_Stream & strm);
694    void UnknownExtensionsEncodeBER(PBER_Stream & strm) const;
695
696    PBoolean PreambleDecodePER(PPER_Stream & strm);
697    void PreambleEncodePER(PPER_Stream & strm) const;
698    PBoolean KnownExtensionDecodePER(PPER_Stream & strm, PINDEX fld, PASN_Object & field);
699    void KnownExtensionEncodePER(PPER_Stream & strm, PINDEX fld, const PASN_Object & field) const;
700    PBoolean UnknownExtensionsDecodePER(PPER_Stream & strm);
701    void UnknownExtensionsEncodePER(PPER_Stream & strm) const;
702
703
704  protected:
705    PBoolean NoExtensionsToDecode(PPER_Stream & strm);
706    PBoolean NoExtensionsToEncode(PPER_Stream & strm);
707
708};
709
710
711/** Class for ASN Set type.
712*/
713class PASN_Set : PASN_Sequence
714{
715
716  public:
717    PASN_Set(unsigned tag = UniversalSet,
718             PASN_Object::TagClass tagClass = UniversalTagClass,
719             unsigned nOpts = 0, PBoolean extend = PFalse, unsigned nExtend = 0);
720
721    virtual PObject * Clone() const;
722    virtual PString GetTypeAsString() const;
723};
724
725
726/** Class for ASN Array type.
727*/
728class PASN_Array : PASN_ConstrainedObject /Abstract/
729{
730
731  public:
732    PINDEX GetSize() const;
733    PBoolean SetSize(PINDEX newSize);
734    PASN_Object & operator[](PINDEX i) const;
735    void Append(PASN_Object * obj);
736    void RemoveAt(PINDEX i);
737    void RemoveAll();
738
739    virtual Comparison Compare(const PObject & obj) const;
740
741
742    virtual void SetConstraintBounds(ConstraintType type, int lower, unsigned upper);
743    virtual PString GetTypeAsString() const;
744    virtual PINDEX GetDataLength() const;
745    virtual PBoolean IsPrimitive() const;
746    virtual PBoolean Decode(PASN_Stream &);
747    virtual void Encode(PASN_Stream &) const;
748
749    virtual PASN_Object * CreateObject() const = 0;
750
751
752  protected:
753    PASN_Array(unsigned tag = UniversalSequence,
754               PASN_Object::TagClass tagClass = UniversalTagClass);
755
756    PASN_Array(const PASN_Array & other);
757
758};
759
760
761/////////////////////////////////////////////////////////////////////////////
762
763/** Base class for ASN decoder/encoder stream.
764*/
765class PASN_Stream /Abstract/
766{
767
768  public:
769    PASN_Stream();
770    PASN_Stream(const PBYTEArray & bytes);
771    PASN_Stream(const BYTE * buf, PINDEX size);
772
773    PINDEX GetPosition() const;
774    void SetPosition(PINDEX newPos);
775    PBoolean IsAtEnd();
776    void ResetDecoder();
777    void BeginEncoding();
778    void CompleteEncoding();
779
780    virtual PBoolean Read(PChannel & chan) = 0;
781    virtual PBoolean Write(PChannel & chan) = 0;
782
783    virtual PBoolean NullDecode(PASN_Null &) = 0;
784    virtual void NullEncode(const PASN_Null &) = 0;
785    virtual PBoolean BooleanDecode(PASN_Boolean &) = 0;
786    virtual void BooleanEncode(const PASN_Boolean &) = 0;
787    virtual PBoolean IntegerDecode(PASN_Integer &) = 0;
788    virtual void IntegerEncode(const PASN_Integer &) = 0;
789    virtual PBoolean EnumerationDecode(PASN_Enumeration &) = 0;
790    virtual void EnumerationEncode(const PASN_Enumeration &) = 0;
791    virtual PBoolean RealDecode(PASN_Real &) = 0;
792    virtual void RealEncode(const PASN_Real &) = 0;
793    virtual PBoolean ObjectIdDecode(PASN_ObjectId &) = 0;
794    virtual void ObjectIdEncode(const PASN_ObjectId &) = 0;
795    virtual PBoolean BitStringDecode(PASN_BitString &) = 0;
796    virtual void BitStringEncode(const PASN_BitString &) = 0;
797    virtual PBoolean OctetStringDecode(PASN_OctetString &) = 0;
798    virtual void OctetStringEncode(const PASN_OctetString &) = 0;
799    virtual PBoolean ConstrainedStringDecode(PASN_ConstrainedString &) = 0;
800    virtual void ConstrainedStringEncode(const PASN_ConstrainedString &) = 0;
801    virtual PBoolean BMPStringDecode(PASN_BMPString &) = 0;
802    virtual void BMPStringEncode(const PASN_BMPString &) = 0;
803    virtual PBoolean ChoiceDecode(PASN_Choice &) = 0;
804    virtual void ChoiceEncode(const PASN_Choice &) = 0;
805    virtual PBoolean ArrayDecode(PASN_Array &) = 0;
806    virtual void ArrayEncode(const PASN_Array &) = 0;
807    virtual PBoolean SequencePreambleDecode(PASN_Sequence &) = 0;
808    virtual void SequencePreambleEncode(const PASN_Sequence &) = 0;
809    virtual PBoolean SequenceKnownDecode(PASN_Sequence &, PINDEX, PASN_Object &) = 0;
810    virtual void SequenceKnownEncode(const PASN_Sequence &, PINDEX, const PASN_Object &) = 0;
811    virtual PBoolean SequenceUnknownDecode(PASN_Sequence &) = 0;
812    virtual void SequenceUnknownEncode(const PASN_Sequence &) = 0;
813
814    BYTE ByteDecode();
815    void ByteEncode(unsigned value);
816
817    unsigned BlockDecode(BYTE * bufptr, unsigned nBytes);
818    void BlockEncode(const BYTE * bufptr, PINDEX nBytes);
819
820    void ByteAlign();
821
822
823  private:
824    void Construct();
825};