aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/x509/x509_dn_ub.cpp
blob: cf8714320e66d2775691f1ce9dd8121486e9be1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* DN_UB maps: Upper bounds on the length of DN strings
*
* This file was automatically generated by ./src/scripts/oids.py on 2017-12-23
*
* All manual edits to this file will be lost. Edit the script
* then regenerate this source file.
*
* Botan is released under the Simplified BSD License (see license.txt)
*/

#include <botan/x509_dn.h>
#include <botan/asn1_oid.h>
#include <map>

namespace {
/**
 * Upper bounds for the length of distinguished name fields as given in RFC 5280, Appendix A.
 * Only OIDS recognized by botan are considered, so far.
 * Maps OID string representations instead of human readable strings in order
 * to avoid an additional lookup.
 */
static const std::map<Botan::OID, size_t> DN_UB =
   {
   { Botan::OID("2.5.4.10"), 64 }, // X520.Organization
   { Botan::OID("2.5.4.11"), 64 }, // X520.OrganizationalUnit
   { Botan::OID("2.5.4.12"), 64 }, // X520.Title
   { Botan::OID("2.5.4.3"), 64 }, // X520.CommonName
   { Botan::OID("2.5.4.4"), 40 }, // X520.Surname
   { Botan::OID("2.5.4.42"), 32768 }, // X520.GivenName
   { Botan::OID("2.5.4.43"), 32768 }, // X520.Initials
   { Botan::OID("2.5.4.44"), 32768 }, // X520.GenerationalQualifier
   { Botan::OID("2.5.4.46"), 64 }, // X520.DNQualifier
   { Botan::OID("2.5.4.5"), 64 }, // X520.SerialNumber
   { Botan::OID("2.5.4.6"), 3 }, // X520.Country
   { Botan::OID("2.5.4.65"), 128 }, // X520.Pseudonym
   { Botan::OID("2.5.4.7"), 128 }, // X520.Locality
   { Botan::OID("2.5.4.8"), 128 } // X520.State
   };
}

namespace Botan {

//static
size_t X509_DN::lookup_ub(const OID& oid)
   {
   auto ub_entry = DN_UB.find(oid);
   if(ub_entry != DN_UB.end())
      {
      return ub_entry->second;
      }
   else
      {
      return 0;
      }
   }
}