8#include <botan/asn1_obj.h>
10#include <botan/ber_dec.h>
11#include <botan/der_enc.h>
12#include <botan/internal/bit_ops.h>
13#include <botan/internal/fmt.h>
14#include <botan/internal/oid_map.h>
15#include <botan/internal/parsing.h>
24std::vector<uint32_t> parse_oid_str(std::string_view oid) {
27 std::vector<uint32_t> oid_elems;
32 return std::vector<uint32_t>();
46 }
catch(Invalid_Argument&)
48 return std::vector<uint32_t>();
67 return std::optional(o);
84 std::vector<uint32_t> raw = parse_oid_str(str);
87 return OID(std::move(raw));
97 if(!oid_str.empty()) {
98 m_id = parse_oid_str(oid_str);
99 if(m_id.size() < 2 || m_id[0] > 2 || (m_id[0] < 2 && m_id[1] > 39)) {
109 std::ostringstream out;
137 return std::lexicographical_compare(oid1.begin(), oid1.end(), oid2.begin(), oid2.end());
143 for(
size_t i = 0; i != val.size(); ++i) {
145 out << std::to_string(val[i]);
146 if(i != val.size() - 1) {
158 if(m_id.size() < 2) {
162 std::vector<uint8_t> encoding;
164 if(m_id[0] > 2 || m_id[1] >= 40) {
168 encoding.push_back(
static_cast<uint8_t
>(40 * m_id[0] + m_id[1]));
170 for(
size_t i = 2; i != m_id.size(); ++i) {
172 encoding.push_back(0);
174 size_t blocks =
high_bit(m_id[i]) + 6;
175 blocks = (blocks - (blocks % 7)) / 7;
179 for(
size_t j = 0; j != blocks - 1; ++j) {
180 encoding.push_back(0x80 | ((m_id[i] >> 7 * (blocks - j - 1)) & 0x7F));
182 encoding.push_back(m_id[i] & 0x7F);
197 const size_t length = obj.
length();
198 const uint8_t* bits = obj.
bits();
200 if(length < 2 && !(length == 1 && bits[0] == 0)) {
205 m_id.push_back(bits[0] / 40);
206 m_id.push_back(bits[0] % 40);
209 while(i != length - 1) {
210 uint32_t component = 0;
211 while(i != length - 1) {
214 if(component >> (32 - 7)) {
218 component = (component << 7) + (bits[i] & 0x7F);
220 if(!(bits[i] & 0x80)) {
224 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)