⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 asn1.h

📁 asn格式文件的编译器
💻 H
📖 第 1 页 / 共 5 页
字号:
	ThisType& operator ++ () { ++ value  ; assert(isValid()); return *this;}	ThisType  operator ++ (int) { ThisType result(getValue()); ++value; assert(isValid()); return result;}	ThisType& operator -- () { -- value  ; assert(isValid()); return *this;}	ThisType  operator -- (int){ ThisType result(getValue()); --value; assert(isValid()); return result;}	    ThisType* clone() const { return static_cast<ThisType*>(INTEGER::clone()); } 	void swap(ThisType& that) { std::swap(value, that.value); }    int_type operator + (const ThisType& rhs) const { int_type t(getValue()); return t+=rhs.getValue();}    int_type operator - (const ThisType& rhs) const { int_type t(getValue()); return t-=rhs.getValue();}    int_type operator * (const ThisType& rhs) const { int_type t(getValue()); return t*=rhs.getValue();}    int_type operator / (const ThisType& rhs) const { int_type t(getValue()); return t/=rhs.getValue();}    friend int_type operator + (int_type lhs, const ThisType& rhs) { int_type t(lhs); return t+=rhs.getValue();}    friend int_type operator - (int_type lhs, const ThisType& rhs) { int_type t(lhs); return t-=rhs.getValue();}    friend int_type operator * (int_type lhs, const ThisType& rhs) { int_type t(lhs); return t*=rhs.getValue();}    friend int_type operator / (int_type lhs, const ThisType& rhs) { int_type t(lhs); return t/=rhs.getValue();}    int_type operator + (int_type rhs) const { int_type t(getValue()); return t+=rhs;}    int_type operator - (int_type rhs) const { int_type t(getValue()); return t-=rhs;}    int_type operator * (int_type rhs) const { int_type t(getValue()); return t*=rhs;}    int_type operator / (int_type rhs) const { int_type t(getValue()); return t/=rhs;}    static const InfoType theInfo;	static bool equal_type(const ASN1::AbstractData& type)	{return type.info() == reinterpret_cast<const ASN1::AbstractData::InfoType*>(&theInfo);}};template <ConstraintType contraint, int lower, unsigned upper >#if defined (__IBMCPP__)// I don't know, why the else-part doesn't work on VAC++5/AiX...const typename ConstrainedObject::InfoType Constrained_INTEGER<contraint, lower, upper>::theInfo = {#elseconst typename Constrained_INTEGER<contraint, lower, upper>::InfoType Constrained_INTEGER<contraint, lower, upper>::theInfo = {#endif //!defined (__IBMCPP__)    &INTEGER::create,    2,      contraint,    lower,    upper};/** Class for ASN Enumerated type.*/class ENUMERATED : public AbstractData, public detail::Allocator<ENUMERATED>{  protected:    ENUMERATED(const void* info);  public:    ENUMERATED(const ENUMERATED& that);      ENUMERATED& operator = (const ENUMERATED& that); 		// ENUMERATED specific methods    int asInt() const { return value; }    void setFromInt(int val) { value = val; }	   	bool isValid() const { return extendable() || isStrictlyValid() ;}	bool isStrictlyValid() const { return value <= getMaximum();}	    int getMaximum() const { return info()->maxEnumValue; }		bool operator == (int rhs) const { return value == rhs; } 	bool operator != (int rhs) const { return value != rhs; } 	bool operator <  (int rhs) const { return value <  rhs; } 	bool operator >  (int rhs) const { return value >  rhs; } 	bool operator <= (int rhs) const { return value <= rhs; } 	bool operator >= (int rhs) const { return value >= rhs; } 	    static AbstractData* create(const void* info);    bool extendable() const { return info()->extendableFlag; }  protected:	struct InfoType	{		CreateFun create;    		unsigned tag;		bool extendableFlag;		unsigned maxEnumValue;		AVN_ONLY(const char** names;)	};		void swap(ENUMERATED& other) { std::swap(value, other.value); }	int value;  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;	const InfoType* info() const { return static_cast<const InfoType*>(info_); } 		#ifdef ASN1_HAS_IOSTREAM  public:	const char* getName() const;	bool setFromName(const std::string&);	const char** names() { return info()->names; }#endif};/** Class for ASN Object Identifier type.*/class OBJECT_IDENTIFIER : public AbstractData, public detail::Allocator<OBJECT_IDENTIFIER>{  protected:    OBJECT_IDENTIFIER(const void* info) : AbstractData(info) {}  public:    OBJECT_IDENTIFIER() : AbstractData(&theInfo) {}#if defined(_MSC_VER) && (_MSC_VER <= 1200)    typedef unsigned* InputIterator;#else    template <class InputIterator>#endif    OBJECT_IDENTIFIER(InputIterator first, InputIterator last, const void* info = &theInfo)      : AbstractData(info),value(first, last)     { }    OBJECT_IDENTIFIER(const OBJECT_IDENTIFIER & other);     OBJECT_IDENTIFIER & operator=(const OBJECT_IDENTIFIER & other) 	{ 		// extensibility and tags are not to be assigned, 		// therefore the parent assignment operator	is not called		value = other.value;		return *this;	}     OBJECT_IDENTIFIER * clone() const { return static_cast<OBJECT_IDENTIFIER*>(do_clone());}    static AbstractData* create(const void* info);	void swap(OBJECT_IDENTIFIER& that) { value.swap(that.value); }	bool isValid() const { return value.size() != 0;} 	bool isStrictlyValid() const { return value.size() != 0;}    unsigned levels() const { return value.size(); }    const unsigned operator[](unsigned idx) const { return value[idx]; }	void append(unsigned arcValue) { value.push_back(arcValue); }	void trim(unsigned levels = 1) { value.erase(value.end()-levels, value.end()); }	template <class InputIterator>	void assign(InputIterator first, InputIterator last)	{	value.assign(first, last); }    bool decodeCommon(const char* data, unsigned dataLen);    void encodeCommon(std::vector<char> & eObjId) const;	// comparison operators	bool operator == (const OBJECT_IDENTIFIER& rhs) const { return value == rhs.value; } 	bool operator != (const OBJECT_IDENTIFIER& rhs) const { return value != rhs.value; } 	bool operator <  (const OBJECT_IDENTIFIER& rhs) const { return value <  rhs.value; } 	bool operator >  (const OBJECT_IDENTIFIER& rhs) const { return value >  rhs.value; } 	bool operator <= (const OBJECT_IDENTIFIER& rhs) const { return value <= rhs.value; } 	bool operator >= (const OBJECT_IDENTIFIER& rhs) const { return value >= rhs.value; }    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;    std::vector<unsigned> value;};/** Class for ASN Bit String type.*/class BIT_STRING : public ConstrainedObject, public detail::Allocator<BIT_STRING>{  protected:    BIT_STRING(const void* info);  public:    BIT_STRING() : ConstrainedObject(&theInfo) {}    BIT_STRING(const BIT_STRING & other);      BIT_STRING & operator=(const BIT_STRING & other) {		bitData = other.bitData;		totalBits = other.totalBits;		return *this;	}	bool isValid() const { return size() >= (unsigned)getLowerLimit() && (getConstraintType() != FixedConstraint || size() <= getUpperLimit()); }	bool isStrictlyValid() const { return size() >= (unsigned)getLowerLimit() && size() <= getUpperLimit(); }     BIT_STRING * clone() const { return static_cast<BIT_STRING*>(do_clone());}    static AbstractData* create(const void* info);	void swap(BIT_STRING& other) {		bitData.swap(other.bitData);		std::swap(totalBits,other.totalBits);	}    unsigned size() const { return totalBits; }    void resize(unsigned nBits) {		bitData.resize((nBits+7)/8);		totalBits = nBits;	}    bool operator[](unsigned bit) const {		if ((unsigned)bit < totalBits)			return (bitData[bit>>3] & (1 << (7 - (bit&7)))) != 0;		return false;	}    void setData(unsigned nBits, const char * buf){        int size = (nBits-1)/8 + 1;		bitData.assign(buf,buf+size);		totalBits = nBits;	}	const std::vector<char>& getData() const{		return bitData;	}    void set(unsigned bit){		if (bit < totalBits)			bitData[(unsigned)(bit>>3)] |= 1 << (7 - (bit&7));	}    void clear(unsigned bit){		if (bit < totalBits)			bitData[(unsigned)(bit>>3)] &= ~(1 << (7 - (bit&7)));	}    void invert(unsigned bit){		if (bit < totalBits)			bitData[(unsigned)(bit>>3)] ^= 1 << (7 - (bit&7));	}	bool operator == (const BIT_STRING& rhs) const { return compare(rhs) == 0; } 	bool operator != (const BIT_STRING& rhs) const { return compare(rhs) != 0; } 	bool operator <  (const BIT_STRING& rhs) const { return compare(rhs) <  0; } 	bool operator >  (const BIT_STRING& rhs) const { return compare(rhs) >  0; } 	bool operator <= (const BIT_STRING& rhs) const { return compare(rhs) <= 0; } 	bool operator >= (const BIT_STRING& rhs) const { return compare(rhs) >= 0; } 	static bool equal_type(const ASN1::AbstractData& type)	{return type.info() == reinterpret_cast<const ASN1::AbstractData::InfoType*>(&theInfo);}        ASN1_EXPORT static const InfoType theInfo;  private:    friend class BERDecoder;    friend class PERDecoder;    friend class AVNDecoder;	virtual int do_compare(const AbstractData& other) const;	virtual AbstractData* do_clone() const ;	virtual bool do_accept(Visitor&);	virtual bool do_accept(ConstVisitor&) const;    unsigned totalBits;    std::vector<char> bitData;};struct EmptyConstraint {    enum {        constraint_type = Unconstrained,        lower_bound = 0,        upper_bound = UINT_MAX    };};template <unsigned TYPE, int LOWERBOUND, unsigned UPPERBOUND>struct SizeConstraint{    enum {        constraint_type = TYPE,        lower_bound = LOWERBOUND,        upper_bound = UPPERBOUND    };};template <class Constraint>class Constrained_BIT_STRING : public BIT_STRING{    typedef BIT_STRING Inherited;protected:    typedef Inherited::InfoType InfoType;    Constrained_BIT_STRING(const void* info) : BIT_STRING(info) {}public:    Constrained_BIT_STRING() : BIT_STRING(&theInfo) {}   // Constrained_BIT_STRING(const Constrained_BIT_STRING & other);  // use default copy constructor    Constrained_BIT_STRING & operator=(const BIT_STRING & other) {		BIT_STRING::operator = (other);		return *this;	}    Constrained_BIT_STRING * clone() const { return static_cast<Constrained_BIT_STRING*>(BIT_STRING::clone());}    static const InfoType theInfo;	static bool equal_type(const ASN1::AbstractData& type)	{return type.info() == reinterpret_cast<const ASN1::AbstractData::InfoType*>(&theInfo);}};template <class Constraint>const typename Constrained_BIT_STRING<Constraint>::InfoType Constrained_BIT_STRING<Constraint>::theInfo = {    BIT_STRING::create,    3,    Constraint::constraint_type,    Constraint::lower_bound,    Constraint::upper_bound};/** Class for ASN Octet String type.*/class OCTET_STRING : public ConstrainedObject, public std::vector<char>, public detail::Allocator<OCTET_STRING>{	typedef std::vector<char> ContainerType;  protected:    OCTET_STRING(const void* info);  public:	typedef ContainerType::value_type value_type;	typedef ContainerType::size_type size_type;	typedef ContainerType::difference_type difference_type;	typedef ContainerType::reference reference;	typedef ContainerType::const_reference const_reference;    OCTET_STRING() : ConstrainedObject(&theInfo) {}	OCTET_STRING(size_type n, char v, const void* info = &theInfo) ;    template <class Itr>    OCTET_STRING(Itr first, Itr last)         : ConstrainedObject(&theInfo),ContainerType(first, last)	    { }	OCTET_STRING(const std::vector<char>& other, const void* info = &theInfo);    OCTET_STRING(const OCTET_STRING & other) ;    OCTET_STRING & operator=(const OCTET_STRING & other)	{		assign(other.begin(), other.end());		return *this;	}	OCTET_STRING & operator = (const std::vector<char>& other) {		assign(other.begin(), other.end());		return *this;	}    OCTET_STRING & operator=(const std::string & str) {		assign(str.begin(), str.end());		return *this;	}    OCTET_STRING & operator=(const char* str) {        assign(str, str+strlen(str));		return *this;    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -