diff options
author | lloyd <[email protected]> | 2010-10-13 14:58:58 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-10-13 14:58:58 +0000 |
commit | 6e85766cf001183e160c8ca2c0ed3eb40f07125c (patch) | |
tree | df11b301786829bc2f6f545038ec97c2269154d9 /src/asn1 | |
parent | fcd3aba1ff6b8597b31165474573dbb339479c14 (diff) | |
parent | bb53c6169463a67cc751625cb0a2c47df129a2ab (diff) |
propagate from branch 'net.randombit.botan' (head 6581b789d58717bc6acee5c6a248e2d44c636e40)
to branch 'net.randombit.botan.c++0x' (head 227a989ae94da8f4379ea4b9b0fc0ee8dbdde0c7)
Diffstat (limited to 'src/asn1')
-rw-r--r-- | src/asn1/asn1_obj.h | 56 | ||||
-rw-r--r-- | src/asn1/asn1_oid.cpp | 40 | ||||
-rw-r--r-- | src/asn1/asn1_str.cpp | 6 | ||||
-rw-r--r-- | src/asn1/asn1_str.h | 38 | ||||
-rw-r--r-- | src/asn1/asn1_tm.cpp | 8 | ||||
-rw-r--r-- | src/asn1/ber_dec.cpp | 42 | ||||
-rw-r--r-- | src/asn1/ber_dec.h | 2 | ||||
-rw-r--r-- | src/asn1/der_enc.cpp | 42 | ||||
-rw-r--r-- | src/asn1/der_enc.h | 14 | ||||
-rw-r--r-- | src/asn1/info.txt | 4 | ||||
-rw-r--r-- | src/asn1/x509_dn.cpp (renamed from src/asn1/asn1_dn.cpp) | 2 | ||||
-rw-r--r-- | src/asn1/x509_dn.h | 54 |
12 files changed, 175 insertions, 133 deletions
diff --git a/src/asn1/asn1_obj.h b/src/asn1/asn1_obj.h index a77f55c79..967aa6d3d 100644 --- a/src/asn1/asn1_obj.h +++ b/src/asn1/asn1_obj.h @@ -11,6 +11,7 @@ #include <botan/asn1_int.h> #include <botan/asn1_oid.h> +#include <botan/asn1_str.h> #include <botan/alg_id.h> #include <vector> #include <map> @@ -63,57 +64,6 @@ class BOTAN_DLL X509_Time : public ASN1_Object }; /** -* Simple String -*/ -class BOTAN_DLL ASN1_String : public ASN1_Object - { - public: - void encode_into(class DER_Encoder&) const; - void decode_from(class BER_Decoder&); - - std::string value() const; - std::string iso_8859() const; - - ASN1_Tag tagging() const; - - ASN1_String(const std::string& = ""); - ASN1_String(const std::string&, ASN1_Tag); - private: - std::string iso_8859_str; - ASN1_Tag tag; - }; - -/** -* Distinguished Name -*/ -class BOTAN_DLL X509_DN : public ASN1_Object - { - public: - void encode_into(class DER_Encoder&) const; - void decode_from(class BER_Decoder&); - - std::multimap<OID, std::string> get_attributes() const; - std::vector<std::string> get_attribute(const std::string&) const; - - std::multimap<std::string, std::string> contents() const; - - void add_attribute(const std::string&, const std::string&); - void add_attribute(const OID&, const std::string&); - - static std::string deref_info_field(const std::string&); - - void do_decode(const MemoryRegion<byte>&); - MemoryVector<byte> get_bits() const; - - X509_DN(); - X509_DN(const std::multimap<OID, std::string>&); - X509_DN(const std::multimap<std::string, std::string>&); - private: - std::multimap<OID, ASN1_String> dn_info; - MemoryVector<byte> dn_bits; - }; - -/** * Alternative Name */ class BOTAN_DLL AlternativeName : public ASN1_Object @@ -149,10 +99,6 @@ bool BOTAN_DLL operator>=(const X509_Time&, const X509_Time&); bool BOTAN_DLL operator<(const X509_Time&, const X509_Time&); bool BOTAN_DLL operator>(const X509_Time&, const X509_Time&); -bool BOTAN_DLL operator==(const X509_DN&, const X509_DN&); -bool BOTAN_DLL operator!=(const X509_DN&, const X509_DN&); -bool BOTAN_DLL operator<(const X509_DN&, const X509_DN&); - /* * Helper Functions */ diff --git a/src/asn1/asn1_oid.cpp b/src/asn1/asn1_oid.cpp index ffe583b90..750eb90f7 100644 --- a/src/asn1/asn1_oid.cpp +++ b/src/asn1/asn1_oid.cpp @@ -50,10 +50,10 @@ void OID::clear() std::string OID::as_string() const { std::string oid_str; - for(u32bit j = 0; j != id.size(); ++j) + for(size_t i = 0; i != id.size(); ++i) { - oid_str += std::to_string(id[j]); - if(j != id.size() - 1) + oid_str += std::to_string(id[i]); + if(i != id.size() - 1) oid_str += '.'; } return oid_str; @@ -66,8 +66,8 @@ bool OID::operator==(const OID& oid) const { if(id.size() != oid.id.size()) return false; - for(u32bit j = 0; j != id.size(); ++j) - if(id[j] != oid.id[j]) + for(size_t i = 0; i != id.size(); ++i) + if(id[i] != oid.id[i]) return false; return true; } @@ -111,11 +111,11 @@ bool operator<(const OID& a, const OID& b) return true; if(oid1.size() > oid2.size()) return false; - for(u32bit j = 0; j != oid1.size(); ++j) + for(size_t i = 0; i != oid1.size(); ++i) { - if(oid1[j] < oid2[j]) + if(oid1[i] < oid2[i]) return true; - if(oid1[j] > oid2[j]) + if(oid1[i] > oid2[i]) return false; } return false; @@ -132,18 +132,18 @@ void OID::encode_into(DER_Encoder& der) const MemoryVector<byte> encoding; encoding.push_back(40 * id[0] + id[1]); - for(u32bit j = 2; j != id.size(); ++j) + for(size_t i = 2; i != id.size(); ++i) { - if(id[j] == 0) + if(id[i] == 0) encoding.push_back(0); else { - u32bit blocks = high_bit(id[j]) + 6; + size_t blocks = high_bit(id[i]) + 6; blocks = (blocks - (blocks % 7)) / 7; - for(u32bit k = 0; k != blocks - 1; ++k) - encoding.push_back(0x80 | ((id[j] >> 7*(blocks-k-1)) & 0x7F)); - encoding.push_back(id[j] & 0x7F); + for(size_t j = 0; j != blocks - 1; ++j) + encoding.push_back(0x80 | ((id[i] >> 7*(blocks-j-1)) & 0x7F)); + encoding.push_back(id[i] & 0x7F); } } der.add_object(OBJECT_ID, UNIVERSAL, encoding); @@ -166,15 +166,15 @@ void OID::decode_from(BER_Decoder& decoder) id.push_back(obj.value[0] / 40); id.push_back(obj.value[0] % 40); - u32bit j = 0; - while(j != obj.value.size() - 1) + size_t i = 0; + while(i != obj.value.size() - 1) { u32bit component = 0; - while(j != obj.value.size() - 1) + while(i != obj.value.size() - 1) { - ++j; - component = (component << 7) + (obj.value[j] & 0x7F); - if(!(obj.value[j] & 0x80)) + ++i; + component = (component << 7) + (obj.value[i] & 0x7F); + if(!(obj.value[i] & 0x80)) break; } id.push_back(component); diff --git a/src/asn1/asn1_str.cpp b/src/asn1/asn1_str.cpp index 892a44472..5faf9546d 100644 --- a/src/asn1/asn1_str.cpp +++ b/src/asn1/asn1_str.cpp @@ -5,7 +5,7 @@ * Distributed under the terms of the Botan license */ -#include <botan/asn1_obj.h> +#include <botan/asn1_str.h> #include <botan/der_enc.h> #include <botan/ber_dec.h> #include <botan/charset.h> @@ -45,9 +45,9 @@ ASN1_Tag choose_encoding(const std::string& str, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - for(u32bit j = 0; j != str.size(); ++j) + for(size_t i = 0; i != str.size(); ++i) { - if(!IS_PRINTABLE[static_cast<byte>(str[j])]) + if(!IS_PRINTABLE[static_cast<byte>(str[i])]) { if(type == "utf8") return UTF8_STRING; if(type == "latin1") return T61_STRING; diff --git a/src/asn1/asn1_str.h b/src/asn1/asn1_str.h new file mode 100644 index 000000000..ba43b0e94 --- /dev/null +++ b/src/asn1/asn1_str.h @@ -0,0 +1,38 @@ +/* +* ASN.1 string type +* (C) 1999-2010 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_ASN1_STRING_H__ +#define BOTAN_ASN1_STRING_H__ + +#include <botan/asn1_int.h> + +namespace Botan { + +/** +* Simple String +*/ +class BOTAN_DLL ASN1_String : public ASN1_Object + { + public: + void encode_into(class DER_Encoder&) const; + void decode_from(class BER_Decoder&); + + std::string value() const; + std::string iso_8859() const; + + ASN1_Tag tagging() const; + + ASN1_String(const std::string& = ""); + ASN1_String(const std::string&, ASN1_Tag); + private: + std::string iso_8859_str; + ASN1_Tag tag; + }; + +} + +#endif diff --git a/src/asn1/asn1_tm.cpp b/src/asn1/asn1_tm.cpp index 65eb96646..6e6868972 100644 --- a/src/asn1/asn1_tm.cpp +++ b/src/asn1/asn1_tm.cpp @@ -62,7 +62,7 @@ void X509_Time::set_to(const std::string& time_str) std::vector<std::string> params; std::string current; - for(u32bit j = 0; j != time_str.size(); ++j) + for(size_t j = 0; j != time_str.size(); ++j) { if(Charset::is_digit(time_str[j])) current += time_str[j]; @@ -109,17 +109,17 @@ void X509_Time::set_to(const std::string& t_spec, ASN1_Tag spec_tag) if(t_spec[t_spec.size()-1] != 'Z') throw Invalid_Argument("Invalid time encoding: " + t_spec); - const u32bit YEAR_SIZE = (spec_tag == UTC_TIME) ? 2 : 4; + const size_t YEAR_SIZE = (spec_tag == UTC_TIME) ? 2 : 4; std::vector<std::string> params; std::string current; - for(u32bit j = 0; j != YEAR_SIZE; ++j) + for(size_t j = 0; j != YEAR_SIZE; ++j) current += t_spec[j]; params.push_back(current); current.clear(); - for(u32bit j = YEAR_SIZE; j != t_spec.size() - 1; ++j) + for(size_t j = YEAR_SIZE; j != t_spec.size() - 1; ++j) { current += t_spec[j]; if(current.size() == 2) diff --git a/src/asn1/ber_dec.cpp b/src/asn1/ber_dec.cpp index 7f0459e22..e98ab3b61 100644 --- a/src/asn1/ber_dec.cpp +++ b/src/asn1/ber_dec.cpp @@ -16,7 +16,7 @@ namespace { /* * BER decode an ASN.1 type tag */ -u32bit decode_tag(DataSource* ber, ASN1_Tag& type_tag, ASN1_Tag& class_tag) +size_t decode_tag(DataSource* ber, ASN1_Tag& type_tag, ASN1_Tag& class_tag) { byte b; if(!ber->read_byte(b)) @@ -32,10 +32,10 @@ u32bit decode_tag(DataSource* ber, ASN1_Tag& type_tag, ASN1_Tag& class_tag) return 1; } - u32bit tag_bytes = 1; + size_t tag_bytes = 1; class_tag = ASN1_Tag(b & 0xE0); - u32bit tag_buf = 0; + size_t tag_buf = 0; while(true) { if(!ber->read_byte(b)) @@ -53,12 +53,12 @@ u32bit decode_tag(DataSource* ber, ASN1_Tag& type_tag, ASN1_Tag& class_tag) /* * Find the EOC marker */ -u32bit find_eoc(DataSource*); +size_t find_eoc(DataSource*); /* * BER decode an ASN.1 length field */ -u32bit decode_length(DataSource* ber, u32bit& field_size) +size_t decode_length(DataSource* ber, size_t& field_size) { byte b; if(!ber->read_byte(b)) @@ -72,9 +72,9 @@ u32bit decode_length(DataSource* ber, u32bit& field_size) if(field_size > 5) throw BER_Decoding_Error("Length field is too large"); - u32bit length = 0; + size_t length = 0; - for(u32bit j = 0; j != field_size - 1; ++j) + for(size_t i = 0; i != field_size - 1; ++i) { if(get_byte(0, length) != 0) throw BER_Decoding_Error("Field length overflow"); @@ -88,22 +88,22 @@ u32bit decode_length(DataSource* ber, u32bit& field_size) /* * BER decode an ASN.1 length field */ -u32bit decode_length(DataSource* ber) +size_t decode_length(DataSource* ber) { - u32bit dummy; + size_t dummy; return decode_length(ber, dummy); } /* * Find the EOC marker */ -u32bit find_eoc(DataSource* ber) +size_t find_eoc(DataSource* ber) { SecureVector<byte> buffer(DEFAULT_BUFFERSIZE), data; while(true) { - const u32bit got = ber->peek(&buffer[0], buffer.size(), data.size()); + const size_t got = ber->peek(&buffer[0], buffer.size(), data.size()); if(got == 0) break; @@ -113,16 +113,16 @@ u32bit find_eoc(DataSource* ber) DataSource_Memory source(data); data.clear(); - u32bit length = 0; + size_t length = 0; while(true) { ASN1_Tag type_tag, class_tag; - u32bit tag_size = decode_tag(&source, type_tag, class_tag); + size_t tag_size = decode_tag(&source, type_tag, class_tag); if(type_tag == NO_OBJECT) break; - u32bit length_size = 0; - u32bit item_size = decode_length(&source, length_size); + size_t length_size = 0; + size_t item_size = decode_length(&source, length_size); source.discard_next(item_size); length += item_size + length_size + tag_size; @@ -205,7 +205,7 @@ BER_Object BER_Decoder::get_next_object() if(next.type_tag == NO_OBJECT) return next; - u32bit length = decode_length(source); + size_t length = decode_length(source); next.value.resize(length); if(source->read(&next.value[0], length) != length) throw BER_Decoding_Error("Value truncated"); @@ -266,7 +266,7 @@ BER_Decoder::BER_Decoder(DataSource& src) /* * BER_Decoder Constructor */ -BER_Decoder::BER_Decoder(const byte data[], u32bit length) +BER_Decoder::BER_Decoder(const byte data[], size_t length) { source = new DataSource_Memory(data, length); owns = true; @@ -416,11 +416,11 @@ BER_Decoder& BER_Decoder::decode(BigInt& out, if(negative) { - for(u32bit j = obj.value.size(); j > 0; --j) - if(obj.value[j-1]--) + for(size_t i = obj.value.size(); i > 0; --i) + if(obj.value[i-1]--) break; - for(u32bit j = 0; j != obj.value.size(); ++j) - obj.value[j] = ~obj.value[j]; + for(size_t i = 0; i != obj.value.size(); ++i) + obj.value[i] = ~obj.value[i]; } out = BigInt(&obj.value[0], obj.value.size()); diff --git a/src/asn1/ber_dec.h b/src/asn1/ber_dec.h index 296d11037..79a15a298 100644 --- a/src/asn1/ber_dec.h +++ b/src/asn1/ber_dec.h @@ -77,7 +77,7 @@ class BOTAN_DLL BER_Decoder BER_Decoder& operator=(const BER_Decoder&) = delete; BER_Decoder(DataSource&); - BER_Decoder(const byte[], u32bit); + BER_Decoder(const byte[], size_t); BER_Decoder(const MemoryRegion<byte>&); BER_Decoder(const BER_Decoder&); ~BER_Decoder(); diff --git a/src/asn1/der_enc.cpp b/src/asn1/der_enc.cpp index fa53aa921..1d12ed5f6 100644 --- a/src/asn1/der_enc.cpp +++ b/src/asn1/der_enc.cpp @@ -31,12 +31,12 @@ SecureVector<byte> encode_tag(ASN1_Tag type_tag, ASN1_Tag class_tag) encoded_tag.push_back(static_cast<byte>(type_tag | class_tag)); else { - u32bit blocks = high_bit(type_tag) + 6; + size_t blocks = high_bit(type_tag) + 6; blocks = (blocks - (blocks % 7)) / 7; encoded_tag.push_back(class_tag | 0x1F); - for(u32bit k = 0; k != blocks - 1; ++k) - encoded_tag.push_back(0x80 | ((type_tag >> 7*(blocks-k-1)) & 0x7F)); + for(size_t i = 0; i != blocks - 1; ++i) + encoded_tag.push_back(0x80 | ((type_tag >> 7*(blocks-i-1)) & 0x7F)); encoded_tag.push_back(type_tag & 0x7F); } @@ -46,17 +46,19 @@ SecureVector<byte> encode_tag(ASN1_Tag type_tag, ASN1_Tag class_tag) /* * DER encode an ASN.1 length field */ -SecureVector<byte> encode_length(u32bit length) +SecureVector<byte> encode_length(size_t length) { SecureVector<byte> encoded_length; if(length <= 127) encoded_length.push_back(static_cast<byte>(length)); else { - const u32bit top_byte = significant_bytes(length); + const size_t top_byte = significant_bytes(length); + encoded_length.push_back(static_cast<byte>(0x80 | top_byte)); - for(u32bit j = 4-top_byte; j != 4; ++j) - encoded_length.push_back(get_byte(j, length)); + + for(size_t i = sizeof(length) - top_byte; i != sizeof(length); ++i) + encoded_length.push_back(get_byte(i, length)); } return encoded_length; } @@ -73,8 +75,8 @@ SecureVector<byte> DER_Encoder::DER_Sequence::get_contents() if(type_tag == SET) { std::sort(set_contents.begin(), set_contents.end()); - for(u32bit j = 0; j != set_contents.size(); ++j) - contents += set_contents[j]; + for(size_t i = 0; i != set_contents.size(); ++i) + contents += set_contents[i]; set_contents.clear(); } @@ -90,7 +92,7 @@ SecureVector<byte> DER_Encoder::DER_Sequence::get_contents() /* * Add an encoded value to the SEQUENCE/SET */ -void DER_Encoder::DER_Sequence::add_bytes(const byte data[], u32bit length) +void DER_Encoder::DER_Sequence::add_bytes(const byte data[], size_t length) { if(type_tag == SET) set_contents.push_back(SecureVector<byte>(data, length)); @@ -183,7 +185,7 @@ DER_Encoder& DER_Encoder::raw_bytes(const MemoryRegion<byte>& val) /* * Write raw bytes into the stream */ -DER_Encoder& DER_Encoder::raw_bytes(const byte bytes[], u32bit length) +DER_Encoder& DER_Encoder::raw_bytes(const byte bytes[], size_t length) { if(subsequences.size()) subsequences[subsequences.size()-1].add_bytes(bytes, length); @@ -238,7 +240,7 @@ DER_Encoder& DER_Encoder::encode(const MemoryRegion<byte>& bytes, /* * Encode this object */ -DER_Encoder& DER_Encoder::encode(const byte bytes[], u32bit length, +DER_Encoder& DER_Encoder::encode(const byte bytes[], size_t length, ASN1_Tag real_type) { return encode(bytes, length, real_type, real_type, UNIVERSAL); @@ -277,10 +279,10 @@ DER_Encoder& DER_Encoder::encode(const BigInt& n, BigInt::encode(&contents[extra_zero], n); if(n < 0) { - for(u32bit j = 0; j != contents.size(); ++j) - contents[j] = ~contents[j]; - for(u32bit j = contents.size(); j > 0; --j) - if(++contents[j-1]) + for(size_t i = 0; i != contents.size(); ++i) + contents[i] = ~contents[i]; + for(size_t i = contents.size(); i > 0; --i) + if(++contents[i-1]) break; } @@ -301,7 +303,7 @@ DER_Encoder& DER_Encoder::encode(const MemoryRegion<byte>& bytes, /* * DER encode an OCTET STRING or BIT STRING */ -DER_Encoder& DER_Encoder::encode(const byte bytes[], u32bit length, +DER_Encoder& DER_Encoder::encode(const byte bytes[], size_t length, ASN1_Tag real_type, ASN1_Tag type_tag, ASN1_Tag class_tag) { @@ -342,7 +344,7 @@ DER_Encoder& DER_Encoder::encode(const ASN1_Object& obj) * Write the encoding of the byte(s) */ DER_Encoder& DER_Encoder::add_object(ASN1_Tag type_tag, ASN1_Tag class_tag, - const byte rep[], u32bit length) + const byte rep[], size_t length) { SecureVector<byte> buffer; buffer += encode_tag(type_tag, class_tag); @@ -359,7 +361,7 @@ DER_Encoder& DER_Encoder::add_object(ASN1_Tag type_tag, ASN1_Tag class_tag, const MemoryRegion<byte>& rep_buf) { const byte* rep = &rep_buf[0]; - const u32bit rep_len = rep_buf.size(); + const size_t rep_len = rep_buf.size(); return add_object(type_tag, class_tag, rep, rep_len); } @@ -370,7 +372,7 @@ DER_Encoder& DER_Encoder::add_object(ASN1_Tag type_tag, ASN1_Tag class_tag, const std::string& rep_str) { const byte* rep = reinterpret_cast<const byte*>(rep_str.data()); - const u32bit rep_len = rep_str.size(); + const size_t rep_len = rep_str.size(); return add_object(type_tag, class_tag, rep, rep_len); } diff --git a/src/asn1/der_enc.h b/src/asn1/der_enc.h index ae10b4bc8..b3fce389d 100644 --- a/src/asn1/der_enc.h +++ b/src/asn1/der_enc.h @@ -30,7 +30,7 @@ class BOTAN_DLL DER_Encoder DER_Encoder& start_explicit(u16bit); DER_Encoder& end_explicit(); - DER_Encoder& raw_bytes(const byte[], u32bit); + DER_Encoder& raw_bytes(const byte[], size_t); DER_Encoder& raw_bytes(const MemoryRegion<byte>&); DER_Encoder& encode_null(); @@ -38,7 +38,7 @@ class BOTAN_DLL DER_Encoder DER_Encoder& encode(u32bit); DER_Encoder& encode(const BigInt&); DER_Encoder& encode(const MemoryRegion<byte>&, ASN1_Tag); - DER_Encoder& encode(const byte[], u32bit, ASN1_Tag); + DER_Encoder& encode(const byte[], size_t, ASN1_Tag); DER_Encoder& encode(bool, ASN1_Tag, ASN1_Tag = CONTEXT_SPECIFIC); DER_Encoder& encode(u32bit, ASN1_Tag, ASN1_Tag = CONTEXT_SPECIFIC); @@ -46,7 +46,7 @@ class BOTAN_DLL DER_Encoder ASN1_Tag = CONTEXT_SPECIFIC); DER_Encoder& encode(const MemoryRegion<byte>&, ASN1_Tag, ASN1_Tag, ASN1_Tag = CONTEXT_SPECIFIC); - DER_Encoder& encode(const byte[], u32bit, ASN1_Tag, + DER_Encoder& encode(const byte[], size_t, ASN1_Tag, ASN1_Tag, ASN1_Tag = CONTEXT_SPECIFIC); template<typename T> @@ -60,15 +60,15 @@ class BOTAN_DLL DER_Encoder template<typename T> DER_Encoder& encode_list(const std::vector<T>& values) { - for(u32bit j = 0; j != values.size(); ++j) - encode(values[j]); + for(size_t i = 0; i != values.size(); ++i) + encode(values[i]); return (*this); } DER_Encoder& encode(const ASN1_Object&); DER_Encoder& encode_if(bool, DER_Encoder&); - DER_Encoder& add_object(ASN1_Tag, ASN1_Tag, const byte[], u32bit); + DER_Encoder& add_object(ASN1_Tag, ASN1_Tag, const byte[], size_t); DER_Encoder& add_object(ASN1_Tag, ASN1_Tag, const MemoryRegion<byte>&); DER_Encoder& add_object(ASN1_Tag, ASN1_Tag, const std::string&); DER_Encoder& add_object(ASN1_Tag, ASN1_Tag, byte); @@ -78,7 +78,7 @@ class BOTAN_DLL DER_Encoder public: ASN1_Tag tag_of() const; SecureVector<byte> get_contents(); - void add_bytes(const byte[], u32bit); + void add_bytes(const byte[], size_t); DER_Sequence(ASN1_Tag, ASN1_Tag); private: ASN1_Tag type_tag, class_tag; diff --git a/src/asn1/info.txt b/src/asn1/info.txt index 7ed025e68..e190ad9ea 100644 --- a/src/asn1/info.txt +++ b/src/asn1/info.txt @@ -6,13 +6,13 @@ load_on auto alg_id.cpp asn1_alt.cpp asn1_att.cpp -asn1_dn.cpp asn1_int.cpp asn1_oid.cpp asn1_str.cpp asn1_tm.cpp ber_dec.cpp der_enc.cpp +x509_dn.cpp </source> <header:public> @@ -20,8 +20,10 @@ alg_id.h asn1_int.h asn1_obj.h asn1_oid.h +asn1_str.h ber_dec.h der_enc.h +x509_dn.h </header:public> <requires> diff --git a/src/asn1/asn1_dn.cpp b/src/asn1/x509_dn.cpp index 7d6e43bcc..0deed1a70 100644 --- a/src/asn1/asn1_dn.cpp +++ b/src/asn1/x509_dn.cpp @@ -5,7 +5,7 @@ * Distributed under the terms of the Botan license */ -#include <botan/asn1_obj.h> +#include <botan/x509_dn.h> #include <botan/der_enc.h> #include <botan/ber_dec.h> #include <botan/parsing.h> diff --git a/src/asn1/x509_dn.h b/src/asn1/x509_dn.h new file mode 100644 index 000000000..c4fc2d17b --- /dev/null +++ b/src/asn1/x509_dn.h @@ -0,0 +1,54 @@ +/* +* X.509 Distinguished Name +* (C) 1999-2010 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_X509_DN_H__ +#define BOTAN_X509_DN_H__ + +#include <botan/asn1_int.h> +#include <botan/asn1_oid.h> +#include <botan/asn1_str.h> +#include <map> + +namespace Botan { + +/** +* Distinguished Name +*/ +class BOTAN_DLL X509_DN : public ASN1_Object + { + public: + void encode_into(class DER_Encoder&) const; + void decode_from(class BER_Decoder&); + + std::multimap<OID, std::string> get_attributes() const; + std::vector<std::string> get_attribute(const std::string&) const; + + std::multimap<std::string, std::string> contents() const; + + void add_attribute(const std::string&, const std::string&); + void add_attribute(const OID&, const std::string&); + + static std::string deref_info_field(const std::string&); + + void do_decode(const MemoryRegion<byte>&); + MemoryVector<byte> get_bits() const; + + X509_DN(); + X509_DN(const std::multimap<OID, std::string>&); + X509_DN(const std::multimap<std::string, std::string>&); + private: + std::multimap<OID, ASN1_String> dn_info; + MemoryVector<byte> dn_bits; + }; + +bool BOTAN_DLL operator==(const X509_DN&, const X509_DN&); +bool BOTAN_DLL operator!=(const X509_DN&, const X509_DN&); +bool BOTAN_DLL operator<(const X509_DN&, const X509_DN&); + +} + +#endif |