📄 asn1.cxx
字号:
{ const OBJECT_IDENTIFIER& that = *boost::polymorphic_downcast<const OBJECT_IDENTIFIER*>(&other); int min_level = std::min(levels(), that.levels()); for (int i = 0; i < min_level; ++i) if (value[i] != that.value[i]) return value[i] - that.value[i]; return levels() - that.levels();}///////////////////////////////////////////////////////////////////////const BIT_STRING::InfoType BIT_STRING::theInfo = { BIT_STRING::create, UniversalTagClass << 16 | UniversalBitString, Unconstrained, 0, UINT_MAX};BIT_STRING::BIT_STRING(const void* info) : ConstrainedObject(info), totalBits(0) {}BIT_STRING::BIT_STRING(const BIT_STRING & other) : ConstrainedObject(other), totalBits(other.totalBits), bitData(other.bitData){}AbstractData* BIT_STRING::create(const void* info){ return new BIT_STRING(info);}bool BIT_STRING::do_accept(Visitor& visitor){ return visitor.visit(*this);}bool BIT_STRING::do_accept(ConstVisitor& visitor) const{ return visitor.visit(*this);}AbstractData* BIT_STRING::do_clone() const{ return new BIT_STRING(*this);}int BIT_STRING::do_compare(const AbstractData& other) const{ const BIT_STRING& that = *boost::polymorphic_downcast<const BIT_STRING*>(&other); int nBytes = std::min(bitData.size(), that.bitData.size()); for (int i = 0 ; i < nBytes; ++i) { char mask = bitData[i] ^ that.bitData[i]; // find the first byte which differs if (mask != 0) return (bitData[i] & mask) - (that.bitData[i] & mask); } return totalBits - that.totalBits;}///////////////////////////////////////////////////////////////////////const OCTET_STRING::InfoType OCTET_STRING::theInfo = { OCTET_STRING::create, UniversalTagClass << 16 | UniversalOctetString, Unconstrained, 0, UINT_MAX};OCTET_STRING::OCTET_STRING(const void* info): ConstrainedObject(info){}OCTET_STRING::OCTET_STRING(size_type n, char v, const void* info) : ConstrainedObject(info), ContainerType(n, v) {}OCTET_STRING::OCTET_STRING(const std::vector<char>& other, const void* info) : ConstrainedObject(info), ContainerType(other) {}OCTET_STRING::OCTET_STRING(const OCTET_STRING & other) : ConstrainedObject(other), ContainerType(other){}AbstractData* OCTET_STRING::create(const void* info){ return new OCTET_STRING(info);}bool OCTET_STRING::do_accept(Visitor& visitor){ return visitor.visit(*this);}bool OCTET_STRING::do_accept(ConstVisitor& visitor) const{ return visitor.visit(*this);}AbstractData * OCTET_STRING::do_clone() const{ return new OCTET_STRING(*this);}int OCTET_STRING::do_compare(const AbstractData& other) const{ const OCTET_STRING& that = *boost::polymorphic_downcast<const OCTET_STRING*>(&other); return lexicographic_compare_bytes(&(*begin()), &(*end()), &(*that.begin()), &(*that.end()));}///////////////////////////////////////////////////////////////////////AbstractString::AbstractString(const AbstractString& other): ConstrainedObject(other.info_), base_string(other){}AbstractString::AbstractString(const void* info): ConstrainedObject(info){ } AbstractString::AbstractString(const void* info, const std::string& str): ConstrainedObject(info), base_string(str) { }AbstractString::AbstractString(const void* info, const char* str): ConstrainedObject(info), base_string(str) {}bool AbstractString::do_accept(Visitor& visitor){ return visitor.visit(*this);}bool AbstractString::do_accept(ConstVisitor& visitor) const{ return visitor.visit(*this);}AbstractData* AbstractString::do_clone() const{ return new AbstractString(*this);}int AbstractString::do_compare(const AbstractData& other) const{ const AbstractString& that = *boost::polymorphic_downcast<const AbstractString*>(&other); return base_string::compare(that);}AbstractData* AbstractString::create(const void* info){ return new AbstractString(info);}/////////////////////////////////////////////////////////////////////////////static const char NumericStringSet[] = " 0123456789";static const char PrintableStringSet[] = " '()+,-./0123456789:=?" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz";static const char VisibleStringSet[] = " !\"#$%&'()*+,-./0123456789:;<=>?" "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_" "`abcdefghijklmnopqrstuvwxyz{|}~";static const char IA5StringSet[] = "\000\001\002\003\004\005\006\007" "\010\011\012\013\014\015\016\017" "\020\021\022\023\024\025\026\027" "\030\031\032\033\034\035\036\037" " !\"#$%&'()*+,-./0123456789:;<=>?" "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_" "`abcdefghijklmnopqrstuvwxyz{|}~\177";static const char GeneralStringSet[] = "\000\001\002\003\004\005\006\007" "\010\011\012\013\014\015\016\017" "\020\021\022\023\024\025\026\027" "\030\031\032\033\034\035\036\037" " !\"#$%&'()*+,-./0123456789:;<=>?" "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_" "`abcdefghijklmnopqrstuvwxyz{|}~\177" "\200\201\202\203\204\205\206\207" "\210\211\212\213\214\215\216\217" "\220\221\222\223\224\225\226\227" "\230\231\232\233\234\235\236\237" "\240\241\242\243\244\245\246\247" "\250\251\252\253\254\255\256\257" "\260\261\262\263\264\265\266\267" "\270\271\272\273\274\275\276\277" "\300\301\302\303\304\305\306\307" "\310\311\312\313\314\315\316\317" "\320\321\322\323\324\325\326\327" "\330\331\332\333\334\335\336\337" "\340\341\342\343\344\345\346\347" "\350\351\352\353\354\355\356\357" "\360\361\362\363\364\365\366\367" "\370\371\372\373\374\375\376\377";const NumericString::InfoType NumericString::theInfo = { AbstractString::create, UniversalTagClass << 16 | UniversalNumericString, Unconstrained, 0, UINT_MAX, NumericStringSet, 11, 4, 4, 4};const PrintableString::InfoType PrintableString::theInfo = { AbstractString::create, UniversalTagClass << 16 | UniversalPrintableString, Unconstrained, 0, UINT_MAX, PrintableStringSet, 74, 7, 7, 8};const VisibleString::InfoType VisibleString::theInfo = { AbstractString::create, UniversalTagClass << 16 | UniversalVisibleString, Unconstrained, 0, UINT_MAX, VisibleStringSet, 95, 7, 7, 8};const IA5String::InfoType IA5String::theInfo = { AbstractString::create, UniversalTagClass << 16 | UniversalIA5String, Unconstrained, 0, UINT_MAX, IA5StringSet, 128, 7, 7, 8};const GeneralString::InfoType GeneralString::theInfo = { AbstractString::create, UniversalTagClass << 16 | UniversalGeneralString, Unconstrained, 0, UINT_MAX, GeneralStringSet, 256, 8, 8, 8};///////////////////////////////////////////////////////////////////////const BMPString::InfoType BMPString::theInfo = { BMPString::create, UniversalTagClass << 16 | UniversalBMPString, Unconstrained, 0, UINT_MAX, 0, 0xffff, 16, 16};BMPString::BMPString(const void* info): ConstrainedObject(info) { }BMPString::BMPString(): ConstrainedObject(&theInfo) { }BMPString::BMPString(const base_string& str, const void* info) : ConstrainedObject(info), base_string(str) { }BMPString::BMPString(const value_type* str, const void* info) : ConstrainedObject(info), base_string(str) { }BMPString::BMPString(const BMPString & other): ConstrainedObject(other), base_string(other){}AbstractData* BMPString::create(const void* info){ return new BMPString(info);}bool BMPString::do_accept(Visitor& visitor){ return visitor.visit(*this);}bool BMPString::do_accept(ConstVisitor& visitor) const{ return visitor.visit(*this);}AbstractData * BMPString::do_clone() const{ return new BMPString(*this);}int BMPString::do_compare(const AbstractData& other) const { const BMPString& that = *boost::polymorphic_downcast<const BMPString*>(&other); return base_string::compare(that);}///////////////////////////////////////////////////////////////////////const GeneralizedTime::InfoType GeneralizedTime::theInfo = { GeneralizedTime::create, UniversalTagClass << 16 | UniversalGeneralisedTime};AbstractData* GeneralizedTime::create(const void* info){ return new GeneralizedTime(info);}GeneralizedTime::GeneralizedTime(const void* info): AbstractData(info), year(1), month(1), day(1), hour(0), minute(0), second(0), millisec(0), mindiff(0), utc(false){}GeneralizedTime::GeneralizedTime(): AbstractData(&theInfo), year(1), month(1), day(1), hour(0), minute(0), second(0), millisec(0), mindiff(0), utc(false){}GeneralizedTime::GeneralizedTime(const char* value) : AbstractData(&theInfo){ set(value); }GeneralizedTime::GeneralizedTime(int yr, int mon, int dy, int hr , int mn, int sc, int ms , int md, bool u ): AbstractData(&theInfo), year(yr), month(mon), day(dy), hour(hr), minute(mn), second(sc), millisec(ms), mindiff(md), utc(u){}GeneralizedTime& GeneralizedTime::operator = (const GeneralizedTime& other ){ year = other.year; month = other.month; day = other.day; hour = other.hour; minute = other.minute; second = other.second; millisec = other.millisec; mindiff = other.mindiff; utc = other.utc; return *this;}GeneralizedTime::GeneralizedTime(const GeneralizedTime& other): AbstractData(other), year(other.year), month(other.month), day(other.day) , hour(other.hour), minute(other.minute), second(other.second), millisec(other.millisec) , mindiff(other.mindiff), utc(other.utc){}void GeneralizedTime::set(const char* valueNotion) { sscanf(valueNotion, "%4d%2d%2d%2d%2d%2d",&year, &month, &day, &hour, &minute, &second); if (valueNotion[14] == '.') { float f; sscanf(&valueNotion[14], "%f",&f); millisec = (int) f*1000; } int len = strlen(valueNotion); int pos = len - 5; if (valueNotion[len-1] == 'Z') utc = true; else if (valueNotion[pos] == '+' || valueNotion[pos] == '-' ) sscanf(&valueNotion[pos], "%d", &mindiff);}std::string GeneralizedTime::get() const { char buf[30]; int len = 14; sprintf(buf, "%04d%02d%02d%02d%02d%02d", year, month, day, hour, minute, second); if (millisec) { sprintf(&buf[14], ".%03d", millisec); len = 18; } if (utc) sprintf(&buf[len], "Z"); else if (mindiff) sprintf(&buf[len], "%+03d%02d", mindiff/60, mindiff%60); return std::string(buf); }bool GeneralizedTime::do_accept(Visitor& visitor){ return visitor.visit(*this);}bool GeneralizedTime::do_accept(ConstVisitor& visitor) const{ return visitor.visit(*this);}void GeneralizedTime::swap(GeneralizedTime& other){ std::swap(year, other.year); std::swap(month, other.month); std::swap(day, other.day); std::swap(hour, other.hour); std::swap(minute, other.minute); std::swap(second, other.second); std::swap(millisec, other.millisec); std::swap(mindiff, other.mindiff); std::swap(utc, other.utc);}int GeneralizedTime::do_compare(const AbstractData& other) const { const GeneralizedTime& that = *boost::polymorphic_downcast<const GeneralizedTime*>(&other); const int* src = &year, *dst = &that.year; for (; src != &mindiff; ++src, ++dst) if (*src != *dst) return *src - *dst; return utc - that.utc;}time_t GeneralizedTime::get_time_t(){ struct tm t; t.tm_year = year-1900; t.tm_mon = month-1; t.tm_mday = day; t.tm_hour = hour; t.tm_min = minute; t.tm_sec = second; return mktime(&t);}void GeneralizedTime::set_time_t(time_t gmt){ struct tm* t = gmtime(&gmt); year = t->tm_year+1900; month = t->tm_mon+1; day = t->tm_mday; hour = t->tm_hour; minute = t->tm_min; second = t->tm_sec;}AbstractData* GeneralizedTime::do_clone() const { return new GeneralizedTime(*this);}///////////////////////////////////////////////////////////////////////AbstractData* CHOICE::create(const void* info){ return new CHOICE(info);}CHOICE::CHOICE(const void* information, int id, AbstractData* value): AbstractData(information), choice(value) , choiceID(id){}CHOICE::CHOICE(const CHOICE & other) : AbstractData(other) , choice( other.choice.get() == NULL ? NULL : other.choice->clone()) , choiceID( other.choiceID){}CHOICE::~CHOICE(){}CHOICE & CHOICE::operator=(const CHOICE & other){ assert(info_ == other.info_); choice.reset(other.choice.get() == NULL ? NULL : other.choice->clone()); choiceID = other.choiceID; return *this;}AbstractData* CHOICE::setSelection(int id, AbstractData* obj){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -