certificate-extension.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #include "cryptopp.hpp"
27 
28 namespace ndn {
29 namespace security {
30 namespace v1 {
31 
32 void
33 CertificateExtension::encode(CryptoPP::BufferedTransformation& out) const
34 {
35  using namespace CryptoPP;
36 
37  // Extension ::= SEQUENCE {
38  // extnID OBJECT IDENTIFIER,
39  // critical BOOLEAN DEFAULT FALSE,
40  // extnValue OCTET STRING }
41 
42  DERSequenceEncoder extension(out);
43  {
44  m_extensionId.encode(extension);
45  DEREncodeUnsigned(extension, m_isCritical, BOOLEAN);
46  DEREncodeOctetString(extension, m_extensionValue.buf(), m_extensionValue.size());
47  }
48  extension.MessageEnd();
49 }
50 
51 void
52 CertificateExtension::decode(CryptoPP::BufferedTransformation& in)
53 {
54  using namespace CryptoPP;
55 
56  // Extension ::= SEQUENCE {
57  // extnID OBJECT IDENTIFIER,
58  // critical BOOLEAN DEFAULT FALSE,
59  // extnValue OCTET STRING }
60 
61  BERSequenceDecoder extension(in);
62  {
63  m_extensionId.decode(extension);
64  BERDecodeUnsigned(extension, m_isCritical, BOOLEAN);
65 
66  // the extra copy operation can be optimized, but not trivial,
67  // since the length is not known in advance
68  SecByteBlock tmpBlock;
69  BERDecodeOctetString(extension, tmpBlock);
70  m_extensionValue.assign(tmpBlock.begin(), tmpBlock.end());
71  }
72  extension.MessageEnd();
73 }
74 
75 } // namespace v1
76 } // namespace security
77 } // namespace ndn
void decode(CryptoPP::BufferedTransformation &in)
Definition: oid.cpp:135
Copyright (c) 2013-2017 Regents of the University of California.
Definition: common.hpp:75
Copyright (c) 2013-2017 Regents of the University of California.
Definition: oid.hpp:29
void encode(CryptoPP::BufferedTransformation &out) const
Definition: oid.cpp:118
uint8_t * buf()
Definition: buffer.hpp:87
void encode(CryptoPP::BufferedTransformation &out) const
void decode(CryptoPP::BufferedTransformation &in)