1 /**
2 * ASN.1 Attribute
3 * 
4 * Copyright:
5 * (C) 1999-2007,2012 Jack Lloyd
6 * (C) 2014-2015 Etienne Cimon
7 *
8 * License:
9 * Botan is released under the Simplified BSD License (see LICENSE.md)
10 */
11 
12 module botan.asn1.asn1_attribute;
13 
14 import botan.constants;
15 static if (BOTAN_HAS_PUBLIC_KEY_CRYPTO):
16 
17 import botan.asn1.der_enc;
18 import botan.asn1.ber_dec;
19 import botan.asn1.oids;
20 import botan.asn1.asn1_obj;
21 import botan.asn1.asn1_oid;
22 import botan.utils.types;
23 
24 alias Attribute = RefCounted!AttributeImpl;
25 
26 /**
27 * Attribute
28 */
29 final class AttributeImpl : ASN1Object
30 {
31 public:
32     this() { }
33 
34     /*
35     * Create an Attribute
36     */
37     this(OID attr_oid, ref Vector!ubyte attr_value)
38     {
39         oid = attr_oid;
40         parameters = attr_value.dup;
41     }
42     
43     /*
44     * Create an Attribute
45     */
46     this(in string attr_oid, ref Vector!ubyte attr_value)
47     {
48         oid = OIDS.lookup(attr_oid);
49         parameters = attr_value.dup;
50     }
51     
52     /*
53     * DER encode a Attribute
54     */
55     override void encodeInto(ref DEREncoder codec) const
56     {
57         codec.startCons(ASN1Tag.SEQUENCE)
58                 .encode(oid)
59                 .startCons(ASN1Tag.SET)
60                 .rawBytes(parameters)
61                 .endCons()
62                 .endCons();
63     }
64     
65     /*
66     * Decode a BER encoded Attribute
67     */
68     override void decodeFrom(ref BERDecoder codec)
69     {
70         codec.startCons(ASN1Tag.SEQUENCE)
71                 .decode(oid)
72                 .startCons(ASN1Tag.SET)
73                 .rawBytes(parameters)
74                 .endCons()
75                 .endCons();
76     }
77 
78     OID oid;
79     Vector!ubyte parameters;
80 }
81 
82