blob: 87489cee51bdcdf9fb3ee2c4bdd59eaf49529219 [file] [log] [blame]
Jeff Thompson958bf9b2013-10-12 17:20:51 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
3 * Copyright (C) 2013 Regents of the University of California.
Jeff Thompson173fd432013-10-12 18:16:41 -07004 * @author: Yingdi Yu <yingdi@cs.ucla.edu>
Jeff Thompson958bf9b2013-10-12 17:20:51 -07005 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
6 * See COPYING for copyright and distribution information.
7 */
8
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -08009#include "common.hpp"
10
11#include "certificate-extension.hpp"
Junxiao Shi482ccc52014-03-31 13:05:24 -070012#include "cryptopp.hpp"
Jeff Thompson958bf9b2013-10-12 17:20:51 -070013
14using namespace std;
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080015using namespace CryptoPP;
Jeff Thompson958bf9b2013-10-12 17:20:51 -070016
17namespace ndn {
18
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080019void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070020CertificateExtension::encode(CryptoPP::BufferedTransformation& out) const
Jeff Thompson958bf9b2013-10-12 17:20:51 -070021{
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080022 // Extension ::= SEQUENCE {
23 // extnID OBJECT IDENTIFIER,
24 // critical BOOLEAN DEFAULT FALSE,
25 // extnValue OCTET STRING }
Jeff Thompson958bf9b2013-10-12 17:20:51 -070026
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080027 DERSequenceEncoder extension(out);
28 {
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070029 m_extensionId.encode(extension);
30 DEREncodeUnsigned(extension, m_isCritical, BOOLEAN);
31 DEREncodeOctetString(extension, m_extensionValue.buf(), m_extensionValue.size());
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080032 }
33 extension.MessageEnd();
Jeff Thompson958bf9b2013-10-12 17:20:51 -070034}
35
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080036void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070037CertificateExtension::decode(CryptoPP::BufferedTransformation& in)
Jeff Thompson958bf9b2013-10-12 17:20:51 -070038{
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080039 // Extension ::= SEQUENCE {
40 // extnID OBJECT IDENTIFIER,
41 // critical BOOLEAN DEFAULT FALSE,
42 // extnValue OCTET STRING }
Jeff Thompson958bf9b2013-10-12 17:20:51 -070043
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080044 BERSequenceDecoder extension(in);
45 {
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070046 m_extensionId.decode(extension);
47 BERDecodeUnsigned(extension, m_isCritical, BOOLEAN);
Jeff Thompson958bf9b2013-10-12 17:20:51 -070048
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080049 // the extra copy operation can be optimized, but not trivial,
50 // since the length is not known in advance
51 SecByteBlock tmpBlock;
52 BERDecodeOctetString(extension, tmpBlock);
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070053 m_extensionValue.assign(tmpBlock.begin(), tmpBlock.end());
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080054 }
55 extension.MessageEnd();
Jeff Thompson958bf9b2013-10-12 17:20:51 -070056}
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070057
Yingdi Yufc40d872014-02-18 12:56:04 -080058} // namespace ndn