tests: eliminate cryptopp use from Test{Signer,Verifier}Filter
Change-Id: Id6781ce2636c9803b601e26b8847b76a029e3b99
Refs: #3946
diff --git a/tests/unit-tests/security/transform/block-cipher.t.cpp b/tests/unit-tests/security/transform/block-cipher.t.cpp
index 82f5d39..ccc5d2b 100644
--- a/tests/unit-tests/security/transform/block-cipher.t.cpp
+++ b/tests/unit-tests/security/transform/block-cipher.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2016 Regents of the University of California.
+/*
+ * Copyright (c) 2013-2017 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -20,10 +20,10 @@
*/
#include "security/transform/block-cipher.hpp"
+
+#include "encoding/buffer-stream.hpp"
#include "security/transform/buffer-source.hpp"
#include "security/transform/stream-sink.hpp"
-#include "encoding/buffer-stream.hpp"
-#include <iostream>
#include "boost-test.hpp"
@@ -38,35 +38,25 @@
BOOST_AUTO_TEST_CASE(AesCbc)
{
- uint8_t key[] = {
+ const uint8_t key[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
};
-
- uint8_t plainText[] = {
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
- };
-
- uint8_t iv[] = {
+ const uint8_t iv[] = {
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
};
-
- /*
- * Cipher text can be generated using:
- *
- * {
- * using namespace CryptoPP;
- * CBC_Mode<AES>::Encryption aes(key, sizeof(key), iv);
- * StringSource(plainText, sizeof(plainText), true,
- * new StreamTransformationFilter(aes,
- * new HexEncoder(new FileSink(std::cerr), false)));
- * }
- */
- uint8_t cipherText[] = {
+ const uint8_t plainText[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
+ };
+ //
+ // You can use the following shell one-liner to calculate the ciphertext:
+ // echo ${plaintext} | xxd -p -r | openssl enc -aes-128-cbc -K ${key} -iv ${iv} | xxd -i
+ //
+ const uint8_t cipherText[] = {
0x07, 0x4d, 0x32, 0x68, 0xc3, 0x40, 0x64, 0x43,
0x1e, 0x66, 0x4c, 0x25, 0x66, 0x42, 0x0f, 0x59,
0x0a, 0x51, 0x19, 0x07, 0x67, 0x5c, 0x0e, 0xfa,
@@ -78,22 +68,20 @@
// encrypt
OBufferStream os;
bufferSource(plainText, sizeof(plainText)) >>
- blockCipher(BlockCipherAlgorithm::AES_CBC,
- CipherOperator::ENCRYPT,
+ blockCipher(BlockCipherAlgorithm::AES_CBC, CipherOperator::ENCRYPT,
key, sizeof(key), iv, sizeof(iv)) >> streamSink(os);
- ConstBufferPtr buf = os.buf();
+ auto buf = os.buf();
BOOST_CHECK_EQUAL_COLLECTIONS(cipherText, cipherText + sizeof(cipherText),
buf->begin(), buf->end());
// decrypt
OBufferStream os2;
bufferSource(cipherText, sizeof(cipherText)) >>
- blockCipher(BlockCipherAlgorithm::AES_CBC,
- CipherOperator::DECRYPT,
+ blockCipher(BlockCipherAlgorithm::AES_CBC, CipherOperator::DECRYPT,
key, sizeof(key), iv, sizeof(iv)) >> streamSink(os2);
- ConstBufferPtr buf2 = os2.buf();
+ auto buf2 = os2.buf();
BOOST_CHECK_EQUAL_COLLECTIONS(plainText, plainText + sizeof(plainText),
buf2->begin(), buf2->end());
}