11 bool ParseArcs(const char * str, ptrdiff_t length, unsigned * a, size_t * pos);
12 bool StringToArcs(const char * str, size_t length, std::vector<unsigned> & arcs);
13 bool AppendToArcs(const char * str, size_t length, std::vector<unsigned> & arcs);
15 bool ParseArcs(const char * str, ptrdiff_t length, unsigned * a, size_t * pos)
19 const char * left = str;
23 while ((left - str) < length)
26 unsigned arc = static_cast<unsigned int>(strtoul(left, &pos, 10));
38 bool StringToArcs(const char * str, size_t length, std::vector<unsigned> & arcs)
43 if (!ParseArcs(str, length, a, &pos))
46 arcs.assign(a, a + pos);
50 bool AppendToArcs(const char * str, size_t length, std::vector<unsigned> & arcs)
55 if (!ParseArcs(str, length, a, &pos))
58 std::copy(&a[0], &a[pos], std::back_inserter(arcs));
64 OID::OID(const std::string & str)
67 if (!StringToArcs(str.c_str(), str.length(), arcs))
68 throw std::runtime_error("Invalid oid");
71 OID::OID(const char * str, size_t length)
74 if (!StringToArcs(str, length, arcs))
75 throw std::runtime_error("Invalid oid");
78 OID::OID(const std::vector<unsigned> & a)
83 OID::OID(const unsigned * a, size_t length)
86 std::vector<unsigned> newArcs(a, a + length);
90 OID::OID(OBJECT_IDENTIFIER_t * oid)
94 int count = OBJECT_IDENTIFIER_get_arcs(oid, a, sizeof(a[0]), 1024);
97 throw std::runtime_error("OID is too long");
99 std::vector<unsigned> newArcs(a, a + count);
103 OID::OID(const OID & rvalue)
112 bool OID::addSuffix(const char * suffix, size_t length)
114 if (!AppendToArcs(suffix, length, arcs))
119 bool OID::addSuffix(const std::string & suffix)
121 if (!AppendToArcs(suffix.c_str(), suffix.length(), arcs))
126 bool OID::addSuffix(const unsigned * suffix, size_t length)
128 std::copy(suffix, suffix + length, std::back_inserter(arcs));
132 bool OID::addSuffix(const std::vector<unsigned> & suffix)
134 std::copy(suffix.begin(), suffix.end(), std::back_inserter(arcs));
138 bool OID::addSuffix(unsigned a, unsigned b)
145 OID OID::copyWithSuffix(const char * suffix, size_t length) const
148 if (!oid.addSuffix(suffix, length))
149 throw std::runtime_error("Invalid suffix");
153 OID OID::copyWithSuffix(const std::string & suffix) const
156 if (!oid.addSuffix(suffix))
157 throw std::runtime_error("Invalid suffix");
161 OID OID::copyWithSuffix(const unsigned * suffix, size_t length) const
164 if (!oid.addSuffix(suffix, length))
165 throw std::runtime_error("Invalid suffix");
169 OID OID::copyWithSuffix(const std::vector<unsigned> & suffix) const
172 if (!oid.addSuffix(suffix))
173 throw std::runtime_error("Invalid suffix");
177 OID OID::copyWithSuffix(unsigned a, unsigned b) const
184 std::string OID::ToString() const
186 std::stringstream stream;
187 for (size_t i = 0; i < arcs.size(); ++i)
188 stream << "." << arcs[i];
192 void OID::ToOID(OBJECT_IDENTIFIER_t * oid) const
194 OBJECT_IDENTIFIER_set_arcs(oid, &arcs.front(), sizeof(unsigned), static_cast<unsigned int>(arcs.size()));
197 OID & OID::operator=(const OID & rvalue)
203 bool OID::operator==(const OID & rvalue) const
205 if (arcs.size() != rvalue.arcs.size())
207 for (size_t i = 0; i < arcs.size(); ++i)
208 if (arcs[i] != rvalue.arcs[i])
213 bool OID::operator<(const OID & rvalue) const
216 size_t min = std::min(arcs.size(), rvalue.arcs.size());
218 arcs[i] == rvalue.arcs[i])
222 if (rvalue.arcs.size() > arcs.size())
227 if (arcs[i] < rvalue.arcs[i])
233 bool OID::PrefixLess(const OID & rvalue) const
236 size_t min = std::min(arcs.size(), rvalue.arcs.size());
238 arcs[i] == rvalue.arcs[i])
242 if (arcs[i] < rvalue.arcs[i])
247 std::ostream & operator<<(std::ostream & stream, const OID & oid)
249 for (size_t i = 0; i < oid.arcs.size(); ++i)
250 stream << "." << oid.arcs[i];