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 | 736708b | 2014-01-06 14:45:34 -0800 | [diff] [blame] | 9 | #if __clang__ |
| 10 | #pragma clang diagnostic push |
| 11 | #pragma clang diagnostic ignored "-Wreorder" |
| 12 | #pragma clang diagnostic ignored "-Wtautological-compare" |
| 13 | #pragma clang diagnostic ignored "-Wunused-variable" |
| 14 | #pragma clang diagnostic ignored "-Wunused-function" |
| 15 | #elif __GNUC__ |
| 16 | #pragma GCC diagnostic ignored "-Wreorder" |
| 17 | #pragma GCC diagnostic ignored "-Wtautological-compare" |
| 18 | #pragma GCC diagnostic ignored "-Wunused-variable" |
| 19 | #pragma GCC diagnostic ignored "-Wunused-function" |
| 20 | #endif |
| 21 | |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 22 | #include <ndn-cpp/security/certificate/certificate-extension.hpp> |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 23 | #include <cryptopp/asn.h> |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 24 | |
| 25 | using namespace std; |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 26 | using namespace CryptoPP; |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 27 | |
| 28 | namespace ndn { |
| 29 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 30 | void |
| 31 | CertificateExtension::encode(CryptoPP::BufferedTransformation &out) const |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 32 | { |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 33 | // Extension ::= SEQUENCE { |
| 34 | // extnID OBJECT IDENTIFIER, |
| 35 | // critical BOOLEAN DEFAULT FALSE, |
| 36 | // extnValue OCTET STRING } |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 37 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 38 | DERSequenceEncoder extension(out); |
| 39 | { |
| 40 | extensionId_.encode(extension); |
| 41 | DEREncodeUnsigned(extension, isCritical_, BOOLEAN); |
| 42 | DEREncodeOctetString(extension, extensionValue_.buf(), extensionValue_.size()); |
| 43 | } |
| 44 | extension.MessageEnd(); |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 45 | } |
| 46 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 47 | void |
| 48 | CertificateExtension::decode(CryptoPP::BufferedTransformation &in) |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 49 | { |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 50 | // Extension ::= SEQUENCE { |
| 51 | // extnID OBJECT IDENTIFIER, |
| 52 | // critical BOOLEAN DEFAULT FALSE, |
| 53 | // extnValue OCTET STRING } |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 54 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 55 | BERSequenceDecoder extension(in); |
| 56 | { |
| 57 | extensionId_.decode(extension); |
| 58 | BERDecodeUnsigned(extension, isCritical_, BOOLEAN); |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 59 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 60 | // the extra copy operation can be optimized, but not trivial, |
| 61 | // since the length is not known in advance |
| 62 | SecByteBlock tmpBlock; |
| 63 | BERDecodeOctetString(extension, tmpBlock); |
| 64 | extensionValue_.assign(tmpBlock.begin(), tmpBlock.end()); |
| 65 | } |
| 66 | extension.MessageEnd(); |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 67 | } |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 68 | |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 69 | } |