Revision control

Copy as Markdown

Other Tools

/*
* This file was automatically generated by {{ script }} on {{ date }}
*
* 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/internal/oid_map.h>
#include <initializer_list>
#include <unordered_map>
namespace Botan {
namespace {
// The hash can collide so we must verify the actual value matches before returning
std::optional<std::string_view> if_match(const OID& oid, std::initializer_list<uint32_t> val, std::string_view name) {
if(oid.matches(val)) {
return name;
} else {
return {};
}
}
std::optional<OID> if_match(std::string_view req, std::string_view actual, std::initializer_list<uint32_t> oid) {
if(req == actual) {
return OID(oid);
} else {
return {};
}
}
uint32_t hash_oid_name(std::string_view s) {
uint64_t hash = 0x8188B31879A4879A;
for(const char c : s) {
hash *= 251;
hash += c;
}
return static_cast<uint32_t>(hash % 805289);
}
} // namespace
//static
std::optional<std::string_view> OID_Map::lookup_static_oid(const OID& oid) {
const uint32_t hc = static_cast<uint32_t>(oid.hash_code() % 858701);
switch(hc) {
{%- for match in static_oid_data|sort(attribute="oid_hash") %}
case 0x{{ "%05X" % (match.oid_hash) }}:
return if_match(oid, {{ match.oid }}, "{{match.name}}");
{%- endfor %}
default:
return {};
}
}
//static
std::optional<OID> OID_Map::lookup_static_oid_name(std::string_view req) {
const uint32_t hc = hash_oid_name(req);
switch(hc) {
{%- for match in static_oid_data|sort(attribute="name_hash") %}
case 0x{{ "%05X" % (match.name_hash) }}:
return if_match(req, "{{match.name}}", {{ match.oid }});
{%- endfor %}
default:
return {};
}
}
std::unordered_map<OID, std::string> OID_Map::load_oid2str_map() {
return {
{%- for oid in dup_oids %}
{OID{{ oid.oid }}, "{{ oid.name }}"},
{%- endfor %}
};
}
std::unordered_map<std::string, OID> OID_Map::load_str2oid_map() {
return {
{%- for oid in aliases %}
{"{{ oid.name }}", OID{{ oid.oid }}},
{%- endfor %}
};
}
} // namespace Botan