All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
certificate-extension.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
9 #include "common.hpp"
10 
12 #include "cryptopp.hpp"
13 
14 using namespace std;
15 using namespace CryptoPP;
16 
17 namespace ndn {
18 
19 void
20 CertificateExtension::encode(CryptoPP::BufferedTransformation& out) const
21 {
22  // Extension ::= SEQUENCE {
23  // extnID OBJECT IDENTIFIER,
24  // critical BOOLEAN DEFAULT FALSE,
25  // extnValue OCTET STRING }
26 
27  DERSequenceEncoder extension(out);
28  {
29  m_extensionId.encode(extension);
30  DEREncodeUnsigned(extension, m_isCritical, BOOLEAN);
31  DEREncodeOctetString(extension, m_extensionValue.buf(), m_extensionValue.size());
32  }
33  extension.MessageEnd();
34 }
35 
36 void
37 CertificateExtension::decode(CryptoPP::BufferedTransformation& in)
38 {
39  // Extension ::= SEQUENCE {
40  // extnID OBJECT IDENTIFIER,
41  // critical BOOLEAN DEFAULT FALSE,
42  // extnValue OCTET STRING }
43 
44  BERSequenceDecoder extension(in);
45  {
46  m_extensionId.decode(extension);
47  BERDecodeUnsigned(extension, m_isCritical, BOOLEAN);
48 
49  // 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  m_extensionValue.assign(tmpBlock.begin(), tmpBlock.end());
54  }
55  extension.MessageEnd();
56 }
57 
58 } // namespace ndn