diff options
author | lloyd <[email protected]> | 2011-02-09 14:27:03 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2011-02-09 14:27:03 +0000 |
commit | 3495b0bbe0779845800fe34ea93acffffc8c2785 (patch) | |
tree | eb48a607a1ca2d6d6227cf7a71efdf52178b5a04 /src | |
parent | 02ed4e271a6287a0c23b137e826e62d2be752b82 (diff) |
Some cleanups, and add an <ios> include for Sun Studio 12
Diffstat (limited to 'src')
-rw-r--r-- | src/asn1/asn1_int.h | 4 | ||||
-rw-r--r-- | src/cert/cvc/asn1_eac_str.cpp | 39 | ||||
-rw-r--r-- | src/cert/cvc/asn1_eac_tm.cpp | 48 |
3 files changed, 49 insertions, 42 deletions
diff --git a/src/asn1/asn1_int.h b/src/asn1/asn1_int.h index cac46190f..25b3cf100 100644 --- a/src/asn1/asn1_int.h +++ b/src/asn1/asn1_int.h @@ -114,8 +114,8 @@ struct BOTAN_DLL BER_Decoding_Error : public Decoding_Error */ struct BOTAN_DLL BER_Bad_Tag : public BER_Decoding_Error { - BER_Bad_Tag(const std::string&, ASN1_Tag); - BER_Bad_Tag(const std::string&, ASN1_Tag, ASN1_Tag); + BER_Bad_Tag(const std::string& msg, ASN1_Tag tag); + BER_Bad_Tag(const std::string& msg, ASN1_Tag tag1, ASN1_Tag tag2); }; } diff --git a/src/cert/cvc/asn1_eac_str.cpp b/src/cert/cvc/asn1_eac_str.cpp index e617ba81f..37a601e4e 100644 --- a/src/cert/cvc/asn1_eac_str.cpp +++ b/src/cert/cvc/asn1_eac_str.cpp @@ -1,7 +1,7 @@ /* * Simple ASN.1 String Types * (C) 2007 FlexSecure GmbH -* 2008 Jack Lloyd +* 2008-2011 Jack Lloyd * * Distributed under the terms of the Botan license */ @@ -12,6 +12,7 @@ #include <botan/charset.h> #include <botan/parsing.h> #include <sstream> +#include <ios> namespace Botan { @@ -21,10 +22,9 @@ namespace Botan { ASN1_EAC_String::ASN1_EAC_String(const std::string& str, ASN1_Tag t) : tag(t) { iso_8859_str = Charset::transcode(str, LOCAL_CHARSET, LATIN1_CHARSET); - if (!sanity_check()) - { - throw Invalid_Argument("attempted to construct ASN1_EAC_String with illegal characters"); - } + + if(!sanity_check()) + throw Invalid_Argument("ASN1_EAC_String contains illegal characters"); } /* @@ -66,23 +66,19 @@ void ASN1_EAC_String::encode_into(DER_Encoder& encoder) const void ASN1_EAC_String::decode_from(BER_Decoder& source) { BER_Object obj = source.get_next_object(); - if (obj.type_tag != this->tag) - { - std::string message("decoding type mismatch for ASN1_EAC_String, tag is "); + if(obj.type_tag != this->tag) + { std::stringstream ss; - std::string str_is; - ss << std::hex << obj.type_tag; - ss >> str_is; - message.append(str_is); - message.append(", while it should be "); - std::stringstream ss2; - std::string str_should; - ss2 << std::hex << this->tag; - ss2 >> str_should; - message.append(str_should); - throw Decoding_Error(message); + + ss << "ASN1_EAC_String tag mismatch, tag was " + << std::hex << obj.type_tag + << " expected " + << std::hex << this->tag; + + throw Decoding_Error(ss.str()); } + Character_Set charset_is; charset_is = LATIN1_CHARSET; @@ -92,9 +88,10 @@ void ASN1_EAC_String::decode_from(BER_Decoder& source) Charset::transcode(ASN1::to_string(obj), charset_is, LOCAL_CHARSET), obj.type_tag); } - catch (Invalid_Argument inv_arg) + catch(Invalid_Argument inv_arg) { - throw Decoding_Error(std::string("error while decoding ASN1_EAC_String: ") + std::string(inv_arg.what())); + throw Decoding_Error(std::string("ASN1_EAC_String decoding failed: ") + + inv_arg.what()); } } diff --git a/src/cert/cvc/asn1_eac_tm.cpp b/src/cert/cvc/asn1_eac_tm.cpp index 0eaca49d6..db5d2fbaf 100644 --- a/src/cert/cvc/asn1_eac_tm.cpp +++ b/src/cert/cvc/asn1_eac_tm.cpp @@ -45,6 +45,7 @@ u32bit dec_two_digit(byte b1, byte b2) return upper*10 + lower; } + } /* @@ -62,19 +63,15 @@ EAC_Time::EAC_Time(u64bit timer, ASN1_Tag t) : tag(t) /* * Create an EAC_Time */ -EAC_Time::EAC_Time(const std::string& t_spec, ASN1_Tag t) - :tag(t) +EAC_Time::EAC_Time(const std::string& t_spec, ASN1_Tag t) : tag(t) { set_to(t_spec); } /* * Create an EAC_Time */ -EAC_Time::EAC_Time(u32bit y, u32bit m, u32bit d, ASN1_Tag t) - : year(y), - month(m), - day(d), - tag(t) +EAC_Time::EAC_Time(u32bit y, u32bit m, u32bit d, ASN1_Tag t) : + year(y), month(m), day(d), tag(t) { } @@ -229,22 +226,27 @@ bool operator==(const EAC_Time& t1, const EAC_Time& t2) { return (t1.cmp(t2) == 0); } + bool operator!=(const EAC_Time& t1, const EAC_Time& t2) { return (t1.cmp(t2) != 0); } + bool operator<=(const EAC_Time& t1, const EAC_Time& t2) { return (t1.cmp(t2) <= 0); } + bool operator>=(const EAC_Time& t1, const EAC_Time& t2) { return (t1.cmp(t2) >= 0); } + bool operator>(const EAC_Time& t1, const EAC_Time& t2) { return (t1.cmp(t2) > 0); } + bool operator<(const EAC_Time& t1, const EAC_Time& t2) { return (t1.cmp(t2) < 0); @@ -285,10 +287,12 @@ u32bit EAC_Time::get_year() const { return year; } + u32bit EAC_Time::get_month() const { return month; } + u32bit EAC_Time::get_day() const { return day; @@ -306,28 +310,34 @@ SecureVector<byte> EAC_Time::encoded_eac_time() const return result; } -ASN1_Ced::ASN1_Ced(std::string const& str) - : EAC_Time(str, ASN1_Tag(37)) +ASN1_Ced::ASN1_Ced(std::string const& str) : + EAC_Time(str, ASN1_Tag(37)) {} -ASN1_Ced::ASN1_Ced(u64bit val) - : EAC_Time(val, ASN1_Tag(37)) +ASN1_Ced::ASN1_Ced(u64bit val) : + EAC_Time(val, ASN1_Tag(37)) {} -ASN1_Ced::ASN1_Ced(EAC_Time const& other) - : EAC_Time(other.get_year(), other.get_month(), other.get_day(), ASN1_Tag(37)) +ASN1_Ced::ASN1_Ced(EAC_Time const& other) : + EAC_Time(other.get_year(), + other.get_month(), + other.get_day(), + ASN1_Tag(37)) {} -ASN1_Cex::ASN1_Cex(std::string const& str) - : EAC_Time(str, ASN1_Tag(36)) +ASN1_Cex::ASN1_Cex(std::string const& str) : + EAC_Time(str, ASN1_Tag(36)) {} -ASN1_Cex::ASN1_Cex(u64bit val) - : EAC_Time(val, ASN1_Tag(36)) +ASN1_Cex::ASN1_Cex(u64bit val) : + EAC_Time(val, ASN1_Tag(36)) {} -ASN1_Cex::ASN1_Cex(EAC_Time const& other) - : EAC_Time(other.get_year(), other.get_month(), other.get_day(), ASN1_Tag(36)) +ASN1_Cex::ASN1_Cex(EAC_Time const& other) : + EAC_Time(other.get_year(), + other.get_month(), + other.get_day(), + ASN1_Tag(36)) {} } |