Botan  2.4.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 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 <map>
16 #include <iosfwd>
17 
18 namespace Botan {
19 
20 /**
21 * Distinguished Name
22 */
23 class BOTAN_PUBLIC_API(2,0) X509_DN final : public ASN1_Object
24  {
25  public:
26  void encode_into(class DER_Encoder&) const override;
27  void decode_from(class BER_Decoder&) override;
28 
29  bool has_field(const std::string& attr) const;
30  std::vector<std::string> get_attribute(const std::string& attr) const;
31 
32  std::string get_first_attribute(const std::string& attr) const;
33 
34  std::multimap<OID, std::string> get_attributes() const;
35  std::multimap<std::string, std::string> contents() const;
36 
37  void add_attribute(const std::string& key, const std::string& val);
38  void add_attribute(const OID& oid, const std::string& val);
39 
40  static std::string deref_info_field(const std::string& key);
41 
42  /**
43  * Lookup upper bounds in characters for the length of distinguished name fields
44  * as given in RFC 5280, Appendix A.
45  *
46  * @param oid the oid of the DN to lookup
47  * @return the upper bound, or zero if no ub is known to Botan
48  */
49  static size_t lookup_ub(const OID& oid);
50 
51  /*
52  * Return the BER encoded data, if any
53  */
54  const std::vector<uint8_t>& get_bits() const;
55 
56  bool empty() const { return m_dn_info.empty(); }
57 
58  X509_DN() = default;
59  explicit X509_DN(const std::multimap<OID, std::string>& vals);
60  explicit X509_DN(const std::multimap<std::string, std::string>& vals);
61  private:
62  std::multimap<OID, ASN1_String> m_dn_info;
63  std::vector<uint8_t> m_dn_bits;
64  };
65 
66 bool BOTAN_PUBLIC_API(2,0) operator==(const X509_DN&, const X509_DN&);
67 bool BOTAN_PUBLIC_API(2,0) operator!=(const X509_DN&, const X509_DN&);
68 bool BOTAN_PUBLIC_API(2,0) operator<(const X509_DN&, const X509_DN&);
69 
70 BOTAN_PUBLIC_API(2,0) std::ostream& operator<<(std::ostream& out, const X509_DN& dn);
71 BOTAN_PUBLIC_API(2,0) std::istream& operator>>(std::istream& in, X509_DN& dn);
72 
73 }
74 
75 #endif
bool operator!=(const AlgorithmIdentifier &a1, const AlgorithmIdentifier &a2)
Definition: alg_id.cpp:90
int operator<<(int fd, Pipe &pipe)
Definition: fd_unix.cpp:17
bool empty() const
Definition: x509_dn.h:56
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
bool operator<(const OID &a, const OID &b)
Definition: asn1_oid.cpp:105
Definition: alg_id.cpp:13
int operator>>(int fd, Pipe &pipe)
Definition: fd_unix.cpp:40
bool operator==(const AlgorithmIdentifier &a1, const AlgorithmIdentifier &a2)
Definition: alg_id.cpp:75