Botan 1.10.17

pk_keys.cpp
Go to the documentation of this file.
1 /*
2 * PK Key Types
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7
8 #include <botan/pk_keys.h>
9 #include <botan/der_enc.h>
10 #include <botan/oids.h>
11
12 namespace Botan {
13
14 /*
15 * Default OID access
16 */
17 OID Public_Key::get_oid() const
18 {
19 try {
20 return OIDS::lookup(algo_name());
21 }
22 catch(Lookup_Error)
23 {
24 throw Lookup_Error("PK algo " + algo_name() + " has no defined OIDs");
25 }
26 }
27
28 /*
29 * Run checks on a loaded public key
30 */
31 void Public_Key::load_check(RandomNumberGenerator& rng) const
32 {
33 if(!check_key(rng, BOTAN_PUBLIC_KEY_STRONG_CHECKS_ON_LOAD))
34 throw Invalid_Argument(algo_name() + ": Invalid public key");
35 }
36
37 /*
38 * Run checks on a loaded private key
39 */
40 void Private_Key::load_check(RandomNumberGenerator& rng) const
41 {
42 if(!check_key(rng, BOTAN_PRIVATE_KEY_STRONG_CHECKS_ON_LOAD))
43 throw Invalid_Argument(algo_name() + ": Invalid private key");
44 }
45
46 /*
47 * Run checks on a generated private key
48 */
49 void Private_Key::gen_check(RandomNumberGenerator& rng) const
50 {
51 if(!check_key(rng, BOTAN_PRIVATE_KEY_STRONG_CHECKS_ON_GENERATE))
52 throw Self_Test_Failure(algo_name() + " private key generation failed");
53 }
54
55 }
Botan::Public_Key::load_check
virtual void load_check(RandomNumberGenerator &rng) const
Definition: pk_keys.cpp:31
Botan::RandomNumberGenerator
Definition: rng.h:20
Botan::Public_Key::check_key
virtual bool check_key(RandomNumberGenerator &rng, bool strong) const =0
Botan::Public_Key::algo_name
virtual std::string algo_name() const =0
Botan::Invalid_Argument
std::invalid_argument Invalid_Argument
Definition: exceptn.h:20
Botan::Public_Key::get_oid
virtual OID get_oid() const
Definition: pk_keys.cpp:17
Botan::Private_Key::gen_check
void gen_check(RandomNumberGenerator &rng) const
Definition: pk_keys.cpp:49
Botan::OIDS::lookup
std::string lookup(const OID &oid)
Definition: oids.cpp:31
Botan::Lookup_Error
Definition: exceptn.h:35
Botan
Definition: algo_base.h:14
Botan::Private_Key::load_check
void load_check(RandomNumberGenerator &rng) const
Definition: pk_keys.cpp:40
Botan::Self_Test_Failure
Definition: exceptn.h:175
Botan::OID
Definition: asn1_oid.h:20