blob: daa1e5222d3db86ecf5596f9b7cc5c6cddaf3082 [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 Afanasyev736708b2014-01-06 14:45:34 -08009#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"
Alexander Afanasyev736708b2014-01-06 14:45:34 -080017#pragma GCC diagnostic ignored "-Wunused-variable"
18#pragma GCC diagnostic ignored "-Wunused-function"
19#endif
20
Jeff Thompson958bf9b2013-10-12 17:20:51 -070021#include <ndn-cpp/security/certificate/certificate-extension.hpp>
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080022#include <cryptopp/asn.h>
Jeff Thompson958bf9b2013-10-12 17:20:51 -070023
24using namespace std;
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080025using namespace CryptoPP;
Jeff Thompson958bf9b2013-10-12 17:20:51 -070026
27namespace ndn {
28
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080029void
30CertificateExtension::encode(CryptoPP::BufferedTransformation &out) const
Jeff Thompson958bf9b2013-10-12 17:20:51 -070031{
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080032 // Extension ::= SEQUENCE {
33 // extnID OBJECT IDENTIFIER,
34 // critical BOOLEAN DEFAULT FALSE,
35 // extnValue OCTET STRING }
Jeff Thompson958bf9b2013-10-12 17:20:51 -070036
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080037 DERSequenceEncoder extension(out);
38 {
39 extensionId_.encode(extension);
40 DEREncodeUnsigned(extension, isCritical_, BOOLEAN);
41 DEREncodeOctetString(extension, extensionValue_.buf(), extensionValue_.size());
42 }
43 extension.MessageEnd();
Jeff Thompson958bf9b2013-10-12 17:20:51 -070044}
45
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080046void
47CertificateExtension::decode(CryptoPP::BufferedTransformation &in)
Jeff Thompson958bf9b2013-10-12 17:20:51 -070048{
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080049 // Extension ::= SEQUENCE {
50 // extnID OBJECT IDENTIFIER,
51 // critical BOOLEAN DEFAULT FALSE,
52 // extnValue OCTET STRING }
Jeff Thompson958bf9b2013-10-12 17:20:51 -070053
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080054 BERSequenceDecoder extension(in);
55 {
56 extensionId_.decode(extension);
57 BERDecodeUnsigned(extension, isCritical_, BOOLEAN);
Jeff Thompson958bf9b2013-10-12 17:20:51 -070058
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080059 // the extra copy operation can be optimized, but not trivial,
60 // since the length is not known in advance
61 SecByteBlock tmpBlock;
62 BERDecodeOctetString(extension, tmpBlock);
63 extensionValue_.assign(tmpBlock.begin(), tmpBlock.end());
64 }
65 extension.MessageEnd();
Jeff Thompson958bf9b2013-10-12 17:20:51 -070066}
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080067
Jeff Thompson958bf9b2013-10-12 17:20:51 -070068}