8 bool ParseArcs(const char * str, ptrdiff_t length, unsigned * a, size_t * pos)
12 const char * left = str;
16 while ((left - str) < length)
19 unsigned arc = strtoul(left, &pos, 10);
31 bool StringToArcs(const char * str, size_t length, std::vector<unsigned> & arcs)
36 if (!ParseArcs(str, length, a, &pos))
39 arcs.assign(a, a + pos);
43 bool AppendToArcs(const char * str, size_t length, std::vector<unsigned> & arcs)
48 if (!ParseArcs(str, length, a, &pos))
51 std::copy(&a[0], &a[pos], std::back_inserter(arcs));
55 OID::OID(const std::string & str)
58 if (!StringToArcs(str.c_str(), str.length(), arcs))
59 throw std::runtime_error("Invalid oid");
62 OID::OID(const char * str, size_t length)
65 if (!StringToArcs(str, length, arcs))
66 throw std::runtime_error("Invalid oid");
69 OID::OID(const std::vector<unsigned> & a)
74 OID::OID(const unsigned * a, size_t length)
77 std::vector<unsigned> newArcs(a, a + length);
81 OID::OID(OBJECT_IDENTIFIER_t * oid)
85 int count = OBJECT_IDENTIFIER_get_arcs(oid, a, sizeof(a[0]), 1024);
88 throw std::runtime_error("OID is too long");
90 std::vector<unsigned> newArcs(a, a + count);
94 OID::OID(const OID & rvalue)
103 bool OID::addSuffix(const char * suffix, size_t length)
105 if (!AppendToArcs(suffix, length, arcs))
110 bool OID::addSuffix(const std::string & suffix)
112 if (!AppendToArcs(suffix.c_str(), suffix.length(), arcs))
117 bool OID::addSuffix(const unsigned * suffix, size_t length)
119 std::copy(suffix, suffix + length, std::back_inserter(arcs));
123 bool OID::addSuffix(const std::vector<unsigned> & suffix)
125 std::copy(suffix.begin(), suffix.end(), std::back_inserter(arcs));
129 bool OID::addSuffix(unsigned a, unsigned b)
136 OID OID::copyWithSuffix(const char * suffix, size_t length) const
139 if (!oid.addSuffix(suffix, length))
140 throw std::runtime_error("Invalid suffix");
144 OID OID::copyWithSuffix(const std::string & suffix) const
147 if (!oid.addSuffix(suffix))
148 throw std::runtime_error("Invalid suffix");
152 OID OID::copyWithSuffix(const unsigned * suffix, size_t length) const
155 if (!oid.addSuffix(suffix, length))
156 throw std::runtime_error("Invalid suffix");
160 OID OID::copyWithSuffix(const std::vector<unsigned> & suffix) const
163 if (!oid.addSuffix(suffix))
164 throw std::runtime_error("Invalid suffix");
168 OID OID::copyWithSuffix(unsigned a, unsigned b) const
175 std::string OID::ToString() const
177 std::stringstream stream;
178 for (size_t i = 0; i < arcs.size(); ++i)
179 stream << "." << arcs[i];
183 void OID::ToOID(OBJECT_IDENTIFIER_t * oid) const
185 OBJECT_IDENTIFIER_set_arcs(oid, &arcs.front(), sizeof(unsigned), arcs.size());
188 OID & OID::operator=(const OID & rvalue)
194 bool OID::operator==(const OID & rvalue) const
196 if (arcs.size() != rvalue.arcs.size())
198 for (size_t i = 0; i < arcs.size(); ++i)
199 if (arcs[i] != rvalue.arcs[i])
204 bool OID::operator<(const OID & rvalue) const
207 size_t min = std::min(arcs.size(), rvalue.arcs.size());
209 arcs[i] == rvalue.arcs[i])
213 if (rvalue.arcs.size() > arcs.size())
218 if (arcs[i] < rvalue.arcs[i])
224 bool OID::PrefixLess(const OID & rvalue) const
227 size_t min = std::min(arcs.size(), rvalue.arcs.size());
229 arcs[i] == rvalue.arcs[i])
233 if (arcs[i] < rvalue.arcs[i])
238 std::ostream & operator<<(std::ostream & stream, const OID & oid)
240 for (size_t i = 0; i < oid.arcs.size(); ++i)
241 stream << "." << oid.arcs[i];