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 | e2dcdfd | 2014-02-07 15:53:28 -0800 | [diff] [blame] | 9 | #include "common.hpp" |
| 10 | |
| 11 | #include "certificate-subject-description.hpp" |
| 12 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 13 | #include <cryptopp/asn.h> |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 14 | |
| 15 | using namespace std; |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 16 | using namespace CryptoPP; |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 17 | |
| 18 | namespace ndn { |
| 19 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 20 | void |
| 21 | CertificateSubjectDescription::encode(CryptoPP::BufferedTransformation &out) const |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 22 | { |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 23 | // RelativeDistinguishedName ::= |
| 24 | // SET OF AttributeTypeAndValue |
| 25 | // |
| 26 | // AttributeTypeAndValue ::= SEQUENCE { |
| 27 | // type AttributeType, |
| 28 | // value AttributeValue } |
| 29 | // |
| 30 | // AttributeType ::= OBJECT IDENTIFIER |
| 31 | // |
| 32 | // AttributeValue ::= ANY DEFINED BY AttributeType |
| 33 | DERSequenceEncoder attributeTypeAndValue(out); |
| 34 | { |
| 35 | oid_.encode(attributeTypeAndValue); |
| 36 | DEREncodeTextString(attributeTypeAndValue, value_, PRINTABLE_STRING); |
| 37 | } |
| 38 | attributeTypeAndValue.MessageEnd(); |
| 39 | } |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 40 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 41 | void |
| 42 | CertificateSubjectDescription::decode(CryptoPP::BufferedTransformation &in) |
| 43 | { |
| 44 | // RelativeDistinguishedName ::= |
| 45 | // SET OF AttributeTypeAndValue |
| 46 | // |
| 47 | // AttributeTypeAndValue ::= SEQUENCE { |
| 48 | // type AttributeType, |
| 49 | // value AttributeValue } |
| 50 | // |
| 51 | // AttributeType ::= OBJECT IDENTIFIER |
| 52 | // |
| 53 | // AttributeValue ::= ANY DEFINED BY AttributeType |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 54 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 55 | BERSequenceDecoder attributeTypeAndValue(in); |
| 56 | { |
| 57 | oid_.decode(attributeTypeAndValue); |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 58 | |
Alexander Afanasyev | 0ea6e08 | 2013-12-26 15:16:37 -0800 | [diff] [blame] | 59 | /// @todo May be add more intelligent processing, since the following |
| 60 | /// may fail if somebody encoded attribute that uses non PRINTABLE_STRING as value |
| 61 | BERDecodeTextString(attributeTypeAndValue, value_, PRINTABLE_STRING); |
| 62 | } |
| 63 | attributeTypeAndValue.MessageEnd(); |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | } |