blob: d871eace83e1cdc06ad61dca89b9fecf1cf5c92b [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Jeff Thompson958bf9b2013-10-12 17:20:51 -07002/**
Alexander Afanasyev2fa59392016-07-29 17:24:23 -07003 * Copyright (c) 2013-2016 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * 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.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -070020 *
21 * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/>
22 * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
Jeff Thompson958bf9b2013-10-12 17:20:51 -070023 */
24
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080025#include "certificate-extension.hpp"
Junxiao Shi482ccc52014-03-31 13:05:24 -070026#include "cryptopp.hpp"
Jeff Thompson958bf9b2013-10-12 17:20:51 -070027
Jeff Thompson958bf9b2013-10-12 17:20:51 -070028namespace ndn {
Alexander Afanasyev2fa59392016-07-29 17:24:23 -070029namespace security {
30namespace v1 {
Jeff Thompson958bf9b2013-10-12 17:20:51 -070031
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080032void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070033CertificateExtension::encode(CryptoPP::BufferedTransformation& out) const
Jeff Thompson958bf9b2013-10-12 17:20:51 -070034{
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070035 using namespace CryptoPP;
36
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080037 // Extension ::= SEQUENCE {
38 // extnID OBJECT IDENTIFIER,
39 // critical BOOLEAN DEFAULT FALSE,
40 // extnValue OCTET STRING }
Jeff Thompson958bf9b2013-10-12 17:20:51 -070041
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080042 DERSequenceEncoder extension(out);
43 {
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070044 m_extensionId.encode(extension);
45 DEREncodeUnsigned(extension, m_isCritical, BOOLEAN);
46 DEREncodeOctetString(extension, m_extensionValue.buf(), m_extensionValue.size());
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080047 }
48 extension.MessageEnd();
Jeff Thompson958bf9b2013-10-12 17:20:51 -070049}
50
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080051void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070052CertificateExtension::decode(CryptoPP::BufferedTransformation& in)
Jeff Thompson958bf9b2013-10-12 17:20:51 -070053{
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070054 using namespace CryptoPP;
55
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080056 // Extension ::= SEQUENCE {
57 // extnID OBJECT IDENTIFIER,
58 // critical BOOLEAN DEFAULT FALSE,
59 // extnValue OCTET STRING }
Jeff Thompson958bf9b2013-10-12 17:20:51 -070060
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080061 BERSequenceDecoder extension(in);
62 {
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070063 m_extensionId.decode(extension);
64 BERDecodeUnsigned(extension, m_isCritical, BOOLEAN);
Jeff Thompson958bf9b2013-10-12 17:20:51 -070065
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080066 // the extra copy operation can be optimized, but not trivial,
67 // since the length is not known in advance
68 SecByteBlock tmpBlock;
69 BERDecodeOctetString(extension, tmpBlock);
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070070 m_extensionValue.assign(tmpBlock.begin(), tmpBlock.end());
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080071 }
72 extension.MessageEnd();
Jeff Thompson958bf9b2013-10-12 17:20:51 -070073}
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070074
Alexander Afanasyev2fa59392016-07-29 17:24:23 -070075} // namespace v1
76} // namespace security
Yingdi Yufc40d872014-02-18 12:56:04 -080077} // namespace ndn