Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2013 Regents of the University of California. |
Jeff Thompson | 173fd43 | 2013-10-12 18:16:41 -0700 | [diff] [blame] | 4 | * @author: Yingdi Yu <yingdi@cs.ucla.edu> |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 5 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
| 6 | * See COPYING for copyright and distribution information. |
| 7 | */ |
| 8 | |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 9 | #include "../../encoding/der/der.hpp" |
Jeff Thompson | 6154ae2 | 2013-10-18 10:44:57 -0700 | [diff] [blame] | 10 | #include "../../util/blob-stream.hpp" |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 11 | #include <ndn-cpp/security/certificate/certificate-extension.hpp> |
| 12 | |
| 13 | using namespace std; |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 14 | |
| 15 | namespace ndn { |
| 16 | |
Jeff Thompson | ce11576 | 2013-12-18 14:59:56 -0800 | [diff] [blame] | 17 | ptr_lib::shared_ptr<der::DerNode> |
Jeff Thompson | 9afac39 | 2013-12-20 10:42:15 -0800 | [diff] [blame] | 18 | CertificateExtension::toDer() const |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 19 | { |
Jeff Thompson | ce11576 | 2013-12-18 14:59:56 -0800 | [diff] [blame] | 20 | ptr_lib::shared_ptr<der::DerSequence> root(new der::DerSequence); |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 21 | |
Jeff Thompson | ce11576 | 2013-12-18 14:59:56 -0800 | [diff] [blame] | 22 | 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 Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 25 | |
| 26 | root->addChild(extensionId); |
| 27 | root->addChild(isCritical); |
| 28 | root->addChild(extensionValue); |
| 29 | |
| 30 | root->getSize(); |
| 31 | |
| 32 | return root; |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | Blob |
Jeff Thompson | 9afac39 | 2013-12-20 10:42:15 -0800 | [diff] [blame] | 36 | CertificateExtension::toDerBlob() const |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 37 | { |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 38 | blob_stream blobStream; |
Jeff Thompson | 6154ae2 | 2013-10-18 10:44:57 -0700 | [diff] [blame] | 39 | der::OutputIterator& start = reinterpret_cast<der::OutputIterator&>(blobStream); |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 40 | |
| 41 | toDer()->encode(start); |
| 42 | |
| 43 | return blobStream.buf(); |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | |
| 47 | } |