blob: 60f7dbb9d9a6ae2e77d62495338cb7bd68651065 [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Jeff Thompson958bf9b2013-10-12 17:20:51 -07002/**
Alexander Afanasyevc169a812014-05-20 20:37:29 -04003 * Copyright (c) 2013-2014 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -070020 *
21 * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/>
22 * @author Jeff Thompson <jefft0@remap.ucla.edu>
23 * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
Jeff Thompson958bf9b2013-10-12 17:20:51 -070024 */
25
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080026#include "common.hpp"
27
28#include "certificate-subject-description.hpp"
29
Junxiao Shi482ccc52014-03-31 13:05:24 -070030#include "cryptopp.hpp"
Jeff Thompson958bf9b2013-10-12 17:20:51 -070031
Jeff Thompson958bf9b2013-10-12 17:20:51 -070032namespace ndn {
33
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080034void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070035CertificateSubjectDescription::encode(CryptoPP::BufferedTransformation& out) const
Jeff Thompson958bf9b2013-10-12 17:20:51 -070036{
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070037 using namespace CryptoPP;
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080038 // RelativeDistinguishedName ::=
39 // SET OF AttributeTypeAndValue
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070040 //
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080041 // AttributeTypeAndValue ::= SEQUENCE {
42 // type AttributeType,
43 // value AttributeValue }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070044 //
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080045 // AttributeType ::= OBJECT IDENTIFIER
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070046 //
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080047 // AttributeValue ::= ANY DEFINED BY AttributeType
48 DERSequenceEncoder attributeTypeAndValue(out);
49 {
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070050 m_oid.encode(attributeTypeAndValue);
51 DEREncodeTextString(attributeTypeAndValue, m_value, PRINTABLE_STRING);
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080052 }
53 attributeTypeAndValue.MessageEnd();
54}
Jeff Thompson958bf9b2013-10-12 17:20:51 -070055
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080056void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070057CertificateSubjectDescription::decode(CryptoPP::BufferedTransformation& in)
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080058{
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070059 using namespace CryptoPP;
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080060 // RelativeDistinguishedName ::=
61 // SET OF AttributeTypeAndValue
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070062 //
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080063 // AttributeTypeAndValue ::= SEQUENCE {
64 // type AttributeType,
65 // value AttributeValue }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070066 //
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080067 // AttributeType ::= OBJECT IDENTIFIER
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070068 //
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080069 // AttributeValue ::= ANY DEFINED BY AttributeType
Jeff Thompson958bf9b2013-10-12 17:20:51 -070070
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080071 BERSequenceDecoder attributeTypeAndValue(in);
72 {
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070073 m_oid.decode(attributeTypeAndValue);
Jeff Thompson958bf9b2013-10-12 17:20:51 -070074
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080075 /// @todo May be add more intelligent processing, since the following
76 /// may fail if somebody encoded attribute that uses non PRINTABLE_STRING as value
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070077 BERDecodeTextString(attributeTypeAndValue, m_value, PRINTABLE_STRING);
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080078 }
79 attributeTypeAndValue.MessageEnd();
Jeff Thompson958bf9b2013-10-12 17:20:51 -070080}
81
Yingdi Yufc40d872014-02-18 12:56:04 -080082} // namespace ndn