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 | |
Alexander Afanasyev | e2dcdfd | 2014-02-07 15:53:28 -0800 | [diff] [blame] | 9 | #include "common.hpp" |
| 10 | |
| 11 | #include "certificate-extension.hpp" |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 12 | #include <cryptopp/asn.h> |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 13 | |
| 14 | using namespace std; |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 15 | using namespace CryptoPP; |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 16 | |
| 17 | namespace ndn { |
| 18 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 19 | void |
| 20 | CertificateExtension::encode(CryptoPP::BufferedTransformation &out) const |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 21 | { |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 22 | // Extension ::= SEQUENCE { |
| 23 | // extnID OBJECT IDENTIFIER, |
| 24 | // critical BOOLEAN DEFAULT FALSE, |
| 25 | // extnValue OCTET STRING } |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 26 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 27 | DERSequenceEncoder extension(out); |
| 28 | { |
| 29 | extensionId_.encode(extension); |
| 30 | DEREncodeUnsigned(extension, isCritical_, BOOLEAN); |
| 31 | DEREncodeOctetString(extension, extensionValue_.buf(), extensionValue_.size()); |
| 32 | } |
| 33 | extension.MessageEnd(); |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 34 | } |
| 35 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 36 | void |
| 37 | CertificateExtension::decode(CryptoPP::BufferedTransformation &in) |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 38 | { |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 39 | // Extension ::= SEQUENCE { |
| 40 | // extnID OBJECT IDENTIFIER, |
| 41 | // critical BOOLEAN DEFAULT FALSE, |
| 42 | // extnValue OCTET STRING } |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 43 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 44 | BERSequenceDecoder extension(in); |
| 45 | { |
| 46 | extensionId_.decode(extension); |
| 47 | BERDecodeUnsigned(extension, isCritical_, BOOLEAN); |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 48 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 49 | // 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); |
| 53 | extensionValue_.assign(tmpBlock.begin(), tmpBlock.end()); |
| 54 | } |
| 55 | extension.MessageEnd(); |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 56 | } |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 57 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame^] | 58 | } // namespace ndn |