blob: d9297a9844e65da18ef49ccec5d5a67fd91c437b [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
Jeff Thompson958bf9b2013-10-12 17:20:51 -07009#include "../../encoding/der/der.hpp"
Jeff Thompson6154ae22013-10-18 10:44:57 -070010#include "../../util/blob-stream.hpp"
Jeff Thompson958bf9b2013-10-12 17:20:51 -070011#include <ndn-cpp/security/certificate/certificate-extension.hpp>
12
13using namespace std;
Jeff Thompson958bf9b2013-10-12 17:20:51 -070014
15namespace ndn {
16
Jeff Thompsonce115762013-12-18 14:59:56 -080017ptr_lib::shared_ptr<der::DerNode>
Jeff Thompson9afac392013-12-20 10:42:15 -080018CertificateExtension::toDer() const
Jeff Thompson958bf9b2013-10-12 17:20:51 -070019{
Jeff Thompsonce115762013-12-18 14:59:56 -080020 ptr_lib::shared_ptr<der::DerSequence> root(new der::DerSequence);
Jeff Thompson958bf9b2013-10-12 17:20:51 -070021
Jeff Thompsonce115762013-12-18 14:59:56 -080022 ptr_lib::shared_ptr<der::DerOid> extensionId(new der::DerOid(extensionId_));
23 ptr_lib::shared_ptr<der::DerBool> isCritical(new der::DerBool(isCritical_));
24 ptr_lib::shared_ptr<der::DerOctetString> extensionValue(new der::DerOctetString(*extensionValue_));
Jeff Thompson958bf9b2013-10-12 17:20:51 -070025
26 root->addChild(extensionId);
27 root->addChild(isCritical);
28 root->addChild(extensionValue);
29
30 root->getSize();
31
32 return root;
Jeff Thompson958bf9b2013-10-12 17:20:51 -070033}
34
35Blob
Jeff Thompson9afac392013-12-20 10:42:15 -080036CertificateExtension::toDerBlob() const
Jeff Thompson958bf9b2013-10-12 17:20:51 -070037{
Jeff Thompson958bf9b2013-10-12 17:20:51 -070038 blob_stream blobStream;
Jeff Thompson6154ae22013-10-18 10:44:57 -070039 der::OutputIterator& start = reinterpret_cast<der::OutputIterator&>(blobStream);
Jeff Thompson958bf9b2013-10-12 17:20:51 -070040
41 toDer()->encode(start);
42
43 return blobStream.buf();
Jeff Thompson958bf9b2013-10-12 17:20:51 -070044}
45
46
47}