aboutsummaryrefslogtreecommitdiffstats
path: root/doc/examples
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-03-08 15:36:18 +0000
committerlloyd <[email protected]>2010-03-08 15:36:18 +0000
commit8a47f6f2bbf169a2ea0853234f81b49070c770df (patch)
tree2633ed0d927faf23a067aa88d6cceb9de29f0be4 /doc/examples
parent05f6d6c8edec9907778f362c927f368140fee6a2 (diff)
Modify pubkey classes to take names instead of object pointers.
Remove use of look_pk from the source and examples, instead instantiate classes directly.
Diffstat (limited to 'doc/examples')
-rw-r--r--doc/examples/dh.cpp4
-rw-r--r--doc/examples/dsa_sign.cpp4
-rw-r--r--doc/examples/dsa_ver.cpp8
-rw-r--r--doc/examples/ecdsa.cpp14
-rw-r--r--doc/examples/pqg_gen.cpp1
-rw-r--r--doc/examples/rsa_dec.cpp10
-rw-r--r--doc/examples/rsa_enc.cpp9
-rw-r--r--doc/examples/sig_gen.cpp6
8 files changed, 26 insertions, 30 deletions
diff --git a/doc/examples/dh.cpp b/doc/examples/dh.cpp
index 23d6c3952..652c7b136 100644
--- a/doc/examples/dh.cpp
+++ b/doc/examples/dh.cpp
@@ -35,8 +35,8 @@ int main()
// Bob sends his public key to Alice
MemoryVector<byte> public_b = private_b.public_value();
- PK_Key_Agreement ka1(private_a, get_kdf("KDF2(SHA-1)"));
- PK_Key_Agreement ka2(private_b, get_kdf("KDF2(SHA-1)"));
+ PK_Key_Agreement ka1(private_a, "KDF2(SHA-1)");
+ PK_Key_Agreement ka2(private_b, "KDF2(SHA-1)");
/*
* Preferably, include some salt or parameter that binds this key
diff --git a/doc/examples/dsa_sign.cpp b/doc/examples/dsa_sign.cpp
index abc22d0de..ea23907cf 100644
--- a/doc/examples/dsa_sign.cpp
+++ b/doc/examples/dsa_sign.cpp
@@ -12,7 +12,7 @@
#include <memory>
#include <botan/botan.h>
-#include <botan/look_pk.h>
+#include <botan/pubkey.h>
#include <botan/dsa.h>
using namespace Botan;
@@ -62,7 +62,7 @@ int main(int argc, char* argv[])
return 1;
}
- PK_Signer signer(*dsakey, get_emsa("EMSA1(SHA-1)"));
+ PK_Signer signer(*dsakey, "EMSA1(SHA-1)");
DataSource_Stream in(message);
byte buf[4096] = { 0 };
diff --git a/doc/examples/dsa_ver.cpp b/doc/examples/dsa_ver.cpp
index 49d9d9bbc..b30208559 100644
--- a/doc/examples/dsa_ver.cpp
+++ b/doc/examples/dsa_ver.cpp
@@ -21,7 +21,7 @@ signature format, encoded into base64 with a trailing newline.
#include <memory>
#include <botan/botan.h>
-#include <botan/look_pk.h>
+#include <botan/pubkey.h>
#include <botan/dsa.h>
using namespace Botan;
@@ -75,14 +75,14 @@ int main(int argc, char* argv[])
SecureVector<byte> sig = b64_decode(sigstr);
- std::auto_ptr<PK_Verifier> ver(get_pk_verifier(*dsakey, "EMSA1(SHA-1)"));
+ PK_Verifier ver(*dsakey, "EMSA1(SHA-1)");
DataSource_Stream in(message);
byte buf[4096] = { 0 };
while(u32bit got = in.read(buf, sizeof(buf)))
- ver->update(buf, got);
+ ver.update(buf, got);
- bool ok = ver->check_signature(sig);
+ bool ok = ver.check_signature(sig);
if(ok)
std::cout << "Signature verified\n";
diff --git a/doc/examples/ecdsa.cpp b/doc/examples/ecdsa.cpp
index 311a13ad9..df1e1b93a 100644
--- a/doc/examples/ecdsa.cpp
+++ b/doc/examples/ecdsa.cpp
@@ -7,7 +7,6 @@
#include <botan/botan.h>
#include <botan/ecdsa.h>
#include <botan/pubkey.h>
-#include <botan/look_pk.h>
#include <memory>
#include <iostream>
@@ -35,22 +34,21 @@ int main()
std::cout << PKCS8::PEM_encode(ecdsa);
*/
- std::auto_ptr<PK_Signer> signer(get_pk_signer(ecdsa, "EMSA1(SHA-256)"));
+ PK_Signer signer(ecdsa, "EMSA1(SHA-256)");
const char* message = "Hello World";
- signer->update((const byte*)message, strlen(message));
+ signer.update((const byte*)message, strlen(message));
- SecureVector<byte> sig = signer->signature(rng);
+ SecureVector<byte> sig = signer.signature(rng);
std::cout << sig.size() << "\n";
- std::auto_ptr<PK_Verifier> verifier(
- get_pk_verifier(ecdsa_pub, "EMSA1(SHA-256)"));
+ PK_Verifier verifier(ecdsa_pub, "EMSA1(SHA-256)");
- verifier->update((const byte*)message, strlen(message));
+ verifier.update((const byte*)message, strlen(message));
- bool ok = verifier->check_signature(sig);
+ bool ok = verifier.check_signature(sig);
if(ok)
std::cout << "Signature valid\n";
else
diff --git a/doc/examples/pqg_gen.cpp b/doc/examples/pqg_gen.cpp
index e797233f9..c033dac3b 100644
--- a/doc/examples/pqg_gen.cpp
+++ b/doc/examples/pqg_gen.cpp
@@ -13,7 +13,6 @@
#include <botan/botan.h>
#include <botan/auto_rng.h>
-#include <botan/look_pk.h>
#include <botan/dsa.h>
#include <botan/numthry.h>
#include <botan/dl_group.h>
diff --git a/doc/examples/rsa_dec.cpp b/doc/examples/rsa_dec.cpp
index 1e789d748..df681d85b 100644
--- a/doc/examples/rsa_dec.cpp
+++ b/doc/examples/rsa_dec.cpp
@@ -1,5 +1,5 @@
/*
-* (C) 2002 Jack Lloyd
+* (C) 2002-2010 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
@@ -16,7 +16,7 @@ same key format as that generated by rsa_kgen.
#include <memory>
#include <botan/botan.h>
-#include <botan/look_pk.h> // for get_kdf
+#include <botan/pubkey.h>
#include <botan/rsa.h>
using namespace Botan;
@@ -75,9 +75,9 @@ int main(int argc, char* argv[])
SecureVector<byte> enc_masterkey = b64_decode(enc_masterkey_str);
- std::auto_ptr<PK_Decryptor> decryptor(get_pk_decryptor(*rsakey,
- "EME1(SHA-1)"));
- SecureVector<byte> masterkey = decryptor->decrypt(enc_masterkey);
+ PK_Decryptor_MR_with_EME decryptor(*rsakey, "EME1(SHA-1)");
+
+ SecureVector<byte> masterkey = decryptor.decrypt(enc_masterkey);
SymmetricKey cast_key = derive_key("CAST", masterkey, 16);
InitializationVector iv = derive_key("IV", masterkey, 8);
diff --git a/doc/examples/rsa_enc.cpp b/doc/examples/rsa_enc.cpp
index 904b1e379..8ee4df181 100644
--- a/doc/examples/rsa_enc.cpp
+++ b/doc/examples/rsa_enc.cpp
@@ -32,7 +32,7 @@
#include <memory>
#include <botan/botan.h>
-#include <botan/look_pk.h>
+#include <botan/pubkey.h>
#include <botan/rsa.h>
using namespace Botan;
@@ -77,8 +77,7 @@ int main(int argc, char* argv[])
AutoSeeded_RNG rng;
- std::auto_ptr<PK_Encryptor> encryptor(get_pk_encryptor(*rsakey,
- "EME1(SHA-1)"));
+ PK_Encryptor_MR_with_EME encryptor(*rsakey, "EME1(SHA-1)");
/* Generate the master key (the other keys are derived from this)
@@ -92,14 +91,14 @@ int main(int argc, char* argv[])
a problem.
*/
SymmetricKey masterkey(rng,
- std::min(32U, encryptor->maximum_input_size()));
+ std::min(32U, encryptor.maximum_input_size()));
SymmetricKey cast_key = derive_key("CAST", masterkey, 16);
SymmetricKey mac_key = derive_key("MAC", masterkey, 16);
SymmetricKey iv = derive_key("IV", masterkey, 8);
SecureVector<byte> encrypted_key =
- encryptor->encrypt(masterkey.bits_of(), rng);
+ encryptor.encrypt(masterkey.bits_of(), rng);
ciphertext << b64_encode(encrypted_key) << std::endl;
diff --git a/doc/examples/sig_gen.cpp b/doc/examples/sig_gen.cpp
index fca069862..cf273216a 100644
--- a/doc/examples/sig_gen.cpp
+++ b/doc/examples/sig_gen.cpp
@@ -12,8 +12,8 @@
#include <memory>
#include <botan/botan.h>
-#include <botan/look_pk.h>
#include <botan/dsa.h>
+#include <botan/pubkey.h>
using namespace Botan;
bool check(std::map<std::string, std::string>);
@@ -90,7 +90,7 @@ bool check(std::map<std::string, std::string> inputs)
pipe.write(inputs["S"] );
pipe.end_msg();
- std::auto_ptr<PK_Verifier> verify(get_pk_verifier(key, "EMSA1(SHA-1)"));
+ PK_Verifier verifier(key, "EMSA1(SHA-1)");
- return verify->verify_message(pipe.read_all(0), pipe.read_all(1));
+ return verifier.verify_message(pipe.read_all(0), pipe.read_all(1));
}