7 bool StringToArcs(const char * str, size_t length, std::vector<unsigned> & arcs)
12 const char * left = str;
16 while ((left - str) < length)
19 unsigned arc = strtoul(left, &pos, 10);
28 std::vector<unsigned> newArcs(a, a + arcPos);
33 OID::OID(const std::string & str)
35 if (!StringToArcs(str.c_str(), str.length(), arcs))
36 throw std::runtime_error("Invalid oid");
39 OID::OID(const char * str, size_t length)
41 if (!StringToArcs(str, length, arcs))
42 throw std::runtime_error("Invalid oid");
45 OID::OID(const std::vector<unsigned> & a)
50 OID::OID(const unsigned * a, size_t length)
52 std::vector<unsigned> newArcs(a, a + length);
56 OID::OID(OBJECT_IDENTIFIER_t * oid)
59 int count = OBJECT_IDENTIFIER_get_arcs(oid, a, sizeof(a[0]), 1024);
62 throw std::runtime_error("OID is too long");
64 std::vector<unsigned> newArcs(a, a + count);
68 OID::OID(const OID & rvalue)
77 std::string OID::ToString() const
79 std::stringstream stream;
80 for (size_t i = 0; i < arcs.size(); ++i)
81 stream << "." << arcs[i];
85 void OID::ToOID(OBJECT_IDENTIFIER_t * oid) const
87 OBJECT_IDENTIFIER_set_arcs(oid, &arcs.front(), sizeof(unsigned), arcs.size());
90 OID & OID::operator=(const OID & rvalue)
96 bool OID::operator==(const OID & rvalue) const
98 if (arcs.size() != rvalue.arcs.size())
100 for (size_t i = 0; i < arcs.size(); ++i)
101 if (arcs[i] != rvalue.arcs[i])
106 bool OID::operator<(const OID & rvalue) const
108 for (size_t i = 0; i < std::min(arcs.size(), rvalue.arcs.size()); ++i)
109 if (arcs[i] > rvalue.arcs[i])
111 if (rvalue.arcs.size() < arcs.size())
116 std::ostream & operator<<(std::ostream & stream, const OID & oid)
118 for (size_t i = 0; i < oid.arcs.size(); ++i)
119 stream << "." << oid.arcs[i];