blob: 73c0c1b1d1fcb424d29cd2feb0d8f74e0b509799 [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"
Alexander Afanasyev736708b2014-01-06 14:45:34 -080017#pragma GCC diagnostic ignored "-Wunused-variable"
18#pragma GCC diagnostic ignored "-Wunused-function"
19#endif
20
Alexander Afanasyev09c613f2014-01-29 00:23:58 -080021#include "security/certificate-subject-description.hpp"
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080022#include <cryptopp/asn.h>
Jeff Thompson958bf9b2013-10-12 17:20:51 -070023
24using namespace std;
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080025using namespace CryptoPP;
Jeff Thompson958bf9b2013-10-12 17:20:51 -070026
27namespace ndn {
28
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080029void
30CertificateSubjectDescription::encode(CryptoPP::BufferedTransformation &out) const
Jeff Thompson958bf9b2013-10-12 17:20:51 -070031{
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080032 // RelativeDistinguishedName ::=
33 // SET OF AttributeTypeAndValue
34 //
35 // AttributeTypeAndValue ::= SEQUENCE {
36 // type AttributeType,
37 // value AttributeValue }
38 //
39 // AttributeType ::= OBJECT IDENTIFIER
40 //
41 // AttributeValue ::= ANY DEFINED BY AttributeType
42 DERSequenceEncoder attributeTypeAndValue(out);
43 {
44 oid_.encode(attributeTypeAndValue);
45 DEREncodeTextString(attributeTypeAndValue, value_, PRINTABLE_STRING);
46 }
47 attributeTypeAndValue.MessageEnd();
48}
Jeff Thompson958bf9b2013-10-12 17:20:51 -070049
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080050void
51CertificateSubjectDescription::decode(CryptoPP::BufferedTransformation &in)
52{
53 // RelativeDistinguishedName ::=
54 // SET OF AttributeTypeAndValue
55 //
56 // AttributeTypeAndValue ::= SEQUENCE {
57 // type AttributeType,
58 // value AttributeValue }
59 //
60 // AttributeType ::= OBJECT IDENTIFIER
61 //
62 // AttributeValue ::= ANY DEFINED BY AttributeType
Jeff Thompson958bf9b2013-10-12 17:20:51 -070063
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080064 BERSequenceDecoder attributeTypeAndValue(in);
65 {
66 oid_.decode(attributeTypeAndValue);
Jeff Thompson958bf9b2013-10-12 17:20:51 -070067
Alexander Afanasyev0ea6e082013-12-26 15:16:37 -080068 /// @todo May be add more intelligent processing, since the following
69 /// may fail if somebody encoded attribute that uses non PRINTABLE_STRING as value
70 BERDecodeTextString(attributeTypeAndValue, value_, PRINTABLE_STRING);
71 }
72 attributeTypeAndValue.MessageEnd();
Jeff Thompson958bf9b2013-10-12 17:20:51 -070073}
74
75}