/src/botan/build/include/botan/x509_dn.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * X.509 Distinguished Name |
3 | | * (C) 1999-2010,2018 Jack Lloyd |
4 | | * (C) 2017 Fabian Weissberg, Rohde & Schwarz Cybersecurity |
5 | | * |
6 | | * Botan is released under the Simplified BSD License (see license.txt) |
7 | | */ |
8 | | |
9 | | #ifndef BOTAN_X509_DN_H_ |
10 | | #define BOTAN_X509_DN_H_ |
11 | | |
12 | | #include <botan/asn1_obj.h> |
13 | | #include <botan/asn1_oid.h> |
14 | | #include <botan/asn1_str.h> |
15 | | #include <vector> |
16 | | #include <map> |
17 | | #include <iosfwd> |
18 | | |
19 | | namespace Botan { |
20 | | |
21 | | /** |
22 | | * Distinguished Name |
23 | | */ |
24 | | class BOTAN_PUBLIC_API(2,0) X509_DN final : public ASN1_Object |
25 | | { |
26 | | public: |
27 | 45.2k | X509_DN() = default; |
28 | | |
29 | | explicit X509_DN(const std::multimap<OID, std::string>& args) |
30 | 0 | { |
31 | 0 | for(auto i : args) |
32 | 0 | add_attribute(i.first, i.second); |
33 | 0 | } |
34 | | |
35 | | explicit X509_DN(const std::multimap<std::string, std::string>& args) |
36 | 0 | { |
37 | 0 | for(auto i : args) |
38 | 0 | add_attribute(i.first, i.second); |
39 | 0 | } |
40 | | |
41 | | void encode_into(class DER_Encoder&) const override; |
42 | | void decode_from(class BER_Decoder&) override; |
43 | | |
44 | | bool has_field(const OID& oid) const; |
45 | | ASN1_String get_first_attribute(const OID& oid) const; |
46 | | |
47 | | /* |
48 | | * Return the BER encoded data, if any |
49 | | */ |
50 | 26.2k | const std::vector<uint8_t>& get_bits() const { return m_dn_bits; } |
51 | | |
52 | 0 | bool empty() const { return m_rdn.empty(); } |
53 | | |
54 | | std::string to_string() const; |
55 | | |
56 | 3.59k | const std::vector<std::pair<OID,ASN1_String>>& dn_info() const { return m_rdn; } |
57 | | |
58 | | std::multimap<OID, std::string> get_attributes() const; |
59 | | std::multimap<std::string, std::string> contents() const; |
60 | | |
61 | | bool has_field(const std::string& attr) const; |
62 | | std::vector<std::string> get_attribute(const std::string& attr) const; |
63 | | std::string get_first_attribute(const std::string& attr) const; |
64 | | |
65 | | void add_attribute(const std::string& key, const std::string& val); |
66 | | |
67 | | void add_attribute(const OID& oid, const std::string& val) |
68 | 0 | { |
69 | 0 | add_attribute(oid, ASN1_String(val)); |
70 | 0 | } |
71 | | |
72 | | void add_attribute(const OID& oid, const ASN1_String& val); |
73 | | |
74 | | static std::string deref_info_field(const std::string& key); |
75 | | |
76 | | /** |
77 | | * Lookup upper bounds in characters for the length of distinguished name fields |
78 | | * as given in RFC 5280, Appendix A. |
79 | | * |
80 | | * @param oid the oid of the DN to lookup |
81 | | * @return the upper bound, or zero if no ub is known to Botan |
82 | | */ |
83 | | static size_t lookup_ub(const OID& oid); |
84 | | |
85 | | private: |
86 | | std::vector<std::pair<OID,ASN1_String>> m_rdn; |
87 | | std::vector<uint8_t> m_dn_bits; |
88 | | }; |
89 | | |
90 | | bool BOTAN_PUBLIC_API(2,0) operator==(const X509_DN& dn1, const X509_DN& dn2); |
91 | | bool BOTAN_PUBLIC_API(2,0) operator!=(const X509_DN& dn1, const X509_DN& dn2); |
92 | | |
93 | | /* |
94 | | The ordering here is arbitrary and may change from release to release. |
95 | | It is intended for allowing DNs as keys in std::map and similiar containers |
96 | | */ |
97 | | bool BOTAN_PUBLIC_API(2,0) operator<(const X509_DN& dn1, const X509_DN& dn2); |
98 | | |
99 | | BOTAN_PUBLIC_API(2,0) std::ostream& operator<<(std::ostream& out, const X509_DN& dn); |
100 | | BOTAN_PUBLIC_API(2,0) std::istream& operator>>(std::istream& in, X509_DN& dn); |
101 | | |
102 | | } |
103 | | |
104 | | #endif |