aboutsummaryrefslogtreecommitdiffstats
path: root/examples/package.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2011-04-04 03:43:52 +0000
committerlloyd <[email protected]>2011-04-04 03:43:52 +0000
commit3b9bfbd07c3723662832caf5b1efe04de28b656d (patch)
treeee2a9324f384efead6e5bb87ac8374e7e8734c90 /examples/package.cpp
parent04db054f1ae8de572ee9c0cfe227e76f84096bd6 (diff)
Convert most of the documentation to reStructured Text, adding
a makefile to build it with Sphinx (http://sphinx.pocoo.org/). Previously credits.txt listed public domain code sources; instead directly credit the authors in the relevant files and delete that file. Drop the draft FIPS 140 security policy; I can't imagine FIPS 140 validation will ever happen, and if it does, I don't want anything to do with it. Also drop the internals doc, which was so out of date (and incomplete) as to be worthless. Move the tutorials and InSiTo pdfs into old/ for the time being, until anything relevant from them can be filtered out and converted into RST.
Diffstat (limited to 'examples/package.cpp')
-rw-r--r--examples/package.cpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/examples/package.cpp b/examples/package.cpp
new file mode 100644
index 000000000..02cf52816
--- /dev/null
+++ b/examples/package.cpp
@@ -0,0 +1,70 @@
+/*
+* (C) 2009 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#include <botan/botan.h>
+#include <botan/serpent.h>
+#include <botan/package.h>
+
+#include <iostream>
+#include <fstream>
+#include <vector>
+
+using namespace Botan;
+
+namespace {
+
+std::vector<byte> slurp_file(const std::string& filename)
+ {
+ std::ifstream in(filename.c_str(), std::ios::binary);
+
+ std::vector<byte> out;
+ byte buf[4096] = { 0 };
+
+ while(in.good())
+ {
+ in.read((char*)buf, sizeof(buf));
+ ssize_t got = in.gcount();
+
+ out.insert(out.end(), buf, buf+got);
+ }
+
+ return out;
+ }
+
+}
+
+int main(int argc, char* argv[])
+ {
+ if(argc != 2)
+ {
+ std::cout << "Usage: " << argv[0] << " filename\n";
+ return 1;
+ }
+
+ LibraryInitializer init;
+
+ AutoSeeded_RNG rng;
+
+ BlockCipher* cipher = new Serpent;
+
+ std::vector<byte> input = slurp_file(argv[1]);
+ std::vector<byte> output(input.size() + cipher->block_size());
+
+ aont_package(rng, new Serpent,
+ &input[0], input.size(),
+ &output[0]);
+
+ std::vector<byte> unpackage_output(output.size() - cipher->block_size());
+
+ aont_unpackage(new Serpent,
+ &output[0], output.size(),
+ &unpackage_output[0]);
+
+ if(unpackage_output == input)
+ std::cout << "Package/unpackage worked\n";
+ else
+ std::cout << "Something went wrong :(\n";
+ }