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 | 09c613f | 2014-01-29 00:23:58 -0800 | [diff] [blame] | 9 | #include "security/certificate-subject-description.hpp" |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 10 | #include <cryptopp/asn.h> |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 11 | |
| 12 | using namespace std; |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 13 | using namespace CryptoPP; |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 14 | |
| 15 | namespace ndn { |
| 16 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 17 | void |
| 18 | CertificateSubjectDescription::encode(CryptoPP::BufferedTransformation &out) const |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 19 | { |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 20 | // 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 Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 37 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 38 | void |
| 39 | CertificateSubjectDescription::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 Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 51 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 52 | BERSequenceDecoder attributeTypeAndValue(in); |
| 53 | { |
| 54 | oid_.decode(attributeTypeAndValue); |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 55 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 56 | /// @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 Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | } |