aboutsummaryrefslogtreecommitdiffstats
path: root/doc/examples
diff options
context:
space:
mode:
authorlloyd <[email protected]>2012-05-31 21:34:07 +0000
committerlloyd <[email protected]>2012-05-31 21:34:07 +0000
commit63defdde855dca51d5db405cb97d9b7c9ba09332 (patch)
tree3305d2e65440007ab9f1b4fd2cc1f57aba61ee44 /doc/examples
parent149a855bd7b090eb3868efff272e455e568eade4 (diff)
Various examples fixes, most notable updating cert_verify to the new API
Diffstat (limited to 'doc/examples')
-rw-r--r--doc/examples/GNUmakefile2
-rw-r--r--doc/examples/cert_verify.cpp33
-rw-r--r--doc/examples/dsa_kgen.cpp3
-rw-r--r--doc/examples/pqg_gen.cpp2
-rw-r--r--doc/examples/rng_test.cpp2
5 files changed, 26 insertions, 16 deletions
diff --git a/doc/examples/GNUmakefile b/doc/examples/GNUmakefile
index c342b4cb2..e61c31b0a 100644
--- a/doc/examples/GNUmakefile
+++ b/doc/examples/GNUmakefile
@@ -2,7 +2,7 @@
BOTAN_CONFIG = botan-config
CXX = g++-4.7.0
-CFLAGS = -O2 -ansi -std=c++0x -W -Wall -I../../build/include
+CFLAGS = -O0 -g -ansi -std=c++11 -W -Wall -I../../build/include
LIBS = -L../.. -lbotan-1.11
SRCS=$(wildcard *.cpp)
diff --git a/doc/examples/cert_verify.cpp b/doc/examples/cert_verify.cpp
index 04bcbecad..d9b170ef0 100644
--- a/doc/examples/cert_verify.cpp
+++ b/doc/examples/cert_verify.cpp
@@ -7,29 +7,38 @@
#include <botan/botan.h>
#include <botan/x509cert.h>
-#include <botan/x509stor.h>
-
-#include <stdio.h>
+#include <botan/x509path.h>
+#include <iostream>
using namespace Botan;
-int main()
+int main(int argc, char* argv[])
{
+ if(argc <= 2)
+ {
+ std::cout << "Usage: " << argv[0] << " subject.pem [CA certificates...]\n";
+ return 1;
+ }
+
LibraryInitializer init;
+ X509_Certificate subject_cert(argv[1]);
- X509_Certificate ca_cert("ca_cert.pem");
- X509_Certificate subject_cert("http_cert.pem");
+ Certificate_Store_In_Memory certs;
- X509_Store cert_store;
+ for(size_t i = 2; argv[i]; ++i)
+ certs.add_certificate(X509_Certificate(argv[i]));
- cert_store.add_cert(ca_cert, /*trusted=*/true);
+ Path_Validation_Restrictions restrictions;
- X509_Code code = cert_store.validate_cert(subject_cert);
+ Path_Validation_Result result =
+ x509_path_validate(subject_cert,
+ restrictions,
+ certs);
- if(code == VERIFIED)
- printf("Cert validated\n");
+ if(result.successful_validation())
+ std::cout << "Certificate validated\n";
else
- printf("Cert did not validate, code = %d\n", code);
+ std::cout << "Certificate did not validate - " << result.result_string() << "\n";
return 0;
}
diff --git a/doc/examples/dsa_kgen.cpp b/doc/examples/dsa_kgen.cpp
index fc5b7b501..f68b20834 100644
--- a/doc/examples/dsa_kgen.cpp
+++ b/doc/examples/dsa_kgen.cpp
@@ -30,7 +30,8 @@ int main(int argc, char* argv[])
AutoSeeded_RNG rng;
- DL_Group group(rng, DL_Group::DSA_Kosherizer, 2048, 256);
+ //DL_Group group(rng, DL_Group::DSA_Kosherizer, 2048, 256);
+ DL_Group group("dsa/jce/1024");
DSA_PrivateKey key(rng, group);
diff --git a/doc/examples/pqg_gen.cpp b/doc/examples/pqg_gen.cpp
index b24c30844..c272f793e 100644
--- a/doc/examples/pqg_gen.cpp
+++ b/doc/examples/pqg_gen.cpp
@@ -94,7 +94,7 @@ bool check(RandomNumberGenerator& rng,
//u32bit c = to_u32bit(inputs["c"]);
- std::vector<byte> seed = unlock(hex_decode(inputs["Seed"]));
+ std::vector<byte> seed = hex_decode(inputs["Seed"]);
BigInt our_p, our_q;
diff --git a/doc/examples/rng_test.cpp b/doc/examples/rng_test.cpp
index 385ac57f3..a6ee6da78 100644
--- a/doc/examples/rng_test.cpp
+++ b/doc/examples/rng_test.cpp
@@ -68,7 +68,7 @@ void x931_tests(std::vector<std::pair<std::string, std::string> > vecs,
ANSI_X931_RNG prng(get_block_cipher(cipher),
new Fixed_Output_RNG);
- secure_vector<byte> x = hex_decode(input);
+ std::vector<byte> x = hex_decode(input);
prng.add_entropy(&x[0], x.size());
secure_vector<byte> output(result.size() / 2);