diff options
author | lloyd <[email protected]> | 2009-09-15 12:39:44 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2009-09-15 12:39:44 +0000 |
commit | 467cfb8b8a31eecfaf63c30cfa13b69bef4cd566 (patch) | |
tree | aa6314c8afa6d2c5e0759a57fc52c91a36f43af1 /doc/examples | |
parent | 63fb872cb36a44a852ec33133de7c242bd44427e (diff) | |
parent | 18d1a6d4d11d40afb2d5a9d96b0437933bcaa472 (diff) |
propagate from branch 'net.randombit.botan.1_8' (head ef51dd2869ed38dae3aeb1c3b931ca9d595580e1)
to branch 'net.randombit.botan' (head fc1942640045423f411fd865cbd584090b28d7eb)
Diffstat (limited to 'doc/examples')
-rw-r--r-- | doc/examples/package.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/doc/examples/package.cpp b/doc/examples/package.cpp new file mode 100644 index 000000000..981abaa31 --- /dev/null +++ b/doc/examples/package.cpp @@ -0,0 +1,61 @@ + +#include <botan/botan.h> +#include <botan/serpent.h> +#include <botan/package.h> + +#include <iostream> +#include <fstream> +#include <vector> + +using namespace Botan; + +std::vector<byte> slurp_file(const std::string& filename) + { + std::ifstream in(filename.c_str()); + + 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); + + AllOrNothingTransform::package(rng, new Serpent, + &input[0], input.size(), + &output[0]); + + std::vector<byte> unpackage_output(output.size() - cipher->BLOCK_SIZE); + + AllOrNothingTransform::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"; + } |