aboutsummaryrefslogtreecommitdiffstats
path: root/src/asn1_str.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2006-05-19 00:07:25 +0000
committerlloyd <[email protected]>2006-05-19 00:07:25 +0000
commitf090e030be53e574fecbe7cf50edfb5fdacb53e1 (patch)
tree0bff0c249a9dbcb674fcd2491ab17e3d123ef1f9 /src/asn1_str.cpp
parenta0af7b26591f8fb79d1f06fe42548e1eb0c35e90 (diff)
Syntax changes to the BER and DER APIs to improve readability of code
that uses them. These changes are not backwards compatible, this commit updates all uses of the APIs within the library.
Diffstat (limited to 'src/asn1_str.cpp')
-rw-r--r--src/asn1_str.cpp44
1 files changed, 6 insertions, 38 deletions
diff --git a/src/asn1_str.cpp b/src/asn1_str.cpp
index ced252b49..f3c8584ed 100644
--- a/src/asn1_str.cpp
+++ b/src/asn1_str.cpp
@@ -4,7 +4,6 @@
*************************************************/
#include <botan/asn1_obj.h>
-#include <botan/asn1_int.h>
#include <botan/der_enc.h>
#include <botan/ber_dec.h>
#include <botan/charset.h>
@@ -133,29 +132,12 @@ void ASN1_String::encode_into(DER_Encoder& encoder) const
encoder.add_object(tagging(), UNIVERSAL, value);
}
-namespace DER {
-
-/*************************************************
-* DER encode an ASN1_String *
-*************************************************/
-void encode(DER_Encoder& encoder, const ASN1_String& string,
- ASN1_Tag type_tag, ASN1_Tag class_tag)
- {
- if(string.tagging() == UTF8_STRING)
- encoder.add_object(type_tag, class_tag, iso2utf(string.iso_8859()));
- else
- encoder.add_object(type_tag, class_tag, string.iso_8859());
- }
-
-}
-
-namespace BER {
-
namespace {
/*************************************************
* Do any UTF-8/Unicode decoding needed *
*************************************************/
+// FIXME: inline this
std::string convert_string(BER_Object obj, ASN1_Tag type)
{
if(type == BMP_STRING)
@@ -177,9 +159,9 @@ std::string convert_string(BER_Object obj, ASN1_Tag type)
return iso2local(value);
}
else if(type == UTF8_STRING)
- return iso2local(utf2iso(BER::to_string(obj)));
+ return iso2local(utf2iso(ASN1::to_string(obj)));
else
- return iso2local(BER::to_string(obj));
+ return iso2local(ASN1::to_string(obj));
}
}
@@ -187,25 +169,11 @@ std::string convert_string(BER_Object obj, ASN1_Tag type)
/*************************************************
* Decode a BER encoded ASN1_String *
*************************************************/
-void decode(BER_Decoder& source, ASN1_String& string,
- ASN1_Tag expected_tag, ASN1_Tag real_tag)
+void ASN1_String::decode_from(BER_Decoder& source)
{
BER_Object obj = source.get_next_object();
- if(obj.type_tag != expected_tag)
- throw BER_Bad_Tag("Unexpected string tag", obj.type_tag);
-
- string = ASN1_String(convert_string(obj, real_tag), real_tag);
- }
-
-/*************************************************
-* Decode a BER encoded ASN1_String *
-*************************************************/
-void decode(BER_Decoder& source, ASN1_String& string)
- {
- BER_Object obj = source.get_next_object();
- string = ASN1_String(convert_string(obj, obj.type_tag), obj.type_tag);
+ // FIXME, don't like this at all...
+ *this = ASN1_String(convert_string(obj, obj.type_tag), obj.type_tag);
}
}
-
-}