monotone

monotone Mtn Source Tree

Root/botan/oids.cpp

1/*************************************************
2* OID Registry Source File *
3* (C) 1999-2007 The Botan Project *
4*************************************************/
5
6#include <botan/oids.h>
7#include <botan/config.h>
8
9namespace Botan {
10
11namespace OIDS {
12
13/*************************************************
14* Register an OID to string mapping *
15*************************************************/
16void add_oid(const OID& oid, const std::string& name)
17 {
18 const std::string oid_str = oid.as_string();
19
20 if(!global_config().is_set("oid2str", oid_str))
21 global_config().set("oid2str", oid_str, name);
22 if(!global_config().is_set("str2oid", name))
23 global_config().set("str2oid", name, oid_str);
24 }
25
26/*************************************************
27* Do an OID to string lookup *
28*************************************************/
29std::string lookup(const OID& oid)
30 {
31 std::string name = global_config().get("oid2str", oid.as_string());
32 if(name == "")
33 return oid.as_string();
34 return name;
35 }
36
37/*************************************************
38* Do a string to OID lookup *
39*************************************************/
40OID lookup(const std::string& name)
41 {
42 std::string value = global_config().get("str2oid", name);
43 if(value != "")
44 return OID(value);
45
46 try
47 {
48 return OID(name);
49 }
50 catch(Exception)
51 {
52 throw Lookup_Error("No object identifier found for " + name);
53 }
54 }
55
56/*************************************************
57* Check to see if an OID exists in the table *
58*************************************************/
59bool have_oid(const std::string& name)
60 {
61 return global_config().is_set("str2oid", name);
62 }
63
64/*************************************************
65* Check to see if an OID exists in the table *
66*************************************************/
67bool name_of(const OID& oid, const std::string& name)
68 {
69 return (oid == lookup(name));
70 }
71
72}
73
74}

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status