blob: 63e7b0bec397b7fda1f4696cbfba0f7792bb9d0c [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
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080013#include <cryptopp/asn.h>
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
21CertificateSubjectDescription::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
25 //
26 // AttributeTypeAndValue ::= SEQUENCE {
27 // type AttributeType,
28 // value AttributeValue }
29 //
30 // AttributeType ::= OBJECT IDENTIFIER
31 //
32 // AttributeValue ::= ANY DEFINED BY AttributeType
33 DERSequenceEncoder attributeTypeAndValue(out);
34 {
35 oid_.encode(attributeTypeAndValue);
36 DEREncodeTextString(attributeTypeAndValue, value_, PRINTABLE_STRING);
37 }
38 attributeTypeAndValue.MessageEnd();
39}
Jeff Thompson958bf9b2013-10-12 17:20:51 -070040
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080041void
42CertificateSubjectDescription::decode(CryptoPP::BufferedTransformation &in)
43{
44 // RelativeDistinguishedName ::=
45 // SET OF AttributeTypeAndValue
46 //
47 // AttributeTypeAndValue ::= SEQUENCE {
48 // type AttributeType,
49 // value AttributeValue }
50 //
51 // AttributeType ::= OBJECT IDENTIFIER
52 //
53 // 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 {
57 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
61 BERDecodeTextString(attributeTypeAndValue, value_, PRINTABLE_STRING);
62 }
63 attributeTypeAndValue.MessageEnd();
Jeff Thompson958bf9b2013-10-12 17:20:51 -070064}
65
66}