7#ifndef BOTAN_ASN1_OBJECT_TYPES_H_
8#define BOTAN_ASN1_OBJECT_TYPES_H_
10#include <botan/exceptn.h>
11#include <botan/secmem.h>
18#include <unordered_map>
72 return static_cast<uint32_t
>(x) &
static_cast<uint32_t
>(y);
76 return static_cast<ASN1_Type>(
static_cast<uint32_t
>(x) |
static_cast<uint32_t
>(y));
80 return static_cast<ASN1_Class>(
static_cast<uint32_t
>(x) |
static_cast<uint32_t
>(y));
84 return static_cast<uint32_t
>(x) |
static_cast<uint32_t
>(y);
88 return static_cast<uint32_t
>(x) |
static_cast<uint32_t
>(y);
116 std::vector<uint8_t> BER_encode()
const;
139 bool is_set()
const {
return m_type_tag != ASN1_Type::NoObject; }
141 uint32_t
tagging()
const {
return type_tag() | class_tag(); }
151 const uint8_t*
bits()
const {
return m_value.data(); }
153 size_t length()
const {
return m_value.size(); }
155 std::span<const uint8_t>
data()
const {
return std::span{m_value}; }
157 void assert_is_a(
ASN1_Type type_tag,
ASN1_Class class_tag, std::string_view descr =
"object")
const;
161 bool is_a(
int type_tag,
ASN1_Class class_tag)
const;
172 uint8_t* mutable_bits(
size_t length) {
173 m_value.resize(length);
174 return m_value.data();
187std::string
to_string(
const BER_Object& obj);
210 BER_Bad_Tag(std::string_view msg, uint32_t tagging);
229 explicit OID(std::string_view str);
234 explicit OID(std::initializer_list<uint32_t>
init);
246 static
OID from_string(std::string_view str);
252 static std::optional<
OID> from_name(std::string_view
name);
257 static
void register_oid(const
OID& oid, std::string_view
name);
266 bool empty()
const {
return m_id.
empty(); }
278 std::string to_string()
const;
284 std::string to_formatted_string()
const;
290 std::string human_name_or_empty()
const;
296 bool registered_oid()
const;
309 const std::vector<uint32_t>& get_components()
const {
314 const std::vector<uint32_t>& get_id()
const {
319 std::vector<uint32_t> m_id;
360 std::string readable_string()
const;
363 bool time_is_set()
const;
366 int32_t cmp(
const ASN1_Time& other)
const;
372 explicit ASN1_Time(
const std::chrono::system_clock::time_point& time);
381 std::chrono::system_clock::time_point to_std_timepoint()
const;
384 uint64_t time_since_epoch()
const;
387 void set_to(std::string_view t_spec,
ASN1_Type type);
388 bool passes_sanity_check()
const;
391 uint32_t m_month = 0;
394 uint32_t m_minute = 0;
395 uint32_t m_second = 0;
422 const std::string&
value()
const {
return m_utf8_str; }
424 size_t size()
const {
return value().size(); }
426 bool empty()
const {
return m_utf8_str.empty(); }
431 static bool is_string_type(
ASN1_Type tag);
441 std::vector<uint8_t> m_data;
442 std::string m_utf8_str;
466 const std::vector<uint8_t>&
parameters()
const {
return m_parameters; }
470 BOTAN_DEPRECATED(
"Use AlgorithmIdentifier::parameters") const std::vector<uint8_t>& get_parameters()
const {
474 bool parameters_are_null()
const;
480 bool empty()
const {
return m_oid.empty() && m_parameters.empty(); }
484 std::vector<uint8_t> m_parameters;
490BOTAN_PUBLIC_API(2, 0) bool operator==(const AlgorithmIdentifier&, const AlgorithmIdentifier&);
491BOTAN_PUBLIC_API(2, 0)
bool operator!=(const AlgorithmIdentifier&, const AlgorithmIdentifier&);
ASN1_Object & operator=(const ASN1_Object &)=default
ASN1_Object(const ASN1_Object &)=default
virtual ~ASN1_Object()=default
virtual void decode_from(BER_Decoder &from)=0
virtual void encode_into(DER_Encoder &to) const =0
const std::string & value() const
bool operator==(const ASN1_String &other) const
friend bool operator<(const ASN1_String &a, const ASN1_String &b)
ASN1_Type tagging() const
ASN1_Time()=default
Create an invalid ASN1_Time.
bool parameters_are_empty() const
bool parameters_are_null_or_empty() const
const std::vector< uint8_t > & parameters() const
AlgorithmIdentifier()=default
BER_Object(BER_Object &&other)=default
const uint8_t * bits() const
BER_Object & operator=(const BER_Object &other)=default
ASN1_Type type_tag() const
BER_Object(const BER_Object &other)=default
std::span< const uint8_t > data() const
BER_Object & operator=(BER_Object &&other)=default
ASN1_Class get_class() const
ASN1_Class class_tag() const
bool operator==(const OID &other) const
std::string to_string() const
int(* final)(unsigned char *, CTX *)
#define BOTAN_PUBLIC_API(maj, min)
#define BOTAN_UNSTABLE_API
#define BOTAN_DEPRECATED(msg)
std::vector< uint8_t > put_in_sequence(const std::vector< uint8_t > &contents)
bool maybe_BER(DataSource &source)
std::string to_string(const BER_Object &obj)
ASN1_Type operator|(ASN1_Type x, ASN1_Type y)
std::string asn1_tag_to_string(ASN1_Type type)
@ ExplicitContextSpecific
std::ostream & operator<<(std::ostream &out, const OID &oid)
bool operator!=(const AlgorithmIdentifier &a1, const AlgorithmIdentifier &a2)
std::string asn1_class_to_string(ASN1_Class type)
std::vector< T, secure_allocator< T > > secure_vector
bool intersects(ASN1_Class x, ASN1_Class y)
std::string to_string(ErrorType type)
Convert an ErrorType to string.