blob: e3ceff6dfeab1a045642886b6352ae4b5e6cad7a [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
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -08009#include "common.hpp"
10
11#include "certificate-extension.hpp"
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080012#include <cryptopp/asn.h>
Jeff Thompson958bf9b2013-10-12 17:20:51 -070013
14using namespace std;
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080015using namespace CryptoPP;
Jeff Thompson958bf9b2013-10-12 17:20:51 -070016
17namespace ndn {
18
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080019void
20CertificateExtension::encode(CryptoPP::BufferedTransformation &out) const
Jeff Thompson958bf9b2013-10-12 17:20:51 -070021{
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080022 // Extension ::= SEQUENCE {
23 // extnID OBJECT IDENTIFIER,
24 // critical BOOLEAN DEFAULT FALSE,
25 // extnValue OCTET STRING }
Jeff Thompson958bf9b2013-10-12 17:20:51 -070026
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080027 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 Thompson958bf9b2013-10-12 17:20:51 -070034}
35
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080036void
37CertificateExtension::decode(CryptoPP::BufferedTransformation &in)
Jeff Thompson958bf9b2013-10-12 17:20:51 -070038{
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080039 // Extension ::= SEQUENCE {
40 // extnID OBJECT IDENTIFIER,
41 // critical BOOLEAN DEFAULT FALSE,
42 // extnValue OCTET STRING }
Jeff Thompson958bf9b2013-10-12 17:20:51 -070043
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080044 BERSequenceDecoder extension(in);
45 {
46 extensionId_.decode(extension);
47 BERDecodeUnsigned(extension, isCritical_, BOOLEAN);
Jeff Thompson958bf9b2013-10-12 17:20:51 -070048
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080049 // 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 Thompson958bf9b2013-10-12 17:20:51 -070056}
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080057
Jeff Thompson958bf9b2013-10-12 17:20:51 -070058}