8#include <botan/asn1_obj.h>
9#include <botan/der_enc.h>
10#include <botan/ber_dec.h>
11#include <botan/internal/bit_ops.h>
12#include <botan/parsing.h>
13#include <botan/oids.h>
22std::vector<uint32_t> parse_oid_str(
const std::string& oid)
27 std::vector<uint32_t> oid_elems;
34 return std::vector<uint32_t>();
45 return std::vector<uint32_t>();
48 if(oid_elems.size() < 2)
49 return std::vector<uint32_t>();
53 catch(Invalid_Argument&)
55 return std::vector<uint32_t>();
71 std::vector<uint32_t> raw = parse_oid_str(str);
74 return OID(std::move(raw));
76 throw Lookup_Error(
"No OID associated with name " + str);
86 m_id = parse_oid_str(oid_str);
88 if(m_id.size() < 2 || m_id[0] > 2)
90 if((m_id[0] == 0 || m_id[0] == 1) && m_id[1] > 39)
100 std::ostringstream oss;
101 oss.imbue(std::locale(
"C"));
102 for(
size_t i = 0; i != m_id.size(); ++i)
105 if(i != m_id.size() - 1)
125 val.push_back(new_component);
126 return OID(std::move(val));
137 return std::lexicographical_compare(oid1.begin(), oid1.end(),
138 oid2.begin(), oid2.end());
149 std::vector<uint8_t> encoding;
151 if(m_id[0] > 2 || m_id[1] >= 40)
154 encoding.push_back(
static_cast<uint8_t
>(40 * m_id[0] + m_id[1]));
156 for(
size_t i = 2; i != m_id.size(); ++i)
159 encoding.push_back(0);
162 size_t blocks =
high_bit(m_id[i]) + 6;
163 blocks = (blocks - (blocks % 7)) / 7;
167 for(
size_t j = 0; j != blocks - 1; ++j)
168 encoding.push_back(0x80 | ((m_id[i] >> 7*(blocks-j-1)) & 0x7F));
169 encoding.push_back(m_id[i] & 0x7F);
184 const size_t length = obj.
length();
185 const uint8_t* bits = obj.
bits();
187 if(length < 2 && !(length == 1 && bits[0] == 0))
193 m_id.push_back(bits[0] / 40);
194 m_id.push_back(bits[0] % 40);
197 while(i != length - 1)
199 uint32_t component = 0;
200 while(i != length - 1)
204 if(component >> (32-7))
207 component = (component << 7) + (bits[i] & 0x7F);
209 if(!(bits[i] & 0x80))
212 m_id.push_back(component);
#define BOTAN_ASSERT(expr, assertion_made)
BER_Object get_next_object()
const uint8_t * bits() const
DER_Encoder & add_object(ASN1_Tag type_tag, ASN1_Tag class_tag, const uint8_t rep[], size_t length)
std::string to_formatted_string() const
const std::vector< uint32_t > & get_components() const
void decode_from(class BER_Decoder &) override
void encode_into(class DER_Encoder &) const override
static OID from_string(const std::string &str)
std::string to_string() const
BOTAN_UNSTABLE_API std::string oid2str_or_empty(const OID &oid)
BOTAN_UNSTABLE_API OID str2oid_or_empty(const std::string &name)
bool operator<(const OID &a, const OID &b)
OID operator+(const OID &oid, uint32_t new_comp)
uint32_t to_u32bit(const std::string &str)