blob: c91cb6af8501449ea192826f0b76f66c9392a87d [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 Afanasyev736708b2014-01-06 14:45:34 -08009#if __clang__
10#pragma clang diagnostic push
11#pragma clang diagnostic ignored "-Wreorder"
12#pragma clang diagnostic ignored "-Wtautological-compare"
13#pragma clang diagnostic ignored "-Wunused-variable"
14#pragma clang diagnostic ignored "-Wunused-function"
15#elif __GNUC__
16#pragma GCC diagnostic ignored "-Wreorder"
17#pragma GCC diagnostic ignored "-Wtautological-compare"
18#pragma GCC diagnostic ignored "-Wunused-variable"
19#pragma GCC diagnostic ignored "-Wunused-function"
20#endif
21
Jeff Thompson958bf9b2013-10-12 17:20:51 -070022#include <ndn-cpp/security/certificate/certificate-subject-description.hpp>
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080023#include <cryptopp/asn.h>
Jeff Thompson958bf9b2013-10-12 17:20:51 -070024
25using namespace std;
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080026using namespace CryptoPP;
Jeff Thompson958bf9b2013-10-12 17:20:51 -070027
28namespace ndn {
29
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080030void
31CertificateSubjectDescription::encode(CryptoPP::BufferedTransformation &out) const
Jeff Thompson958bf9b2013-10-12 17:20:51 -070032{
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080033 // RelativeDistinguishedName ::=
34 // SET OF AttributeTypeAndValue
35 //
36 // AttributeTypeAndValue ::= SEQUENCE {
37 // type AttributeType,
38 // value AttributeValue }
39 //
40 // AttributeType ::= OBJECT IDENTIFIER
41 //
42 // AttributeValue ::= ANY DEFINED BY AttributeType
43 DERSequenceEncoder attributeTypeAndValue(out);
44 {
45 oid_.encode(attributeTypeAndValue);
46 DEREncodeTextString(attributeTypeAndValue, value_, PRINTABLE_STRING);
47 }
48 attributeTypeAndValue.MessageEnd();
49}
Jeff Thompson958bf9b2013-10-12 17:20:51 -070050
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080051void
52CertificateSubjectDescription::decode(CryptoPP::BufferedTransformation &in)
53{
54 // RelativeDistinguishedName ::=
55 // SET OF AttributeTypeAndValue
56 //
57 // AttributeTypeAndValue ::= SEQUENCE {
58 // type AttributeType,
59 // value AttributeValue }
60 //
61 // AttributeType ::= OBJECT IDENTIFIER
62 //
63 // AttributeValue ::= ANY DEFINED BY AttributeType
Jeff Thompson958bf9b2013-10-12 17:20:51 -070064
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080065 BERSequenceDecoder attributeTypeAndValue(in);
66 {
67 oid_.decode(attributeTypeAndValue);
Jeff Thompson958bf9b2013-10-12 17:20:51 -070068
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080069 /// @todo May be add more intelligent processing, since the following
70 /// may fail if somebody encoded attribute that uses non PRINTABLE_STRING as value
71 BERDecodeTextString(attributeTypeAndValue, value_, PRINTABLE_STRING);
72 }
73 attributeTypeAndValue.MessageEnd();
Jeff Thompson958bf9b2013-10-12 17:20:51 -070074}
75
76}