aboutsummaryrefslogtreecommitdiffstats
path: root/src/pk_keys.cpp
blob: 4a175e17cd1adc47ac2917e7ee42ede033cde42a (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
59
60
61
62
63
64
65
66
67
68
/*************************************************
* PK Key Types Source File                       *
* (C) 1999-2006 The Botan Project                *
*************************************************/

#include <botan/pk_keys.h>
#include <botan/config.h>
#include <botan/oids.h>

namespace Botan {

namespace {

/*************************************************
* Find out how much testing should be performed  *
*************************************************/
bool key_check_level(const std::string& type)
   {
   const std::string setting = global_config().option("pk/test/" + type);
   if(setting == "basic")
      return false;
   return true;
   }

}

/*************************************************
* Default OID access                             *
*************************************************/
OID PK_Key::get_oid() const
   {
   try {
      return OIDS::lookup(algo_name());
      }
   catch(Lookup_Error)
      {
      throw Lookup_Error("PK algo " + algo_name() + " has no defined OIDs");
      }
   }

/*************************************************
* Run checks on a loaded public key              *
*************************************************/
void PK_Key::check_loaded_public() const
   {
   if(!check_key(key_check_level("public")))
      throw Invalid_Argument(algo_name() + ": Invalid public key");
   }

/*************************************************
* Run checks on a loaded private key             *
*************************************************/
void PK_Key::check_loaded_private() const
   {
   if(!check_key(key_check_level("private")))
      throw Invalid_Argument(algo_name() + ": Invalid private key");
   }

/*************************************************
* Run checks on a generated private key          *
*************************************************/
void PK_Key::check_generated_private() const
   {
   if(!check_key(key_check_level("private_gen")))
      throw Self_Test_Failure(algo_name() + " private key generation failed");
   }

}