blob: de7283c66f489ebf235bae18e32090bf56ac54fc [file] [log] [blame]
Jeff Thompson958bf9b2013-10-12 17:20:51 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07003 * Copyright (c) 2013-2014, Regents of the University of California.
4 * All rights reserved.
5 *
6 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
7 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
8 *
9 * This file licensed under New BSD License. See COPYING for detailed information about
10 * ndn-cxx library copyright, permissions, and redistribution restrictions.
11 *
12 * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/>
13 * @author Jeff Thompson <jefft0@remap.ucla.edu>
14 * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
Jeff Thompson958bf9b2013-10-12 17:20:51 -070015 */
16
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080017#include "common.hpp"
18
19#include "certificate-subject-description.hpp"
20
Junxiao Shi482ccc52014-03-31 13:05:24 -070021#include "cryptopp.hpp"
Jeff Thompson958bf9b2013-10-12 17:20:51 -070022
23using namespace std;
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080024using namespace CryptoPP;
Jeff Thompson958bf9b2013-10-12 17:20:51 -070025
26namespace ndn {
27
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080028void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070029CertificateSubjectDescription::encode(CryptoPP::BufferedTransformation& out) const
Jeff Thompson958bf9b2013-10-12 17:20:51 -070030{
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080031 // RelativeDistinguishedName ::=
32 // SET OF AttributeTypeAndValue
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070033 //
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080034 // AttributeTypeAndValue ::= SEQUENCE {
35 // type AttributeType,
36 // value AttributeValue }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070037 //
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080038 // AttributeType ::= OBJECT IDENTIFIER
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070039 //
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080040 // AttributeValue ::= ANY DEFINED BY AttributeType
41 DERSequenceEncoder attributeTypeAndValue(out);
42 {
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070043 m_oid.encode(attributeTypeAndValue);
44 DEREncodeTextString(attributeTypeAndValue, m_value, PRINTABLE_STRING);
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080045 }
46 attributeTypeAndValue.MessageEnd();
47}
Jeff Thompson958bf9b2013-10-12 17:20:51 -070048
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080049void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070050CertificateSubjectDescription::decode(CryptoPP::BufferedTransformation& in)
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080051{
52 // RelativeDistinguishedName ::=
53 // SET OF AttributeTypeAndValue
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070054 //
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080055 // AttributeTypeAndValue ::= SEQUENCE {
56 // type AttributeType,
57 // value AttributeValue }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070058 //
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080059 // AttributeType ::= OBJECT IDENTIFIER
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070060 //
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080061 // AttributeValue ::= ANY DEFINED BY AttributeType
Jeff Thompson958bf9b2013-10-12 17:20:51 -070062
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080063 BERSequenceDecoder attributeTypeAndValue(in);
64 {
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070065 m_oid.decode(attributeTypeAndValue);
Jeff Thompson958bf9b2013-10-12 17:20:51 -070066
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080067 /// @todo May be add more intelligent processing, since the following
68 /// may fail if somebody encoded attribute that uses non PRINTABLE_STRING as value
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070069 BERDecodeTextString(attributeTypeAndValue, m_value, PRINTABLE_STRING);
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080070 }
71 attributeTypeAndValue.MessageEnd();
Jeff Thompson958bf9b2013-10-12 17:20:51 -070072}
73
Yingdi Yufc40d872014-02-18 12:56:04 -080074} // namespace ndn