blob: bf0a00c42d5ad506c28946acafb65f31a3f6c023 [file] [log] [blame]
Yingdi Yu2620b1c2014-06-12 15:32:57 -07001/* -*- 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/public-key.hpp"
23#include "security/cryptopp.hpp"
24#include "encoding/buffer-stream.hpp"
25
26#include "boost-test.hpp"
27
28
29namespace ndn {
30
31BOOST_AUTO_TEST_SUITE(SecurityTestPublicKey)
32
33const std::string RSA_DER("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuFoDcNtffwbfFix64fw0\
34hI2tKMkFrc6Ex7yw0YLMK9vGE8lXOyBl/qXabow6RCz+GldmFN6E2Qhm1+AX3Zm5\
35sj3H53/HPtzMefvMQ9X7U+lK8eNMWawpRzvBh4/36VrK/awlkNIVIQ9aXj6q6BVe\
36zL+zWT/WYemLq/8A1/hHWiwCtfOH1xQhGqWHJzeSgwIgOOrzxTbRaCjhAb1u2TeV\
37yx/I9H/DV+AqSHCaYbB92HDcDN0kqwSnUf5H1+osE9MR5DLBLhXdSiULSgxT3Or/\
38y2QgsgUK59WrjhlVMPEiHHRs15NZJbL1uQFXjgScdEarohcY3dilqotineFZCeN8\
39DwIDAQAB");
40const std::string ECDSA_DER("MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAENZpqkPJDj8uhSpffOiCbvSYMLsGB\
411Eo/WU6mrexjGvduQXjqwon/eSHFI6EgHZk8L9KfiV5XVtVsk2g5wIpJVg==");
42
43BOOST_AUTO_TEST_CASE(RSA)
44{
45 using namespace CryptoPP;
46
47 OBufferStream os;
48 StringSource ss(reinterpret_cast<const uint8_t*>(RSA_DER.c_str()), RSA_DER.size(),
49 true, new Base64Decoder(new FileSink(os)));
50
51 shared_ptr<PublicKey> publicKey;
52 BOOST_REQUIRE_NO_THROW(publicKey = shared_ptr<PublicKey>(new PublicKey(os.buf()->buf(),
53 os.buf()->size())));
54
55 BOOST_CHECK_EQUAL(publicKey->getKeyType(), KEY_TYPE_RSA);
56}
57
58BOOST_AUTO_TEST_CASE(ECDSA)
59{
60 using namespace CryptoPP;
61
62 OBufferStream os;
63 StringSource ss(reinterpret_cast<const uint8_t*>(ECDSA_DER.c_str()), ECDSA_DER.size(),
64 true, new Base64Decoder(new FileSink(os)));
65
66 shared_ptr<PublicKey> publicKey;
67 BOOST_REQUIRE_NO_THROW(publicKey = shared_ptr<PublicKey>(new PublicKey(os.buf()->buf(),
68 os.buf()->size())));
69
70 BOOST_CHECK_EQUAL(publicKey->getKeyType(), KEY_TYPE_ECDSA);
71}
72
73BOOST_AUTO_TEST_SUITE_END()
74
75} // namespace ndn