Yingdi Yu | ebfa4cb | 2014-06-17 15:28:53 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2013-2014 Regents of the University of California. |
| 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 6 | * |
| 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 20 | */ |
| 21 | |
| 22 | #include "security/signature-sha256-with-ecdsa.hpp" |
| 23 | |
| 24 | #include "boost-test.hpp" |
| 25 | |
| 26 | namespace ndn { |
| 27 | |
| 28 | BOOST_AUTO_TEST_SUITE(SecurityTestSignatureSha256WithEcdsa) |
| 29 | |
| 30 | const uint8_t sigInfo[] = { |
| 31 | 0x16, 0x1b, // SignatureInfo |
| 32 | 0x1b, 0x01, // SignatureType |
| 33 | 0x03, |
| 34 | 0x1c, 0x16, // KeyLocator |
| 35 | 0x07, 0x14, // Name |
| 36 | 0x08, 0x04, |
| 37 | 0x74, 0x65, 0x73, 0x74, |
| 38 | 0x08, 0x03, |
| 39 | 0x6b, 0x65, 0x79, |
| 40 | 0x08, 0x07, |
| 41 | 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72 |
| 42 | }; |
| 43 | |
| 44 | const uint8_t sigValue[] = { |
| 45 | 0x17, 0x40, // SignatureValue |
| 46 | 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec, |
| 47 | 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6, |
| 48 | 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38, |
| 49 | 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc, |
| 50 | 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b |
| 51 | }; |
| 52 | |
| 53 | |
| 54 | BOOST_AUTO_TEST_CASE(Decoding) |
| 55 | { |
| 56 | Block sigInfoBlock(sigInfo, sizeof(sigInfo)); |
| 57 | Block sigValueBlock(sigValue, sizeof(sigValue)); |
| 58 | |
| 59 | Signature sig(sigInfoBlock, sigValueBlock); |
| 60 | BOOST_REQUIRE_NO_THROW(SignatureSha256WithEcdsa(sig)); |
| 61 | } |
| 62 | |
| 63 | BOOST_AUTO_TEST_CASE(Encoding) |
| 64 | { |
| 65 | SignatureSha256WithEcdsa sig; |
| 66 | |
| 67 | Name name("/test/key/locator"); |
| 68 | KeyLocator keyLocator(name); |
| 69 | |
| 70 | sig.setKeyLocator(keyLocator); |
| 71 | |
| 72 | const Block& encodeSigInfoBlock = sig.getInfo(); |
| 73 | |
| 74 | Block sigInfoBlock(sigInfo, sizeof(sigInfo)); |
| 75 | |
| 76 | BOOST_CHECK_EQUAL_COLLECTIONS(sigInfoBlock.wire(), |
| 77 | sigInfoBlock.wire() + sigInfoBlock.size(), |
| 78 | encodeSigInfoBlock.wire(), |
| 79 | encodeSigInfoBlock.wire() + encodeSigInfoBlock.size()); |
| 80 | } |
| 81 | |
| 82 | BOOST_AUTO_TEST_SUITE_END() |
| 83 | |
| 84 | } // namespace ndn |