blob: e2636db201e0f47b222184645616bacf824b9e48 [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"
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 Thompson958bf9b2013-10-12 17:20:51 -070022#include <ndn-cpp/security/certificate/certificate-extension.hpp>
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080023#include <cryptopp/asn.h>
Jeff Thompson958bf9b2013-10-12 17:20:51 -070024
25using namespace std;
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080026using namespace CryptoPP;
Jeff Thompson958bf9b2013-10-12 17:20:51 -070027
28namespace ndn {
29
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080030void
31CertificateExtension::encode(CryptoPP::BufferedTransformation &out) const
Jeff Thompson958bf9b2013-10-12 17:20:51 -070032{
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080033 // Extension ::= SEQUENCE {
34 // extnID OBJECT IDENTIFIER,
35 // critical BOOLEAN DEFAULT FALSE,
36 // extnValue OCTET STRING }
Jeff Thompson958bf9b2013-10-12 17:20:51 -070037
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080038 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 Thompson958bf9b2013-10-12 17:20:51 -070045}
46
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080047void
48CertificateExtension::decode(CryptoPP::BufferedTransformation &in)
Jeff Thompson958bf9b2013-10-12 17:20:51 -070049{
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080050 // Extension ::= SEQUENCE {
51 // extnID OBJECT IDENTIFIER,
52 // critical BOOLEAN DEFAULT FALSE,
53 // extnValue OCTET STRING }
Jeff Thompson958bf9b2013-10-12 17:20:51 -070054
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080055 BERSequenceDecoder extension(in);
56 {
57 extensionId_.decode(extension);
58 BERDecodeUnsigned(extension, isCritical_, BOOLEAN);
Jeff Thompson958bf9b2013-10-12 17:20:51 -070059
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080060 // 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 Thompson958bf9b2013-10-12 17:20:51 -070067}
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080068
Jeff Thompson958bf9b2013-10-12 17:20:51 -070069}