blob: 5c257d457a526a47bddd1746df8c2a381582f3ac [file] [log] [blame]
Jeff Thompson958bf9b2013-10-12 17:20:51 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
3 * Copyright (C) 2013 Regents of the University of California.
4 * @author: Yingdi Yu <yingdi@cs.ucla.edu>
5 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
6 * See COPYING for copyright and distribution information.
7 */
8
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -08009#include "common.hpp"
10
11#include "certificate-subject-description.hpp"
12
Junxiao Shi482ccc52014-03-31 13:05:24 -070013#include "cryptopp.hpp"
Jeff Thompson958bf9b2013-10-12 17:20:51 -070014
15using namespace std;
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080016using namespace CryptoPP;
Jeff Thompson958bf9b2013-10-12 17:20:51 -070017
18namespace ndn {
19
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080020void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070021CertificateSubjectDescription::encode(CryptoPP::BufferedTransformation& out) const
Jeff Thompson958bf9b2013-10-12 17:20:51 -070022{
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080023 // RelativeDistinguishedName ::=
24 // SET OF AttributeTypeAndValue
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070025 //
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080026 // AttributeTypeAndValue ::= SEQUENCE {
27 // type AttributeType,
28 // value AttributeValue }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070029 //
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080030 // AttributeType ::= OBJECT IDENTIFIER
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070031 //
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080032 // AttributeValue ::= ANY DEFINED BY AttributeType
33 DERSequenceEncoder attributeTypeAndValue(out);
34 {
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070035 m_oid.encode(attributeTypeAndValue);
36 DEREncodeTextString(attributeTypeAndValue, m_value, PRINTABLE_STRING);
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080037 }
38 attributeTypeAndValue.MessageEnd();
39}
Jeff Thompson958bf9b2013-10-12 17:20:51 -070040
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080041void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070042CertificateSubjectDescription::decode(CryptoPP::BufferedTransformation& in)
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080043{
44 // RelativeDistinguishedName ::=
45 // SET OF AttributeTypeAndValue
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070046 //
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080047 // AttributeTypeAndValue ::= SEQUENCE {
48 // type AttributeType,
49 // value AttributeValue }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070050 //
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080051 // AttributeType ::= OBJECT IDENTIFIER
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070052 //
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080053 // AttributeValue ::= ANY DEFINED BY AttributeType
Jeff Thompson958bf9b2013-10-12 17:20:51 -070054
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080055 BERSequenceDecoder attributeTypeAndValue(in);
56 {
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070057 m_oid.decode(attributeTypeAndValue);
Jeff Thompson958bf9b2013-10-12 17:20:51 -070058
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080059 /// @todo May be add more intelligent processing, since the following
60 /// may fail if somebody encoded attribute that uses non PRINTABLE_STRING as value
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070061 BERDecodeTextString(attributeTypeAndValue, m_value, PRINTABLE_STRING);
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080062 }
63 attributeTypeAndValue.MessageEnd();
Jeff Thompson958bf9b2013-10-12 17:20:51 -070064}
65
Yingdi Yufc40d872014-02-18 12:56:04 -080066} // namespace ndn