blob: fc6156f7e2b2182f81e4dcdea7d2c65d17d7bba7 [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 Afanasyev09c613f2014-01-29 00:23:58 -08009#include "security/certificate-subject-description.hpp"
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080010#include <cryptopp/asn.h>
Jeff Thompson958bf9b2013-10-12 17:20:51 -070011
12using namespace std;
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080013using namespace CryptoPP;
Jeff Thompson958bf9b2013-10-12 17:20:51 -070014
15namespace ndn {
16
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080017void
18CertificateSubjectDescription::encode(CryptoPP::BufferedTransformation &out) const
Jeff Thompson958bf9b2013-10-12 17:20:51 -070019{
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080020 // RelativeDistinguishedName ::=
21 // SET OF AttributeTypeAndValue
22 //
23 // AttributeTypeAndValue ::= SEQUENCE {
24 // type AttributeType,
25 // value AttributeValue }
26 //
27 // AttributeType ::= OBJECT IDENTIFIER
28 //
29 // AttributeValue ::= ANY DEFINED BY AttributeType
30 DERSequenceEncoder attributeTypeAndValue(out);
31 {
32 oid_.encode(attributeTypeAndValue);
33 DEREncodeTextString(attributeTypeAndValue, value_, PRINTABLE_STRING);
34 }
35 attributeTypeAndValue.MessageEnd();
36}
Jeff Thompson958bf9b2013-10-12 17:20:51 -070037
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080038void
39CertificateSubjectDescription::decode(CryptoPP::BufferedTransformation &in)
40{
41 // RelativeDistinguishedName ::=
42 // SET OF AttributeTypeAndValue
43 //
44 // AttributeTypeAndValue ::= SEQUENCE {
45 // type AttributeType,
46 // value AttributeValue }
47 //
48 // AttributeType ::= OBJECT IDENTIFIER
49 //
50 // AttributeValue ::= ANY DEFINED BY AttributeType
Jeff Thompson958bf9b2013-10-12 17:20:51 -070051
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080052 BERSequenceDecoder attributeTypeAndValue(in);
53 {
54 oid_.decode(attributeTypeAndValue);
Jeff Thompson958bf9b2013-10-12 17:20:51 -070055
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080056 /// @todo May be add more intelligent processing, since the following
57 /// may fail if somebody encoded attribute that uses non PRINTABLE_STRING as value
58 BERDecodeTextString(attributeTypeAndValue, value_, PRINTABLE_STRING);
59 }
60 attributeTypeAndValue.MessageEnd();
Jeff Thompson958bf9b2013-10-12 17:20:51 -070061}
62
63}