1
/*************************************************
2
* PK Key Types Source File *
3
* (C) 1999-2007 The Botan Project *
4
*************************************************/
6
#include <botan/pk_keys.h>
7
#include <botan/config.h>
8
#include <botan/oids.h>
14
/*************************************************
15
* Find out how much testing should be performed *
16
*************************************************/
17
bool key_check_level(const std::string& type)
19
const std::string setting = global_config().option("pk/test/" + type);
20
if(setting == "basic")
27
/*************************************************
28
* Default OID access *
29
*************************************************/
30
OID Public_Key::get_oid() const
33
return OIDS::lookup(algo_name());
37
throw Lookup_Error("PK algo " + algo_name() + " has no defined OIDs");
41
/*************************************************
42
* Run checks on a loaded public key *
43
*************************************************/
44
void Public_Key::load_check() const
46
if(!check_key(key_check_level("public")))
47
throw Invalid_Argument(algo_name() + ": Invalid public key");
50
/*************************************************
51
* Run checks on a loaded private key *
52
*************************************************/
53
void Private_Key::load_check() const
55
if(!check_key(key_check_level("private")))
56
throw Invalid_Argument(algo_name() + ": Invalid private key");
59
/*************************************************
60
* Run checks on a generated private key *
61
*************************************************/
62
void Private_Key::gen_check() const
64
if(!check_key(key_check_level("private_gen")))
65
throw Self_Test_Failure(algo_name() + " private key generation failed");