diff options
author | lloyd <[email protected]> | 2010-11-19 20:00:34 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-11-19 20:00:34 +0000 |
commit | fda988f9f6f44d87c384a56dce590ca1121b5ab7 (patch) | |
tree | e8ef2c93dfe6c74cdf9cab63b26153b2af124493 /src | |
parent | db9f18deb5ba7c091b8389e1243a200eff135903 (diff) |
Fix pr 127 and pr 128. Don't require the common name and country codes
in newly generated DNs, there are reasonable cases where you do not
need or want either. Also fix the saving of dn_bits, and remove
X509_DN::do_decode and inline it into its only caller (decode_from).
Diffstat (limited to 'src')
-rw-r--r-- | src/asn1/x509_dn.cpp | 60 | ||||
-rw-r--r-- | src/asn1/x509_dn.h | 1 |
2 files changed, 26 insertions, 35 deletions
diff --git a/src/asn1/x509_dn.cpp b/src/asn1/x509_dn.cpp index 0a4760391..58bfc450d 100644 --- a/src/asn1/x509_dn.cpp +++ b/src/asn1/x509_dn.cpp @@ -113,35 +113,6 @@ std::vector<std::string> X509_DN::get_attribute(const std::string& attr) const } /* -* Handle the decoding operation of a DN -*/ -void X509_DN::do_decode(const MemoryRegion<byte>& bits) - { - BER_Decoder sequence(bits); - - while(sequence.more_items()) - { - BER_Decoder rdn = sequence.start_cons(SET); - - while(rdn.more_items()) - { - OID oid; - ASN1_String str; - - rdn.start_cons(SEQUENCE) - .decode(oid) - .decode(str) - .verify_end() - .end_cons(); - - add_attribute(oid, str.value()); - } - } - - dn_bits = bits; - } - -/* * Return the BER encoded data, if any */ MemoryVector<byte> X509_DN::get_bits() const @@ -275,12 +246,12 @@ void X509_DN::encode_into(DER_Encoder& der) const der.raw_bytes(dn_bits); else { - do_ava(der, dn_info, PRINTABLE_STRING, "X520.Country", true); + do_ava(der, dn_info, PRINTABLE_STRING, "X520.Country"); do_ava(der, dn_info, DIRECTORY_STRING, "X520.State"); do_ava(der, dn_info, DIRECTORY_STRING, "X520.Locality"); do_ava(der, dn_info, DIRECTORY_STRING, "X520.Organization"); do_ava(der, dn_info, DIRECTORY_STRING, "X520.OrganizationalUnit"); - do_ava(der, dn_info, DIRECTORY_STRING, "X520.CommonName", true); + do_ava(der, dn_info, DIRECTORY_STRING, "X520.CommonName"); do_ava(der, dn_info, PRINTABLE_STRING, "X520.SerialNumber"); } @@ -292,13 +263,34 @@ void X509_DN::encode_into(DER_Encoder& der) const */ void X509_DN::decode_from(BER_Decoder& source) { - dn_info.clear(); + MemoryVector<byte> bits; source.start_cons(SEQUENCE) - .raw_bytes(dn_bits) + .raw_bytes(bits) .end_cons(); - do_decode(dn_bits); + BER_Decoder sequence(bits); + + while(sequence.more_items()) + { + BER_Decoder rdn = sequence.start_cons(SET); + + while(rdn.more_items()) + { + OID oid; + ASN1_String str; + + rdn.start_cons(SEQUENCE) + .decode(oid) + .decode(str) + .verify_end() + .end_cons(); + + add_attribute(oid, str.value()); + } + } + + dn_info = bits; } } diff --git a/src/asn1/x509_dn.h b/src/asn1/x509_dn.h index c4fc2d17b..3f63eb49c 100644 --- a/src/asn1/x509_dn.h +++ b/src/asn1/x509_dn.h @@ -34,7 +34,6 @@ class BOTAN_DLL X509_DN : public ASN1_Object static std::string deref_info_field(const std::string&); - void do_decode(const MemoryRegion<byte>&); MemoryVector<byte> get_bits() const; X509_DN(); |