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" |
| 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 Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 22 | #include <ndn-cpp/security/certificate/certificate-subject-description.hpp> |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 23 | #include <cryptopp/asn.h> |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 24 | |
| 25 | using namespace std; |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 26 | using namespace CryptoPP; |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 27 | |
| 28 | namespace ndn { |
| 29 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 30 | void |
| 31 | CertificateSubjectDescription::encode(CryptoPP::BufferedTransformation &out) const |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 32 | { |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 33 | // 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 Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 50 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 51 | void |
| 52 | CertificateSubjectDescription::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 Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 64 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 65 | BERSequenceDecoder attributeTypeAndValue(in); |
| 66 | { |
| 67 | oid_.decode(attributeTypeAndValue); |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 68 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 69 | /// @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 Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | } |