Botan  2.6.0
Crypto and TLS for C++11
x509_dn.h
Go to the documentation of this file.
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  X509_DN() = default;
28 
29  explicit X509_DN(const std::multimap<OID, std::string>& args)
30  {
31  for(auto i : args)
32  add_attribute(i.first, i.second);
33  }
34 
35  explicit X509_DN(const std::multimap<std::string, std::string>& args)
36  {
37  for(auto i : args)
38  add_attribute(i.first, i.second);
39  }
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  const std::vector<uint8_t>& get_bits() const { return m_dn_bits; }
51 
52  bool empty() const { return m_rdn.empty(); }
53 
54  const std::vector<std::pair<OID,ASN1_String>>& dn_info() const { return m_rdn; }
55 
56  std::multimap<OID, std::string> get_attributes() const;
57  std::multimap<std::string, std::string> contents() const;
58 
59  bool has_field(const std::string& attr) const;
60  std::vector<std::string> get_attribute(const std::string& attr) const;
61  std::string get_first_attribute(const std::string& attr) const;
62 
63  void add_attribute(const std::string& key, const std::string& val);
64 
65  void add_attribute(const OID& oid, const std::string& val)
66  {
67  add_attribute(oid, ASN1_String(val));
68  }
69 
70  void add_attribute(const OID& oid, const ASN1_String& val);
71 
72  static std::string deref_info_field(const std::string& key);
73 
74  /**
75  * Lookup upper bounds in characters for the length of distinguished name fields
76  * as given in RFC 5280, Appendix A.
77  *
78  * @param oid the oid of the DN to lookup
79  * @return the upper bound, or zero if no ub is known to Botan
80  */
81  static size_t lookup_ub(const OID& oid);
82 
83  private:
84  std::vector<std::pair<OID,ASN1_String>> m_rdn;
85  std::vector<uint8_t> m_dn_bits;
86  };
87 
88 bool BOTAN_PUBLIC_API(2,0) operator==(const X509_DN&, const X509_DN&);
89 bool BOTAN_PUBLIC_API(2,0) operator!=(const X509_DN&, const X509_DN&);
90 bool BOTAN_PUBLIC_API(2,0) operator<(const X509_DN&, const X509_DN&);
91 
92 BOTAN_PUBLIC_API(2,0) std::ostream& operator<<(std::ostream& out, const X509_DN& dn);
93 BOTAN_PUBLIC_API(2,0) std::istream& operator>>(std::istream& in, X509_DN& dn);
94 
95 }
96 
97 #endif
const std::vector< uint8_t > & get_bits() const
Definition: x509_dn.h:50
bool empty() const
Definition: x509_dn.h:52
const std::vector< std::pair< OID, ASN1_String > > & dn_info() const
Definition: x509_dn.h:54
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
Definition: bigint.h:719
X509_DN(const std::multimap< std::string, std::string > &args)
Definition: x509_dn.h:35
Definition: alg_id.cpp:13
X509_DN(const std::multimap< OID, std::string > &args)
Definition: x509_dn.h:29
void add_attribute(const OID &oid, const std::string &val)
Definition: x509_dn.h:65