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/internal/parsing.h>
13#include <botan/internal/oid_map.h>
14#include <botan/internal/fmt.h>
23std::vector<uint32_t> parse_oid_str(std::string_view oid)
28 std::vector<uint32_t> oid_elems;
35 return std::vector<uint32_t>();
50 catch(Invalid_Argument&)
52 return std::vector<uint32_t>();
72 return std::optional(o);
87 std::vector<uint32_t> raw = parse_oid_str(str);
90 return OID(std::move(raw));
102 m_id = parse_oid_str(oid_str);
103 if(m_id.size() < 2 || m_id[0] > 2 || (m_id[0] < 2 && m_id[1] > 39))
115 std::ostringstream out;
146 return std::lexicographical_compare(oid1.begin(), oid1.end(),
147 oid2.begin(), oid2.end());
154 for(
size_t i = 0; i != val.size(); ++i)
157 out << std::to_string(val[i]);
158 if(i != val.size() - 1)
173 std::vector<uint8_t> encoding;
175 if(m_id[0] > 2 || m_id[1] >= 40)
178 encoding.push_back(
static_cast<uint8_t
>(40 * m_id[0] + m_id[1]));
180 for(
size_t i = 2; i != m_id.size(); ++i)
183 encoding.push_back(0);
186 size_t blocks =
high_bit(m_id[i]) + 6;
187 blocks = (blocks - (blocks % 7)) / 7;
191 for(
size_t j = 0; j != blocks - 1; ++j)
192 encoding.push_back(0x80 | ((m_id[i] >> 7*(blocks-j-1)) & 0x7F));
193 encoding.push_back(m_id[i] & 0x7F);
208 const size_t length = obj.
length();
209 const uint8_t* bits = obj.
bits();
211 if(length < 2 && !(length == 1 && bits[0] == 0))
217 m_id.push_back(bits[0] / 40);
218 m_id.push_back(bits[0] % 40);
221 while(i != length - 1)
223 uint32_t component = 0;
224 while(i != length - 1)
228 if(component >> (32-7))
231 component = (component << 7) + (bits[i] & 0x7F);
233 if(!(bits[i] & 0x80))
236 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_Type type_tag, ASN1_Class class_tag, const uint8_t rep[], size_t length)
std::string oid2str(const OID &oid)
void add_oid(const OID &oid, std::string_view str)
static OID_Map & global_registry()
OID str2oid(std::string_view str)
void encode_into(DER_Encoder &) const override
std::string to_formatted_string() const
bool registered_oid() const
const std::vector< uint32_t > & get_components() const
static std::optional< OID > from_name(std::string_view name)
static void register_oid(const OID &oid, std::string_view name)
std::string human_name_or_empty() const
void decode_from(BER_Decoder &) override
std::string to_string() const
static OID from_string(std::string_view str)
uint32_t to_u32bit(std::string_view str_view)
std::string fmt(std::string_view format, const T &... args)
bool operator<(const OID &a, const OID &b)
constexpr size_t high_bit(T n)
std::ostream & operator<<(std::ostream &out, const OID &oid)