Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 1 | /* -*- 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 Afanasyev | 736708b | 2014-01-06 14:45:34 -0800 | [diff] [blame] | 9 | #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 Afanasyev | 736708b | 2014-01-06 14:45:34 -0800 | [diff] [blame] | 17 | #pragma GCC diagnostic ignored "-Wunused-variable" |
| 18 | #pragma GCC diagnostic ignored "-Wunused-function" |
| 19 | #endif |
| 20 | |
Yingdi Yu | 4f32463 | 2014-01-15 18:10:03 -0800 | [diff] [blame] | 21 | #include <ndn-cpp/security/certificate-subject-description.hpp> |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 22 | #include <cryptopp/asn.h> |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 23 | |
| 24 | using namespace std; |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 25 | using namespace CryptoPP; |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 26 | |
| 27 | namespace ndn { |
| 28 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 29 | void |
| 30 | CertificateSubjectDescription::encode(CryptoPP::BufferedTransformation &out) const |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 31 | { |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 32 | // 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 Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 49 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 50 | void |
| 51 | CertificateSubjectDescription::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 Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 63 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 64 | BERSequenceDecoder attributeTypeAndValue(in); |
| 65 | { |
| 66 | oid_.decode(attributeTypeAndValue); |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 67 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 68 | /// @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 Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | } |