blob: 51c29ed008c19c0b4a8174969d20b9550ee256d9 [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 <ndn-cpp/security/certificate/certificate-extension.hpp>
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080010#include <cryptopp/asn.h>
Jeff Thompson958bf9b2013-10-12 17:20:51 -070011
12using namespace std;
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080013using namespace CryptoPP;
Jeff Thompson958bf9b2013-10-12 17:20:51 -070014
15namespace ndn {
16
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080017void
18CertificateExtension::encode(CryptoPP::BufferedTransformation &out) const
Jeff Thompson958bf9b2013-10-12 17:20:51 -070019{
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080020 // Extension ::= SEQUENCE {
21 // extnID OBJECT IDENTIFIER,
22 // critical BOOLEAN DEFAULT FALSE,
23 // extnValue OCTET STRING }
Jeff Thompson958bf9b2013-10-12 17:20:51 -070024
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080025 DERSequenceEncoder extension(out);
26 {
27 extensionId_.encode(extension);
28 DEREncodeUnsigned(extension, isCritical_, BOOLEAN);
29 DEREncodeOctetString(extension, extensionValue_.buf(), extensionValue_.size());
30 }
31 extension.MessageEnd();
Jeff Thompson958bf9b2013-10-12 17:20:51 -070032}
33
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080034void
35CertificateExtension::decode(CryptoPP::BufferedTransformation &in)
Jeff Thompson958bf9b2013-10-12 17:20:51 -070036{
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080037 // Extension ::= SEQUENCE {
38 // extnID OBJECT IDENTIFIER,
39 // critical BOOLEAN DEFAULT FALSE,
40 // extnValue OCTET STRING }
Jeff Thompson958bf9b2013-10-12 17:20:51 -070041
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080042 BERSequenceDecoder extension(in);
43 {
44 extensionId_.decode(extension);
45 BERDecodeUnsigned(extension, isCritical_, BOOLEAN);
Jeff Thompson958bf9b2013-10-12 17:20:51 -070046
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080047 // the extra copy operation can be optimized, but not trivial,
48 // since the length is not known in advance
49 SecByteBlock tmpBlock;
50 BERDecodeOctetString(extension, tmpBlock);
51 extensionValue_.assign(tmpBlock.begin(), tmpBlock.end());
52 }
53 extension.MessageEnd();
Jeff Thompson958bf9b2013-10-12 17:20:51 -070054}
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080055
Jeff Thompson958bf9b2013-10-12 17:20:51 -070056}