diff options
author | Simon Warta <[email protected]> | 2015-06-26 11:32:10 +0200 |
---|---|---|
committer | Simon Warta <[email protected]> | 2015-06-27 11:18:13 +0200 |
commit | d007082daa03ddebd124c38393f42793a1b50811 (patch) | |
tree | 04788426bbc4072024ae2d878c1c64830e9bc572 /src/lib/asn1 | |
parent | 105fb962ae525428c2385098abdf20bbf4382353 (diff) |
lib/asn1: Convert &vec[0] to vec.data()
Diffstat (limited to 'src/lib/asn1')
-rw-r--r-- | src/lib/asn1/asn1_time.cpp | 21 | ||||
-rw-r--r-- | src/lib/asn1/ber_dec.cpp | 12 | ||||
-rw-r--r-- | src/lib/asn1/der_enc.cpp | 12 | ||||
-rw-r--r-- | src/lib/asn1/der_enc.h | 4 |
4 files changed, 27 insertions, 22 deletions
diff --git a/src/lib/asn1/asn1_time.cpp b/src/lib/asn1/asn1_time.cpp index b79e8a9ba..72bf87df9 100644 --- a/src/lib/asn1/asn1_time.cpp +++ b/src/lib/asn1/asn1_time.cpp @@ -11,6 +11,8 @@ #include <botan/charset.h> #include <botan/parsing.h> #include <botan/calendar.h> +#include <sstream> +#include <iomanip> namespace Botan { @@ -230,14 +232,17 @@ std::string X509_Time::readable_string() const if(time_is_set() == false) throw Invalid_State("X509_Time::readable_string: No time set"); - std::string output(24, 0); - - std::sprintf(&output[0], "%04d/%02d/%02d %02d:%02d:%02d UTC", - year, month, day, hour, minute, second); - - output.resize(23); // remove trailing null - - return output; + // desired format: "%04d/%02d/%02d %02d:%02d:%02d UTC" + std::stringstream output; + { + using namespace std; + output << setfill('0') + << setw(4) << year << "/" << setw(2) << month << "/" << setw(2) << day + << " " + << setw(2) << hour << ":" << setw(2) << minute << ":" << setw(2) << second + << " UTC"; + } + return output.str(); } /* diff --git a/src/lib/asn1/ber_dec.cpp b/src/lib/asn1/ber_dec.cpp index 0ff79399c..e9133d50f 100644 --- a/src/lib/asn1/ber_dec.cpp +++ b/src/lib/asn1/ber_dec.cpp @@ -103,11 +103,11 @@ size_t find_eoc(DataSource* ber) while(true) { - const size_t got = ber->peek(&buffer[0], buffer.size(), data.size()); + const size_t got = ber->peek(buffer.data(), buffer.size(), data.size()); if(got == 0) break; - data += std::make_pair(&buffer[0], got); + data += std::make_pair(buffer.data(), got); } DataSource_Memory source(data); @@ -309,7 +309,7 @@ BER_Decoder::BER_Decoder(const secure_vector<byte>& data) */ BER_Decoder::BER_Decoder(const std::vector<byte>& data) { - source = new DataSource_Memory(&data[0], data.size()); + source = new DataSource_Memory(data.data(), data.size()); owns = true; pushed.type_tag = pushed.class_tag = NO_OBJECT; parent = nullptr; @@ -391,7 +391,7 @@ BER_Decoder& BER_Decoder::decode_octet_string_bigint(BigInt& out) { secure_vector<byte> out_vec; decode(out_vec, OCTET_STRING); - out = BigInt::decode(&out_vec[0], out_vec.size()); + out = BigInt::decode(out_vec.data(), out_vec.size()); return (*this); } @@ -530,7 +530,7 @@ BER_Decoder& BER_Decoder::decode(secure_vector<byte>& buffer, throw BER_Decoding_Error("Bad number of unused bits in BIT STRING"); buffer.resize(obj.value.size() - 1); - copy_mem(&buffer[0], &obj.value[1], obj.value.size() - 1); + copy_mem(buffer.data(), &obj.value[1], obj.value.size() - 1); } return (*this); } @@ -553,7 +553,7 @@ BER_Decoder& BER_Decoder::decode(std::vector<byte>& buffer, throw BER_Decoding_Error("Bad number of unused bits in BIT STRING"); buffer.resize(obj.value.size() - 1); - copy_mem(&buffer[0], &obj.value[1], obj.value.size() - 1); + copy_mem(buffer.data(), &obj.value[1], obj.value.size() - 1); } return (*this); } diff --git a/src/lib/asn1/der_enc.cpp b/src/lib/asn1/der_enc.cpp index ab84c258d..f886e8ed3 100644 --- a/src/lib/asn1/der_enc.cpp +++ b/src/lib/asn1/der_enc.cpp @@ -179,12 +179,12 @@ DER_Encoder& DER_Encoder::end_explicit() */ DER_Encoder& DER_Encoder::raw_bytes(const secure_vector<byte>& val) { - return raw_bytes(&val[0], val.size()); + return raw_bytes(val.data(), val.size()); } DER_Encoder& DER_Encoder::raw_bytes(const std::vector<byte>& val) { - return raw_bytes(&val[0], val.size()); + return raw_bytes(val.data(), val.size()); } /* @@ -238,7 +238,7 @@ DER_Encoder& DER_Encoder::encode(const BigInt& n) DER_Encoder& DER_Encoder::encode(const secure_vector<byte>& bytes, ASN1_Tag real_type) { - return encode(&bytes[0], bytes.size(), + return encode(bytes.data(), bytes.size(), real_type, real_type, UNIVERSAL); } @@ -248,7 +248,7 @@ DER_Encoder& DER_Encoder::encode(const secure_vector<byte>& bytes, DER_Encoder& DER_Encoder::encode(const std::vector<byte>& bytes, ASN1_Tag real_type) { - return encode(&bytes[0], bytes.size(), + return encode(bytes.data(), bytes.size(), real_type, real_type, UNIVERSAL); } @@ -311,7 +311,7 @@ DER_Encoder& DER_Encoder::encode(const secure_vector<byte>& bytes, ASN1_Tag real_type, ASN1_Tag type_tag, ASN1_Tag class_tag) { - return encode(&bytes[0], bytes.size(), + return encode(bytes.data(), bytes.size(), real_type, type_tag, class_tag); } @@ -322,7 +322,7 @@ DER_Encoder& DER_Encoder::encode(const std::vector<byte>& bytes, ASN1_Tag real_type, ASN1_Tag type_tag, ASN1_Tag class_tag) { - return encode(&bytes[0], bytes.size(), + return encode(bytes.data(), bytes.size(), real_type, type_tag, class_tag); } diff --git a/src/lib/asn1/der_enc.h b/src/lib/asn1/der_enc.h index 0e96fea3b..dbb97d1aa 100644 --- a/src/lib/asn1/der_enc.h +++ b/src/lib/asn1/der_enc.h @@ -99,13 +99,13 @@ class BOTAN_DLL DER_Encoder DER_Encoder& add_object(ASN1_Tag type_tag, ASN1_Tag class_tag, const std::vector<byte>& rep) { - return add_object(type_tag, class_tag, &rep[0], rep.size()); + return add_object(type_tag, class_tag, rep.data(), rep.size()); } DER_Encoder& add_object(ASN1_Tag type_tag, ASN1_Tag class_tag, const secure_vector<byte>& rep) { - return add_object(type_tag, class_tag, &rep[0], rep.size()); + return add_object(type_tag, class_tag, rep.data(), rep.size()); } DER_Encoder& add_object(ASN1_Tag type_tag, ASN1_Tag class_tag, |