blob: 307fd3c7529f967f5a3b783e2a4b39e1040066ba [file] [log] [blame]
Jeff Thompson958bf9b2013-10-12 17:20:51 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07003 * Copyright (c) 2013-2014, Regents of the University of California.
4 * All rights reserved.
5 *
6 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
7 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
8 *
9 * This file licensed under New BSD License. See COPYING for detailed information about
10 * ndn-cxx library copyright, permissions, and redistribution restrictions.
11 *
12 * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/>
13 * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
Jeff Thompson958bf9b2013-10-12 17:20:51 -070014 */
15
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080016#include "common.hpp"
17
18#include "certificate-extension.hpp"
Junxiao Shi482ccc52014-03-31 13:05:24 -070019#include "cryptopp.hpp"
Jeff Thompson958bf9b2013-10-12 17:20:51 -070020
21using namespace std;
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080022using namespace CryptoPP;
Jeff Thompson958bf9b2013-10-12 17:20:51 -070023
24namespace ndn {
25
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080026void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070027CertificateExtension::encode(CryptoPP::BufferedTransformation& out) const
Jeff Thompson958bf9b2013-10-12 17:20:51 -070028{
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080029 // Extension ::= SEQUENCE {
30 // extnID OBJECT IDENTIFIER,
31 // critical BOOLEAN DEFAULT FALSE,
32 // extnValue OCTET STRING }
Jeff Thompson958bf9b2013-10-12 17:20:51 -070033
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080034 DERSequenceEncoder extension(out);
35 {
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070036 m_extensionId.encode(extension);
37 DEREncodeUnsigned(extension, m_isCritical, BOOLEAN);
38 DEREncodeOctetString(extension, m_extensionValue.buf(), m_extensionValue.size());
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080039 }
40 extension.MessageEnd();
Jeff Thompson958bf9b2013-10-12 17:20:51 -070041}
42
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080043void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070044CertificateExtension::decode(CryptoPP::BufferedTransformation& in)
Jeff Thompson958bf9b2013-10-12 17:20:51 -070045{
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080046 // Extension ::= SEQUENCE {
47 // extnID OBJECT IDENTIFIER,
48 // critical BOOLEAN DEFAULT FALSE,
49 // extnValue OCTET STRING }
Jeff Thompson958bf9b2013-10-12 17:20:51 -070050
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080051 BERSequenceDecoder extension(in);
52 {
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070053 m_extensionId.decode(extension);
54 BERDecodeUnsigned(extension, m_isCritical, BOOLEAN);
Jeff Thompson958bf9b2013-10-12 17:20:51 -070055
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080056 // the extra copy operation can be optimized, but not trivial,
57 // since the length is not known in advance
58 SecByteBlock tmpBlock;
59 BERDecodeOctetString(extension, tmpBlock);
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070060 m_extensionValue.assign(tmpBlock.begin(), tmpBlock.end());
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080061 }
62 extension.MessageEnd();
Jeff Thompson958bf9b2013-10-12 17:20:51 -070063}
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070064
Yingdi Yufc40d872014-02-18 12:56:04 -080065} // namespace ndn