From ad3c9c5a74be828440385f31c4b99affc3f33654 Mon Sep 17 00:00:00 2001 From: lloyd Date: Sat, 21 Jul 2007 19:35:10 +0000 Subject: Use std::string::data() instead of std::string::c_str() in cases where we just want access to the underlying data representation but don't care if the return value is NULL terminated or not. --- src/base.cpp | 2 +- src/data_src.cpp | 2 +- src/der_enc.cpp | 2 +- src/kdf.cpp | 4 ++-- src/pgp_s2k.cpp | 2 +- src/pipe.cpp | 2 +- src/pipe_rw.cpp | 2 +- src/pkcs5.cpp | 2 +- src/pubkey.cpp | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/base.cpp b/src/base.cpp index 3afa9e6b1..fb5e219c9 100644 --- a/src/base.cpp +++ b/src/base.cpp @@ -150,7 +150,7 @@ void BufferedComputation::update(const MemoryRegion& in) *************************************************/ void BufferedComputation::update(const std::string& str) { - update((const byte*)str.c_str(), str.size()); + update((const byte*)str.data(), str.size()); } /************************************************* diff --git a/src/data_src.cpp b/src/data_src.cpp index 8f5b43dac..9ed7dc6c9 100644 --- a/src/data_src.cpp +++ b/src/data_src.cpp @@ -93,7 +93,7 @@ DataSource_Memory::DataSource_Memory(const MemoryRegion& in) *************************************************/ DataSource_Memory::DataSource_Memory(const std::string& in) { - source.set((const byte*)in.c_str(), in.length()); + source.set((const byte*)in.data(), in.length()); offset = 0; } diff --git a/src/der_enc.cpp b/src/der_enc.cpp index 9973fd5cb..1a4bb1b48 100644 --- a/src/der_enc.cpp +++ b/src/der_enc.cpp @@ -373,7 +373,7 @@ DER_Encoder& DER_Encoder::add_object(ASN1_Tag type_tag, ASN1_Tag class_tag, DER_Encoder& DER_Encoder::add_object(ASN1_Tag type_tag, ASN1_Tag class_tag, const std::string& rep_str) { - const byte* rep = (const byte*)rep_str.c_str(); + const byte* rep = (const byte*)rep_str.data(); const u32bit rep_len = rep_str.size(); return add_object(type_tag, class_tag, rep, rep_len); } diff --git a/src/kdf.cpp b/src/kdf.cpp index dad00204d..5dd53b957 100644 --- a/src/kdf.cpp +++ b/src/kdf.cpp @@ -19,7 +19,7 @@ SecureVector KDF::derive_key(u32bit key_len, const std::string& salt) const { return derive_key(key_len, secret, secret.size(), - (const byte*)salt.c_str(), salt.length()); + (const byte*)salt.data(), salt.length()); } /************************************************* @@ -52,7 +52,7 @@ SecureVector KDF::derive_key(u32bit key_len, const std::string& salt) const { return derive_key(key_len, secret, secret_len, - (const byte*)salt.c_str(), salt.length()); + (const byte*)salt.data(), salt.length()); } /************************************************* diff --git a/src/pgp_s2k.cpp b/src/pgp_s2k.cpp index 1e2778eea..b8a27cc6e 100644 --- a/src/pgp_s2k.cpp +++ b/src/pgp_s2k.cpp @@ -44,7 +44,7 @@ OctetString OpenPGP_S2K::derive(u32bit key_len, const std::string& passphrase, { hash->update(salt_buf, salt_size); left -= salt_size; - hash->update((const byte*)passphrase.c_str(), left); + hash->update((const byte*)passphrase.data(), left); } hash_buf = hash->final(); diff --git a/src/pipe.cpp b/src/pipe.cpp index 20acf98e5..e876e57d1 100644 --- a/src/pipe.cpp +++ b/src/pipe.cpp @@ -130,7 +130,7 @@ void Pipe::process_msg(const MemoryRegion& input) *************************************************/ void Pipe::process_msg(const std::string& input) { - process_msg((const byte*)input.c_str(), input.length()); + process_msg((const byte*)input.data(), input.length()); } /************************************************* diff --git a/src/pipe_rw.cpp b/src/pipe_rw.cpp index 85a027e1a..7a7e672fb 100644 --- a/src/pipe_rw.cpp +++ b/src/pipe_rw.cpp @@ -48,7 +48,7 @@ void Pipe::write(const MemoryRegion& input) *************************************************/ void Pipe::write(const std::string& str) { - write((const byte*)str.c_str(), str.size()); + write((const byte*)str.data(), str.size()); } /************************************************* diff --git a/src/pkcs5.cpp b/src/pkcs5.cpp index 3f6e22ac4..c0dc72b35 100644 --- a/src/pkcs5.cpp +++ b/src/pkcs5.cpp @@ -72,7 +72,7 @@ OctetString PKCS5_PBKDF2::derive(u32bit key_len, throw Invalid_Argument("PKCS#5 PBKDF2: Empty passphrase is invalid"); HMAC hmac(hash_name); - hmac.set_key((const byte*)passphrase.c_str(), passphrase.length()); + hmac.set_key((const byte*)passphrase.data(), passphrase.length()); SecureVector key(key_len); byte* T = key.begin(); diff --git a/src/pubkey.cpp b/src/pubkey.cpp index bdcca9c49..f480c425f 100644 --- a/src/pubkey.cpp +++ b/src/pubkey.cpp @@ -378,7 +378,7 @@ SymmetricKey PK_Key_Agreement::derive_key(u32bit key_len, const std::string& params) const { return derive_key(key_len, in, in_len, - (const byte*)params.c_str(), params.length()); + (const byte*)params.data(), params.length()); } /************************************************* -- cgit v1.2.3