/* * 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 #include #include namespace Botan { namespace { // The hash can collide so we must verify the actual value matches before returning std::optional if_match(const OID& oid, std::initializer_list val, std::string_view name) { if(oid.matches(val)) { return name; } else { return {}; } } std::optional if_match(std::string_view req, std::string_view actual, std::initializer_list 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(hash % 805289); } } // namespace //static std::optional OID_Map::lookup_static_oid(const OID& oid) { const uint32_t hc = static_cast(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_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_Map::load_oid2str_map() { return { {%- for oid in dup_oids %} {OID{{ oid.oid }}, "{{ oid.name }}"}, {%- endfor %} }; } std::unordered_map OID_Map::load_str2oid_map() { return { {%- for oid in aliases %} {"{{ oid.name }}", OID{{ oid.oid }}}, {%- endfor %} }; } } // namespace Botan