blob: 86ab52d5298ca1d32cb16151885d2ca92554859b [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
32using namespace std;
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080033using namespace CryptoPP;
Jeff Thompson958bf9b2013-10-12 17:20:51 -070034
35namespace ndn {
36
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080037void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070038CertificateSubjectDescription::encode(CryptoPP::BufferedTransformation& out) const
Jeff Thompson958bf9b2013-10-12 17:20:51 -070039{
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080040 // RelativeDistinguishedName ::=
41 // SET OF AttributeTypeAndValue
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070042 //
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080043 // AttributeTypeAndValue ::= SEQUENCE {
44 // type AttributeType,
45 // value AttributeValue }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070046 //
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080047 // AttributeType ::= OBJECT IDENTIFIER
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070048 //
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080049 // AttributeValue ::= ANY DEFINED BY AttributeType
50 DERSequenceEncoder attributeTypeAndValue(out);
51 {
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070052 m_oid.encode(attributeTypeAndValue);
53 DEREncodeTextString(attributeTypeAndValue, m_value, PRINTABLE_STRING);
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080054 }
55 attributeTypeAndValue.MessageEnd();
56}
Jeff Thompson958bf9b2013-10-12 17:20:51 -070057
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080058void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070059CertificateSubjectDescription::decode(CryptoPP::BufferedTransformation& in)
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080060{
61 // RelativeDistinguishedName ::=
62 // SET OF AttributeTypeAndValue
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070063 //
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080064 // AttributeTypeAndValue ::= SEQUENCE {
65 // type AttributeType,
66 // value AttributeValue }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070067 //
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080068 // AttributeType ::= OBJECT IDENTIFIER
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070069 //
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080070 // AttributeValue ::= ANY DEFINED BY AttributeType
Jeff Thompson958bf9b2013-10-12 17:20:51 -070071
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080072 BERSequenceDecoder attributeTypeAndValue(in);
73 {
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070074 m_oid.decode(attributeTypeAndValue);
Jeff Thompson958bf9b2013-10-12 17:20:51 -070075
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080076 /// @todo May be add more intelligent processing, since the following
77 /// may fail if somebody encoded attribute that uses non PRINTABLE_STRING as value
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070078 BERDecodeTextString(attributeTypeAndValue, m_value, PRINTABLE_STRING);
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080079 }
80 attributeTypeAndValue.MessageEnd();
Jeff Thompson958bf9b2013-10-12 17:20:51 -070081}
82
Yingdi Yufc40d872014-02-18 12:56:04 -080083} // namespace ndn