8#include <botan/pkix_types.h>
10#include <botan/ber_dec.h>
11#include <botan/x509cert.h>
12#include <botan/internal/loadstor.h>
13#include <botan/internal/parsing.h>
22 size_t p = str.find(
':');
24 if(p != std::string::npos) {
25 m_type = str.substr(0, p);
26 m_name = str.substr(p + 1, std::string::npos);
63 }
else if(obj.
length() == 32) {
74 std::vector<std::string> nam;
75 std::function<bool(
const GeneralName*,
const std::string&)> match_fn;
81 match_fn = std::mem_fn(&GeneralName::matches_dns);
88 }
else if(
type() ==
"DN") {
89 match_fn = std::mem_fn(&GeneralName::matches_dn);
93 const auto alt_dn = alt_name.
dn();
94 if(alt_dn.empty() ==
false) {
95 nam.push_back(alt_dn.to_string());
97 }
else if(
type() ==
"IP") {
98 match_fn = std::mem_fn(&GeneralName::matches_ip);
111 for(
const std::string& n : nam) {
112 bool m = match_fn(
this, n);
127bool GeneralName::matches_dns(
const std::string& nam)
const {
128 if(nam.size() ==
name().size()) {
130 }
else if(
name().size() > nam.size()) {
136 const std::string constr =
name().front() ==
'.' ?
name() :
"." +
name();
137 const std::string substr = nam.substr(nam.size() - constr.size(), constr.size());
142bool GeneralName::matches_dn(
const std::string& nam)
const {
143 std::stringstream ss(nam);
144 std::stringstream tt(
name());
145 X509_DN nam_dn, my_dn;
150 auto attr = nam_dn.get_attributes();
154 for(
const auto& c : my_dn.dn_info()) {
155 auto i = attr.equal_range(c.first);
157 if(i.first != i.second) {
159 ret = ret && (i.first->second == c.second.value());
163 return trys > 0 && ret;
166bool GeneralName::matches_ip(
const std::string& nam)
const {
171 throw Decoding_Error(
"failed to parse IPv4 address");
177 return (ip & mask) == net;
181 os << gn.
type() <<
":" << gn.
name();
187 const auto min = std::stoull(str, &p0, 10);
188 const auto max = std::stoull(str.substr(p0 + 1), &p1, 10);
191 if(p0 > 0 && p1 > 0) {
192 m_minimum =
static_cast<size_t>(min);
193 m_maximum =
static_cast<size_t>(max);
214 m_maximum = std::numeric_limits<std::size_t>::max();
std::vector< std::string > get_attribute(std::string_view attr) const
BER_Object get_next_object()
BER_Decoder & decode(bool &out)
BER_Decoder start_sequence()
BER_Decoder & decode_optional(T &out, ASN1_Type type_tag, ASN1_Class class_tag, const T &default_value=T())
const uint8_t * bits() const
bool is_a(ASN1_Type type_tag, ASN1_Class class_tag) const
const std::string & type() const
void encode_into(DER_Encoder &) const override
MatchResult matches(const X509_Certificate &cert) const
void decode_from(BER_Decoder &) override
const std::string & name() const
A single Name Constraint.
void decode_from(BER_Decoder &) override
const GeneralName & base() const
void encode_into(DER_Encoder &) const override
const X509_DN & subject_dn() const
const AlternativeName & subject_alt_name() const
void decode_from(BER_Decoder &) override
std::vector< std::string > get_attribute(std::string_view attr) const
std::string to_string() const
std::string to_string(const BER_Object &obj)
uint32_t string_to_ipv4(std::string_view str)
std::vector< std::string > split_on(std::string_view str, char delim)
std::string tolower_string(std::string_view in)
std::ostream & operator<<(std::ostream &out, const OID &oid)
constexpr uint32_t load_be< uint32_t >(const uint8_t in[], size_t off)
std::string ipv4_to_string(uint32_t ip)