📄 asn1.h
字号:
class GeneralizedTime : public AbstractData, public detail::Allocator<GeneralizedTime>{protected: GeneralizedTime(const void* info);public: typedef const char* const_reference; GeneralizedTime(); GeneralizedTime(const char* value); GeneralizedTime(int year, int month, int day, int hour = 0, int minute=0, int second=0, int millisec = 0, int mindiff = 0, bool utc = false); GeneralizedTime(const GeneralizedTime& other) ; GeneralizedTime& operator = (const GeneralizedTime& other ) ; /** * Returns the character string format of this object. Unlike asValueNototation(), * the string returned by get() does not contain double quote marks ("). */ std::string get() const; /** * Set the value of this object using character string format. Unlike fromValueNototation(), * the string used by set() shall not contain double quote marks ("). */ void set(const char*); time_t get_time_t(); void set_time_t(time_t gmt); int get_year() const { return year; } int get_month() const { return month; } int get_day() const { return day; } int get_hour() const { return hour; } int get_minute() const { return minute;} int get_second() const { return second; } int get_millisec() const { return millisec; } int get_mindiff() const { return mindiff; } bool get_utc() const { return utc;} void set_year(int yr) { year = yr; } void set_month(int mon) { month = mon; } void set_day(int dy) { day = dy; } void set_hour(int hr) { hour = hr; } void set_minute(int min) { minute = min;} void set_second(int sec) { second = sec; } void set_millisec(int milsec) { millisec = milsec ;} void set_mindiff(int mdiff) { utc = false; mindiff = mdiff; } void set_utc(bool tc) { mindiff = 0; utc = tc; } void swap(GeneralizedTime& other) ; GeneralizedTime* clone() const { return static_cast<GeneralizedTime*>(do_clone()); } bool isValid() const { return isStrictlyValid();} static AbstractData* create(const void* info); bool isStrictlyValid() const; ASN1_EXPORT static const InfoType theInfo; static bool equal_type(const ASN1::AbstractData& type) {return type.info() == reinterpret_cast<const ASN1::AbstractData::InfoType*>(&theInfo);}private: virtual int do_compare(const AbstractData& other) const; virtual AbstractData* do_clone() const ; virtual bool do_accept(Visitor&); virtual bool do_accept(ConstVisitor&) const; int year, month, day, hour, minute, second, millisec, mindiff; bool utc;};/** Class for ASN Choice type.*/class CHOICE : public AbstractData, public detail::Allocator<CHOICE>{ public: enum Id { unknownSelection_ = -2, unselected_ = -1 }; /** * Returns the index of the currently selected alternatives. */ int currentSelection() const { return choiceID; } bool isSelected(int sel) const { return choiceID == sel; } bool isUnknownSelection() const { return choiceID == unknownSelection_; } bool isValid() const; bool isStrictlyValid() const; /** * Returns the object of the currently selected alternatives. */ AbstractData * getSelection() { return choice.get(); } const AbstractData * getSelection() const { return choice.get(); } /** * Set the value by alternative index number. */ bool select(int selection) { if (choiceID != selection) { choiceID = selection; return createSelection(); } return true; } /** * Set the value by index number and the pointer to the selected alternative. * * This member funtion will take the ownership of the object pointed by \c obj. * * @param id The index number of the selected alternative. * @param obj The pointer to the selected alternative. */ AbstractData* setSelection(int id, AbstractData* obj); /** * Returns the number of alternatives in the extension root. */ unsigned getNumChoices() const { return info()->numChoices; } bool extendable() const { return info()->extendableFlag; } unsigned getSelectionTag() const { assert(choiceID >= 0); return info()->tags == 0 ? 0x800000 | choiceID : info()->tags[choiceID]; } static AbstractData* create(const void* info); protected: CHOICE(const void* info , int id = -1, AbstractData* value= NULL); ~CHOICE(); CHOICE(const CHOICE & other); CHOICE & operator=(const CHOICE & other); void swap(CHOICE& other); std::auto_ptr<AbstractData> choice; int choiceID; struct InfoType { CreateFun create; unsigned tag; bool extendableFlag; const void** selectionInfos; unsigned numChoices; unsigned totalChoices; unsigned* tags; AVN_ONLY(const char** names;) }; private: virtual int do_compare(const AbstractData& other) const; virtual bool do_accept(Visitor&); virtual bool do_accept(ConstVisitor&) const; virtual AbstractData* do_clone() const; bool createSelection(); const InfoType* info() const { return static_cast<const InfoType*>(info_);} public: /** * Set the value by \c tag number and \c tag class. */ bool setID(unsigned tagNum, unsigned tagClass);#ifdef ASN1_HAS_IOSTREAM public: const char* getSelectionName() const { assert(choiceID < static_cast<int>(info()->totalChoices)); return info()->names[choiceID]; } friend class AVNDecoder;#endif};class PEREncoder;class PERDecoder;/** Class for ASN Sequence type.*/class SEQUENCE : public AbstractData, public detail::Allocator<SEQUENCE>{public: enum { AUTOMATIC_TAG, EXPLICIT_TAG, IMPLICIT_TAG }; SEQUENCE(const SEQUENCE & other); ~SEQUENCE(); SEQUENCE & operator=(const SEQUENCE & other); SEQUENCE * clone() const { return static_cast<SEQUENCE*>(do_clone()); } void swap(SEQUENCE& other); /** * Returns the pointer to the component of the SEQUENCE at position \c pos. */ AbstractData* getField(unsigned pos) { assert(pos < fields.size()); return fields[pos]; } const AbstractData* getField(unsigned pos) const { assert(pos < fields.size()); return fields[pos]; } unsigned tagMode() const { if (info()->tags == 0) return AUTOMATIC_TAG; else if (info()->tags != static_cast<const void*>(&defaultTag)) return EXPLICIT_TAG; else return IMPLICIT_TAG; } unsigned getFieldTag(int pos) const { if (info()->tags == 0) // Automatic Tags return 0x800000 | pos; else if (info()->tags != static_cast<const void*>(&defaultTag)) // EXPLICIT Tag return info()->tags[pos]; else return static_cast<const AbstractData::InfoType*>(info()->fieldInfos[pos])->tag; // IMPLICIT Tag } bool extendable() const { return info()->extendableFlag; } /** * Makes an OPTIONAL field present. * * @param opt The index to the OPTIONAL field * @param pos The position of the OPTIONAL field */ void includeOptionalField(unsigned opt, unsigned pos); /** * Tests the presence of an OPTIONAL field. * * @param opt The index to the OPTIONAL field */ bool hasOptionalField(unsigned opt) const; /** * Makes an OPTIONAL field absence. * * @param opt The index to the OPTIONAL field */ void removeOptionalField(unsigned opt); static AbstractData* create(const void*); protected: SEQUENCE(const void* info); enum { mandatory_ = -1 }; class FieldVector : public std::vector<AbstractData*> { public: FieldVector(){}; ~FieldVector(); FieldVector(const FieldVector& other); private: FieldVector& operator = (const FieldVector& other); }; struct BitMap { BitMap() : totalBits(0) {} unsigned size() const { return totalBits;} void resize(unsigned nBits); bool operator [] (unsigned bit) const; void set(unsigned bit); void clear(unsigned bit); void swap(BitMap& other); unsigned totalBits; std::vector<char> bitData; }; FieldVector fields; BitMap optionMap; BitMap extensionMap; ASN1_EXPORT static const unsigned defaultTag; struct InfoType { CreateFun create; unsigned tag; bool extendableFlag; const void** fieldInfos; int* ids; unsigned numFields; unsigned knownExtensions; unsigned numOptional; const char* nonOptionalExtensions; const unsigned* tags; AVN_ONLY(const char** names;) }; private: friend class Visitor; friend class ConstVisitor; friend class PEREncoder; friend class PERDecoder; virtual int do_compare(const AbstractData& other) const; virtual AbstractData* do_clone() const ; virtual bool do_accept(ConstVisitor&) const; const InfoType* info() const { return static_cast<const InfoType*>(info_);} protected: virtual bool do_accept(Visitor&);#ifdef ASN1_HAS_IOSTREAM public: const char* getFieldName(int i) const { return info()->names[i]; }#endif};/** Class for ASN set type.*/class SET : public SEQUENCE{ public: SET * clone() const { return static_cast<SET*>(SEQUENCE::clone()); } protected: SET::SET(const void* info) : SEQUENCE(info) { }};/** Class for ASN SEQUENCE type.*/class SEQUENCE_OF_Base : public ConstrainedObject, public detail::Allocator<SEQUENCE_OF_Base>{ protected: typedef std::vector<AbstractData*> Container; SEQUENCE_OF_Base(const void*); public: ~SEQUENCE_OF_Base() { clear();} SEQUENCE_OF_Base(const SEQUENCE_OF_Base & other); SEQUENCE_OF_Base & operator=(const SEQUENCE_OF_Base & other); typedef Container::iterator iterator; typedef Container::const_iterator const_iterator; iterator begin() { return container.begin(); } iterator end() { return container.end(); } const_iterator begin() const { return container.begin(); } const_iterator end() const { r
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -