Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014-2015, Regents of the University of California |
| 4 | * |
| 5 | * This file is part of ndn-group-encrypt (Group-based Encryption Protocol for NDN). |
| 6 | * See AUTHORS.md for complete list of ndn-group-encrypt authors and contributors. |
| 7 | * |
| 8 | * ndn-group-encrypt is free software: you can redistribute it and/or modify it under the terms |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, |
| 10 | * either version 3 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * ndn-group-encrypt is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 | * PURPOSE. See the GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * ndn-group-encrypt, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | #include "encrypted-content.hpp" |
| 21 | |
| 22 | #include "boost-test.hpp" |
| 23 | #include <algorithm> |
| 24 | |
| 25 | namespace ndn { |
| 26 | namespace gep { |
| 27 | namespace tests { |
| 28 | |
| 29 | BOOST_AUTO_TEST_SUITE(TestEncryptedContent) |
| 30 | |
| 31 | const uint8_t encrypted[] = { |
Prashanth Swaminathan | b1b9596 | 2015-07-06 13:13:08 -0700 | [diff] [blame] | 32 | 0x82, 0x30, // EncryptedContent |
| 33 | 0x1c, 0x16, // KeyLocator |
| 34 | 0x07, 0x14, // Name |
| 35 | 0x08, 0x04, |
| 36 | 0x74, 0x65, 0x73, 0x74, // 'test' |
| 37 | 0x08, 0x03, |
| 38 | 0x6b, 0x65, 0x79, // 'key' |
| 39 | 0x08, 0x07, |
| 40 | 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72, // 'locator' |
| 41 | 0x83, 0x01, // EncryptedAlgorithm |
Prashanth Swaminathan | d5b3eae | 2015-07-09 15:37:05 -0700 | [diff] [blame] | 42 | 0x03, |
Prashanth Swaminathan | b1b9596 | 2015-07-06 13:13:08 -0700 | [diff] [blame] | 43 | 0x85, 0x0a, // InitialVector |
| 44 | 0x72, 0x61, 0x6e, 0x64, 0x6f, 0x6d, 0x62, 0x69, 0x74, 0x73, |
| 45 | 0x84, 0x07, // EncryptedPayload |
| 46 | 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74 |
| 47 | }; |
| 48 | |
| 49 | const uint8_t encrypted_noiv[] = { |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 50 | 0x82, 0x24, // EncryptedContent |
| 51 | 0x1c, 0x16, // KeyLocator |
| 52 | 0x07, 0x14, // Name |
| 53 | 0x08, 0x04, |
| 54 | 0x74, 0x65, 0x73, 0x74, // 'test' |
| 55 | 0x08, 0x03, |
| 56 | 0x6b, 0x65, 0x79, // 'key' |
| 57 | 0x08, 0x07, |
| 58 | 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72, // 'locator' |
| 59 | 0x83, 0x01, // EncryptedAlgorithm |
Prashanth Swaminathan | d5b3eae | 2015-07-09 15:37:05 -0700 | [diff] [blame] | 60 | 0x03, |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 61 | 0x84, 0x07, // EncryptedPayload |
| 62 | 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74 |
| 63 | }; |
| 64 | |
| 65 | const uint8_t message[] = { |
| 66 | 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74 |
| 67 | }; |
| 68 | |
Prashanth Swaminathan | b1b9596 | 2015-07-06 13:13:08 -0700 | [diff] [blame] | 69 | const uint8_t iv[] = { |
| 70 | 0x72, 0x61, 0x6e, 0x64, 0x6f, 0x6d, 0x62, 0x69, 0x74, 0x73 |
| 71 | }; |
| 72 | |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 73 | BOOST_AUTO_TEST_CASE(Constructor) |
| 74 | { |
| 75 | EncryptedContent content; |
| 76 | BOOST_CHECK_EQUAL(content.getAlgorithmType(), -1); |
Prashanth Swaminathan | d5b3eae | 2015-07-09 15:37:05 -0700 | [diff] [blame] | 77 | BOOST_CHECK_EQUAL((content.getPayload()).size(), 0); |
| 78 | BOOST_CHECK_EQUAL((content.getInitialVector()).size(), 0); |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 79 | BOOST_CHECK_EQUAL(content.hasKeyLocator(), false); |
| 80 | BOOST_CHECK_THROW(content.getKeyLocator(), EncryptedContent::Error); |
| 81 | |
Prashanth Swaminathan | d5b3eae | 2015-07-09 15:37:05 -0700 | [diff] [blame] | 82 | Buffer payload(message, sizeof(message)); |
| 83 | //Buffer initialVector(iv, sizeof(iv)); |
Prashanth Swaminathan | b1b9596 | 2015-07-06 13:13:08 -0700 | [diff] [blame] | 84 | |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 85 | KeyLocator keyLocator("test/key/locator"); |
Prashanth Swaminathan | d5b3eae | 2015-07-09 15:37:05 -0700 | [diff] [blame] | 86 | EncryptedContent sha256RsaContent(tlv::AlgorithmRsaOaep, keyLocator, |
| 87 | message, sizeof(message), iv, sizeof(iv)); |
| 88 | const Buffer& contentPayload = sha256RsaContent.getPayload(); |
| 89 | const Buffer& contentInitialVector = sha256RsaContent.getInitialVector(); |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 90 | |
Prashanth Swaminathan | d5b3eae | 2015-07-09 15:37:05 -0700 | [diff] [blame] | 91 | BOOST_CHECK_EQUAL(sha256RsaContent.getAlgorithmType(), tlv::AlgorithmRsaOaep); |
| 92 | BOOST_CHECK_EQUAL_COLLECTIONS(contentPayload.begin(), |
| 93 | contentPayload.end(), |
| 94 | payload.begin(), |
| 95 | payload.end()); |
| 96 | BOOST_CHECK_EQUAL_COLLECTIONS(contentInitialVector.begin(), |
| 97 | contentInitialVector.end(), |
| 98 | iv, |
| 99 | iv + sizeof(iv)); |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 100 | BOOST_CHECK_EQUAL(sha256RsaContent.hasKeyLocator(), true); |
| 101 | BOOST_CHECK_NO_THROW(sha256RsaContent.getKeyLocator()); |
| 102 | BOOST_CHECK_EQUAL(sha256RsaContent.getKeyLocator().getName(), Name("test/key/locator")); |
| 103 | |
| 104 | Block encryptedBlock(encrypted, sizeof(encrypted)); |
| 105 | const Block& encoded = sha256RsaContent.wireEncode(); |
| 106 | |
| 107 | BOOST_CHECK_EQUAL_COLLECTIONS(encryptedBlock.wire(), |
| 108 | encryptedBlock.wire() + encryptedBlock.size(), |
| 109 | encoded.wire(), |
| 110 | encoded.wire() + encoded.size()); |
| 111 | |
| 112 | sha256RsaContent = EncryptedContent(encryptedBlock); |
Prashanth Swaminathan | d5b3eae | 2015-07-09 15:37:05 -0700 | [diff] [blame] | 113 | const Buffer& contentPayloadBlock = sha256RsaContent.getPayload(); |
| 114 | const Buffer& contentInitialVectorBlock = sha256RsaContent.getInitialVector(); |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 115 | |
Prashanth Swaminathan | d5b3eae | 2015-07-09 15:37:05 -0700 | [diff] [blame] | 116 | BOOST_CHECK_EQUAL(sha256RsaContent.getAlgorithmType(), tlv::AlgorithmRsaOaep); |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 117 | BOOST_CHECK_EQUAL(sha256RsaContent.hasKeyLocator(), true); |
Prashanth Swaminathan | d5b3eae | 2015-07-09 15:37:05 -0700 | [diff] [blame] | 118 | BOOST_CHECK_EQUAL_COLLECTIONS(contentPayloadBlock.begin(), |
| 119 | contentPayloadBlock.end(), |
| 120 | payload.begin(), |
| 121 | payload.end()); |
| 122 | BOOST_CHECK_EQUAL_COLLECTIONS(contentInitialVectorBlock.begin(), |
| 123 | contentInitialVectorBlock.end(), |
| 124 | iv, |
| 125 | iv + sizeof(iv)); |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 126 | BOOST_CHECK_NO_THROW(sha256RsaContent.getKeyLocator()); |
| 127 | BOOST_CHECK_EQUAL(sha256RsaContent.getKeyLocator().getName(), Name("test/key/locator")); |
Prashanth Swaminathan | b1b9596 | 2015-07-06 13:13:08 -0700 | [diff] [blame] | 128 | |
Prashanth Swaminathan | d5b3eae | 2015-07-09 15:37:05 -0700 | [diff] [blame] | 129 | sha256RsaContent = EncryptedContent(tlv::AlgorithmRsaOaep, keyLocator, |
| 130 | message, sizeof(message)); |
| 131 | const Buffer& contentPayloadRecovered = sha256RsaContent.getPayload(); |
Prashanth Swaminathan | b1b9596 | 2015-07-06 13:13:08 -0700 | [diff] [blame] | 132 | |
Prashanth Swaminathan | d5b3eae | 2015-07-09 15:37:05 -0700 | [diff] [blame] | 133 | BOOST_CHECK_EQUAL(sha256RsaContent.getAlgorithmType(), tlv::AlgorithmRsaOaep); |
| 134 | BOOST_CHECK_EQUAL_COLLECTIONS(contentPayloadRecovered.begin(), |
| 135 | contentPayloadRecovered.end(), |
| 136 | payload.begin(), |
| 137 | payload.end()); |
| 138 | BOOST_CHECK_EQUAL((sha256RsaContent.getInitialVector()).size(), 0); |
Prashanth Swaminathan | b1b9596 | 2015-07-06 13:13:08 -0700 | [diff] [blame] | 139 | BOOST_CHECK_EQUAL(sha256RsaContent.hasKeyLocator(), true); |
| 140 | BOOST_CHECK_NO_THROW(sha256RsaContent.getKeyLocator()); |
| 141 | BOOST_CHECK_EQUAL(sha256RsaContent.getKeyLocator().getName(), Name("test/key/locator")); |
| 142 | |
| 143 | encryptedBlock = Block(encrypted_noiv, sizeof(encrypted_noiv)); |
| 144 | const Block& encodedNoIV = sha256RsaContent.wireEncode(); |
| 145 | |
| 146 | BOOST_CHECK_EQUAL_COLLECTIONS(encryptedBlock.wire(), |
| 147 | encryptedBlock.wire() + encryptedBlock.size(), |
| 148 | encodedNoIV.wire(), |
| 149 | encodedNoIV.wire() + encodedNoIV.size()); |
| 150 | |
| 151 | sha256RsaContent = EncryptedContent(encryptedBlock); |
Prashanth Swaminathan | d5b3eae | 2015-07-09 15:37:05 -0700 | [diff] [blame] | 152 | const Buffer& contentPayloadNoIV = sha256RsaContent.getPayload(); |
Prashanth Swaminathan | b1b9596 | 2015-07-06 13:13:08 -0700 | [diff] [blame] | 153 | |
Prashanth Swaminathan | d5b3eae | 2015-07-09 15:37:05 -0700 | [diff] [blame] | 154 | BOOST_CHECK_EQUAL(sha256RsaContent.getAlgorithmType(), tlv::AlgorithmRsaOaep); |
Prashanth Swaminathan | b1b9596 | 2015-07-06 13:13:08 -0700 | [diff] [blame] | 155 | BOOST_CHECK_EQUAL(sha256RsaContent.hasKeyLocator(), true); |
Prashanth Swaminathan | d5b3eae | 2015-07-09 15:37:05 -0700 | [diff] [blame] | 156 | BOOST_CHECK_EQUAL_COLLECTIONS(contentPayloadNoIV.begin(), |
| 157 | contentPayloadNoIV.end(), |
| 158 | payload.begin(), |
| 159 | payload.end()); |
| 160 | BOOST_CHECK_EQUAL((sha256RsaContent.getInitialVector()).size(), 0); |
Prashanth Swaminathan | b1b9596 | 2015-07-06 13:13:08 -0700 | [diff] [blame] | 161 | BOOST_CHECK_NO_THROW(sha256RsaContent.getKeyLocator()); |
| 162 | BOOST_CHECK_EQUAL(sha256RsaContent.getKeyLocator().getName(), Name("test/key/locator")); |
| 163 | |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | BOOST_AUTO_TEST_CASE(ConstructorError) |
| 167 | { |
| 168 | const uint8_t error1[] = { |
Prashanth Swaminathan | b1b9596 | 2015-07-06 13:13:08 -0700 | [diff] [blame] | 169 | 0x1f, 0x30, // Wrong EncryptedContent (0x82, 0x24) |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 170 | 0x1c, 0x16, // KeyLocator |
| 171 | 0x07, 0x14, // Name |
| 172 | 0x08, 0x04, |
| 173 | 0x74, 0x65, 0x73, 0x74, |
| 174 | 0x08, 0x03, |
| 175 | 0x6b, 0x65, 0x79, |
| 176 | 0x08, 0x07, |
| 177 | 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72, |
| 178 | 0x83, 0x01, // EncryptedAlgorithm |
Prashanth Swaminathan | d5b3eae | 2015-07-09 15:37:05 -0700 | [diff] [blame] | 179 | 0x03, |
Prashanth Swaminathan | b1b9596 | 2015-07-06 13:13:08 -0700 | [diff] [blame] | 180 | 0x85, 0x0a, // InitialVector |
| 181 | 0x72, 0x61, 0x6e, 0x64, 0x6f, 0x6d, 0x62, 0x69, 0x74, 0x73, |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 182 | 0x84, 0x07, // EncryptedPayload |
| 183 | 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74 |
| 184 | }; |
| 185 | Block errorBlock1(error1, sizeof(error1)); |
| 186 | BOOST_CHECK_THROW(EncryptedContent info(errorBlock1), EncryptedContent::Error); |
| 187 | |
| 188 | const uint8_t error2[] = { |
Prashanth Swaminathan | b1b9596 | 2015-07-06 13:13:08 -0700 | [diff] [blame] | 189 | 0x82, 0x30, // EncryptedContent |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 190 | 0x1d, 0x16, // Wrong KeyLocator (0x1c, 0x16) |
| 191 | 0x07, 0x14, // Name |
| 192 | 0x08, 0x04, |
| 193 | 0x74, 0x65, 0x73, 0x74, |
| 194 | 0x08, 0x03, |
| 195 | 0x6b, 0x65, 0x79, |
| 196 | 0x08, 0x07, |
| 197 | 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72, |
| 198 | 0x83, 0x01, // EncryptedAlgorithm |
Prashanth Swaminathan | d5b3eae | 2015-07-09 15:37:05 -0700 | [diff] [blame] | 199 | 0x03, |
Prashanth Swaminathan | b1b9596 | 2015-07-06 13:13:08 -0700 | [diff] [blame] | 200 | 0x85, 0x0a, // InitialVector |
| 201 | 0x72, 0x61, 0x6e, 0x64, 0x6f, 0x6d, 0x62, 0x69, 0x74, 0x73, |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 202 | 0x84, 0x07, // EncryptedPayload |
| 203 | 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74 |
| 204 | }; |
| 205 | Block errorBlock2(error2, sizeof(error2)); |
| 206 | BOOST_CHECK_THROW(EncryptedContent info(errorBlock2), EncryptedContent::Error); |
| 207 | |
| 208 | const uint8_t error3[] = { |
Prashanth Swaminathan | b1b9596 | 2015-07-06 13:13:08 -0700 | [diff] [blame] | 209 | 0x82, 0x30, // EncryptedContent |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 210 | 0x1c, 0x16, // KeyLocator |
| 211 | 0x07, 0x14, // Name |
| 212 | 0x08, 0x04, |
| 213 | 0x74, 0x65, 0x73, 0x74, |
| 214 | 0x08, 0x03, |
| 215 | 0x6b, 0x65, 0x79, |
| 216 | 0x08, 0x07, |
| 217 | 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72, |
| 218 | 0x1d, 0x01, // Wrong EncryptedAlgorithm (0x83, 0x01) |
Prashanth Swaminathan | d5b3eae | 2015-07-09 15:37:05 -0700 | [diff] [blame] | 219 | 0x03, |
Prashanth Swaminathan | b1b9596 | 2015-07-06 13:13:08 -0700 | [diff] [blame] | 220 | 0x85, 0x0a, // InitialVector |
| 221 | 0x72, 0x61, 0x6e, 0x64, 0x6f, 0x6d, 0x62, 0x69, 0x74, 0x73, |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 222 | 0x84, 0x07, // EncryptedPayload |
| 223 | 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74 |
| 224 | }; |
| 225 | Block errorBlock3(error3, sizeof(error3)); |
| 226 | BOOST_CHECK_THROW(EncryptedContent info(errorBlock3), EncryptedContent::Error); |
| 227 | |
| 228 | const uint8_t error4[] = { |
Prashanth Swaminathan | b1b9596 | 2015-07-06 13:13:08 -0700 | [diff] [blame] | 229 | 0x82, 0x30, // EncryptedContent |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 230 | 0x1c, 0x16, // KeyLocator |
| 231 | 0x07, 0x14, // Name |
| 232 | 0x08, 0x04, |
| 233 | 0x74, 0x65, 0x73, 0x74, // 'test' |
| 234 | 0x08, 0x03, |
| 235 | 0x6b, 0x65, 0x79, // 'key' |
| 236 | 0x08, 0x07, |
| 237 | 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72, // 'locator' |
| 238 | 0x83, 0x01, // EncryptedAlgorithm |
Prashanth Swaminathan | d5b3eae | 2015-07-09 15:37:05 -0700 | [diff] [blame] | 239 | 0x03, |
Prashanth Swaminathan | b1b9596 | 2015-07-06 13:13:08 -0700 | [diff] [blame] | 240 | 0x1f, 0x0a, // InitialVector (0x84, 0x0a) |
| 241 | 0x72, 0x61, 0x6e, 0x64, 0x6f, 0x6d, 0x62, 0x69, 0x74, 0x73, |
| 242 | 0x84, 0x07, // EncryptedPayload |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 243 | 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74 |
| 244 | }; |
| 245 | Block errorBlock4(error4, sizeof(error4)); |
| 246 | BOOST_CHECK_THROW(EncryptedContent info(errorBlock4), EncryptedContent::Error); |
| 247 | |
| 248 | const uint8_t error5[] = { |
Prashanth Swaminathan | b1b9596 | 2015-07-06 13:13:08 -0700 | [diff] [blame] | 249 | 0x82, 0x30, // EncryptedContent |
| 250 | 0x1c, 0x16, // KeyLocator |
| 251 | 0x07, 0x14, // Name |
| 252 | 0x08, 0x04, |
| 253 | 0x74, 0x65, 0x73, 0x74, // 'test' |
| 254 | 0x08, 0x03, |
| 255 | 0x6b, 0x65, 0x79, // 'key' |
| 256 | 0x08, 0x07, |
| 257 | 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72, // 'locator' |
| 258 | 0x83, 0x01, // EncryptedAlgorithm |
Prashanth Swaminathan | d5b3eae | 2015-07-09 15:37:05 -0700 | [diff] [blame] | 259 | 0x03, |
Prashanth Swaminathan | b1b9596 | 2015-07-06 13:13:08 -0700 | [diff] [blame] | 260 | 0x85, 0x0a, // InitialVector |
| 261 | 0x72, 0x61, 0x6e, 0x64, 0x6f, 0x6d, 0x62, 0x69, 0x74, 0x73, |
| 262 | 0x21, 0x07, // EncryptedPayload (0x85, 0x07) |
| 263 | 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74 |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 264 | }; |
| 265 | Block errorBlock5(error5, sizeof(error5)); |
| 266 | BOOST_CHECK_THROW(EncryptedContent info(errorBlock5), EncryptedContent::Error); |
Prashanth Swaminathan | b1b9596 | 2015-07-06 13:13:08 -0700 | [diff] [blame] | 267 | |
| 268 | const uint8_t error6[] = { |
| 269 | 0x82, 0x00 // Empty EncryptedContent |
| 270 | }; |
| 271 | Block errorBlock6(error6, sizeof(error6)); |
| 272 | BOOST_CHECK_THROW(EncryptedContent info(errorBlock6), EncryptedContent::Error); |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | BOOST_AUTO_TEST_CASE(SetterGetter) |
| 276 | { |
| 277 | EncryptedContent content; |
| 278 | BOOST_CHECK_EQUAL(content.getAlgorithmType(), -1); |
Prashanth Swaminathan | d5b3eae | 2015-07-09 15:37:05 -0700 | [diff] [blame] | 279 | BOOST_CHECK_EQUAL((content.getPayload()).size(), 0); |
| 280 | BOOST_CHECK_EQUAL((content.getInitialVector()).size(), 0); |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 281 | BOOST_CHECK_EQUAL(content.hasKeyLocator(), false); |
| 282 | BOOST_CHECK_THROW(content.getKeyLocator(), EncryptedContent::Error); |
| 283 | |
Prashanth Swaminathan | d5b3eae | 2015-07-09 15:37:05 -0700 | [diff] [blame] | 284 | content.setAlgorithmType(tlv::AlgorithmRsaOaep); |
| 285 | BOOST_CHECK_EQUAL(content.getAlgorithmType(), tlv::AlgorithmRsaOaep); |
| 286 | BOOST_CHECK_EQUAL((content.getPayload()).size(), 0); |
| 287 | BOOST_CHECK_EQUAL(content.getInitialVector().size(), 0); |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 288 | BOOST_CHECK_EQUAL(content.hasKeyLocator(), false); |
| 289 | |
| 290 | KeyLocator keyLocator("/test/key/locator"); |
| 291 | content.setKeyLocator(keyLocator); |
| 292 | BOOST_CHECK_EQUAL(content.hasKeyLocator(), true); |
| 293 | BOOST_CHECK_NO_THROW(content.getKeyLocator()); |
| 294 | BOOST_CHECK_EQUAL(content.getKeyLocator().getName(), Name("/test/key/locator")); |
Prashanth Swaminathan | d5b3eae | 2015-07-09 15:37:05 -0700 | [diff] [blame] | 295 | BOOST_CHECK_EQUAL((content.getPayload()).size(), 0); |
| 296 | BOOST_CHECK_EQUAL((content.getInitialVector()).size(), 0); |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 297 | |
Prashanth Swaminathan | d5b3eae | 2015-07-09 15:37:05 -0700 | [diff] [blame] | 298 | content.setPayload(message, sizeof(message)); |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 299 | |
Prashanth Swaminathan | d5b3eae | 2015-07-09 15:37:05 -0700 | [diff] [blame] | 300 | const Buffer& contentPayload = content.getPayload(); |
| 301 | BOOST_CHECK_EQUAL_COLLECTIONS(contentPayload.begin(), |
| 302 | contentPayload.end(), |
| 303 | message, |
| 304 | message + sizeof(message)); |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 305 | |
Prashanth Swaminathan | d5b3eae | 2015-07-09 15:37:05 -0700 | [diff] [blame] | 306 | content.setInitialVector(iv, sizeof(iv)); |
Prashanth Swaminathan | b1b9596 | 2015-07-06 13:13:08 -0700 | [diff] [blame] | 307 | |
Prashanth Swaminathan | d5b3eae | 2015-07-09 15:37:05 -0700 | [diff] [blame] | 308 | const Buffer& contentInitialVector = content.getInitialVector(); |
| 309 | BOOST_CHECK_EQUAL_COLLECTIONS(contentInitialVector.begin(), |
| 310 | contentInitialVector.end(), |
| 311 | iv, |
| 312 | iv + sizeof(iv)); |
Prashanth Swaminathan | b1b9596 | 2015-07-06 13:13:08 -0700 | [diff] [blame] | 313 | |
Prashanth | c0029b6 | 2015-04-27 14:00:08 -0700 | [diff] [blame] | 314 | const Block& encoded = content.wireEncode(); |
| 315 | Block contentBlock(encrypted, sizeof(encrypted)); |
| 316 | |
| 317 | BOOST_CHECK_EQUAL_COLLECTIONS(contentBlock.wire(), |
| 318 | contentBlock.wire() + contentBlock.size(), |
| 319 | encoded.wire(), |
| 320 | encoded.wire() + encoded.size()); |
| 321 | } |
| 322 | BOOST_AUTO_TEST_SUITE_END() |
| 323 | |
| 324 | } // namespace tests |
| 325 | } // namespace gep |
| 326 | } // namespace ndn |