summaryrefslogtreecommitdiffstats
path: root/src/test/testcrypto.cc
diff options
context:
space:
mode:
authorRoald J. van Loon <roaldvanloon@gmail.com>2013-09-07 15:27:33 +0200
committerRoald J. van Loon <roaldvanloon@gmail.com>2013-09-07 22:41:10 +0200
commit0b267b3038728770357e382e2bd40db47da769b7 (patch)
treef4439015fcca3a9e89737807b524beb1432562ab /src/test/testcrypto.cc
parentautomake cleanup: moving code away from include to common (diff)
downloadceph-0b267b3038728770357e382e2bd40db47da769b7.tar.xz
ceph-0b267b3038728770357e382e2bd40db47da769b7.zip
automake cleanup: moving tests to test subdir
This are tests and should be in the src/test subdir. Signed-off-by: Roald J. van Loon <roaldvanloon@gmail.com>
Diffstat (limited to 'src/test/testcrypto.cc')
-rw-r--r--src/test/testcrypto.cc56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/test/testcrypto.cc b/src/test/testcrypto.cc
new file mode 100644
index 00000000000..0b7a9d54742
--- /dev/null
+++ b/src/test/testcrypto.cc
@@ -0,0 +1,56 @@
+#include "auth/Crypto.h"
+#include "common/Clock.h"
+
+#include "common/config.h"
+#include "common/debug.h"
+
+#define dout_subsys ceph_subsys_auth
+
+#define AES_KEY_LEN 16
+
+int main(int argc, char *argv[])
+{
+ char aes_key[AES_KEY_LEN];
+ memset(aes_key, 0x77, sizeof(aes_key));
+ bufferptr keybuf(aes_key, sizeof(aes_key));
+ CryptoKey key(CEPH_CRYPTO_AES, ceph_clock_now(g_ceph_context), keybuf);
+
+ const char *msg="hello! this is a message\n";
+ char pad[16];
+ memset(pad, 0, 16);
+ bufferptr ptr(msg, strlen(msg));
+ bufferlist enc_in;
+ enc_in.append(ptr);
+ enc_in.append(msg, strlen(msg));
+
+ bufferlist enc_out;
+ std::string error;
+ key.encrypt(g_ceph_context, enc_in, enc_out, error);
+ if (!error.empty()) {
+ dout(0) << "couldn't encode! error " << error << dendl;
+ exit(1);
+ }
+
+ const char *enc_buf = enc_out.c_str();
+ for (unsigned i=0; i<enc_out.length(); i++) {
+ std::cout << hex << (int)(unsigned char)enc_buf[i] << dec << " ";
+ if (i && !(i%16))
+ std::cout << std::endl;
+ }
+
+ bufferlist dec_in, dec_out;
+
+ dec_in = enc_out;
+
+ key.decrypt(g_ceph_context, dec_in, dec_out, error);
+ if (!error.empty()) {
+ dout(0) << "couldn't decode! error " << error << dendl;
+ exit(1);
+ }
+
+ dout(0) << "decoded len: " << dec_out.length() << dendl;
+ dout(0) << "decoded msg: " << dec_out.c_str() << dendl;
+
+ return 0;
+}
+