X-Git-Url: https://www.tinc-vpn.org/git/browse?p=fides;a=blobdiff_plain;f=lib%2Fprivatekey.cc;h=e990c2516f75fed89bdc5832b6167b6920eb00f5;hp=4cda7a526f84fb7cd036a010b57089314393542e;hb=f36a11f15b1d75cf3d786cab06fefe0d50812c83;hpb=401e0b5e1d97ded0e2c7415c6dd0f94ee6bfb470 diff --git a/lib/privatekey.cc b/lib/privatekey.cc index 4cda7a5..e990c25 100644 --- a/lib/privatekey.cc +++ b/lib/privatekey.cc @@ -33,8 +33,8 @@ using namespace std; static Botan::AutoSeeded_RNG rng; -namespace fides { - /// \class privatekey +namespace Fides { + /// \class PrivateKey /// /// \brief Representation of a public/private keypair. /// @@ -42,10 +42,10 @@ namespace fides { /// so that others who have the corresponding public key /// can ascertain that the statement was really made by us. - privatekey::privatekey(): priv(0) { + PrivateKey::PrivateKey(): priv(0) { } - privatekey::~privatekey() { + PrivateKey::~PrivateKey() { delete priv; pub = 0; } @@ -53,7 +53,7 @@ namespace fides { /// Generates a new public/private keypair. // /// @param field OID of the field to generate a key in. - void privatekey::generate(const std::string &field) { + void PrivateKey::generate(const std::string &field) { Botan::EC_Domain_Params domain = Botan::get_EC_Dom_Pars_by_oid(field); pub = priv = new Botan::ECDSA_PrivateKey(rng, domain); } @@ -65,7 +65,7 @@ namespace fides { /// Allowed values are 112, 128, 160, 192, 224, 256, 384 and 521. /// Keys less than 160 bits are considered weak. /// Keys greater than 224 bits are considered very strong. - void privatekey::generate(unsigned int bits) { + void PrivateKey::generate(unsigned int bits) { switch(bits) { case 112: return generate("1.3.132.0.6"); case 128: return generate("1.3.132.0.28"); @@ -75,26 +75,26 @@ namespace fides { case 256: return generate("1.3.132.0.10"); case 384: return generate("1.3.132.0.34"); case 521: return generate("1.3.132.0.35"); - default: throw fides::exception("Unsupported number of bits for private key"); + default: throw Fides::exception("Unsupported number of bits for private key"); } } /// Loads a private key from a stream. // /// @param in Stream to read from. - void privatekey::load_private(std::istream &in) { + void PrivateKey::load_private(std::istream &in) { try { Botan::DataSource_Stream stream(in); pub = priv = dynamic_cast(Botan::PKCS8::load_key(stream, rng, "")); } catch(Botan::Exception &e) { - throw fides::exception(e.what()); + throw Fides::exception(e.what()); } } /// Loads a private key from a file. // /// @param filename Name of the file to read from. - void privatekey::load_private(const std::string &filename) { + void PrivateKey::load_private(const std::string &filename) { ifstream in(filename.c_str()); load_private(in); } @@ -102,14 +102,14 @@ namespace fides { /// Saves the private key to a stream. // /// @param out Stream to write to. - void privatekey::save_private(std::ostream &out) const { + void PrivateKey::save_private(std::ostream &out) const { out << Botan::PKCS8::PEM_encode(*priv); } /// Saves the private key to a file. // /// @param filename Name of the file to write to. - void privatekey::save_private(const std::string &filename) const { + void PrivateKey::save_private(const std::string &filename) const { ofstream out(filename.c_str()); save_private(out); } @@ -118,7 +118,7 @@ namespace fides { // /// @param statement The statement that is to be signed. /// @return A string containing the signature. - string privatekey::sign(const std::string &statement) const { + string PrivateKey::sign(const std::string &statement) const { auto_ptr signer(Botan::get_pk_signer(*priv, "EMSA1(SHA-512)")); Botan::SecureVector sig = signer->sign_message((const Botan::byte *)statement.data(), statement.size(), rng); return string((const char *)sig.begin(), (size_t)sig.size());