Remove stl_compat.h. Chromium's toolchains may now assume C++11 library support, so we may freely use C++11 features. (Chromium's still in the process of deciding what to allow, but we use Google's style guide directly, toolchain limitations aside.) Change-Id: I1c7feb92b7f5f51d9091a4c686649fb574ac138d Reviewed-on: https://boringssl-review.googlesource.com/6465 Reviewed-by: Adam Langley <agl@google.com>
diff --git a/crypto/bn/bn_test.cc b/crypto/bn/bn_test.cc index 47093a7..7241277 100644 --- a/crypto/bn/bn_test.cc +++ b/crypto/bn/bn_test.cc
@@ -76,6 +76,8 @@ #include <stdio.h> #include <string.h> +#include <utility> + #include <openssl/bn.h> #include <openssl/crypto.h> #include <openssl/err.h> @@ -211,7 +213,7 @@ if (!sample) { return 1; } - if (!test_lshift(bc_file.get(), ctx.get(), bssl::move(sample))) { + if (!test_lshift(bc_file.get(), ctx.get(), std::move(sample))) { return 1; } flush_fp(bc_file.get());
diff --git a/crypto/bytestring/bytestring_test.cc b/crypto/bytestring/bytestring_test.cc index eae88d9..f25c186 100644 --- a/crypto/bytestring/bytestring_test.cc +++ b/crypto/bytestring/bytestring_test.cc
@@ -483,7 +483,7 @@ return false; } if (!CBB_add_asn1(&cbb, &contents, 0x30) || - !CBB_add_bytes(&contents, bssl::vector_data(&test_data), 130) || + !CBB_add_bytes(&contents, test_data.data(), 130) || !CBB_finish(&cbb, &buf, &buf_len)) { CBB_cleanup(&cbb); return false; @@ -492,7 +492,7 @@ if (buf_len != 3 + 130 || memcmp(buf, "\x30\x81\x82", 3) != 0 || - memcmp(buf + 3, bssl::vector_data(&test_data), 130) != 0) { + memcmp(buf + 3, test_data.data(), 130) != 0) { return false; } @@ -500,7 +500,7 @@ return false; } if (!CBB_add_asn1(&cbb, &contents, 0x30) || - !CBB_add_bytes(&contents, bssl::vector_data(&test_data), 1000) || + !CBB_add_bytes(&contents, test_data.data(), 1000) || !CBB_finish(&cbb, &buf, &buf_len)) { CBB_cleanup(&cbb); return false; @@ -509,7 +509,7 @@ if (buf_len != 4 + 1000 || memcmp(buf, "\x30\x82\x03\xe8", 4) != 0 || - memcmp(buf + 4, bssl::vector_data(&test_data), 1000)) { + memcmp(buf + 4, test_data.data(), 1000)) { return false; } @@ -518,7 +518,7 @@ } if (!CBB_add_asn1(&cbb, &contents, 0x30) || !CBB_add_asn1(&contents, &inner_contents, 0x30) || - !CBB_add_bytes(&inner_contents, bssl::vector_data(&test_data), 100000) || + !CBB_add_bytes(&inner_contents, test_data.data(), 100000) || !CBB_finish(&cbb, &buf, &buf_len)) { CBB_cleanup(&cbb); return false; @@ -527,7 +527,7 @@ if (buf_len != 5 + 5 + 100000 || memcmp(buf, "\x30\x83\x01\x86\xa5\x30\x83\x01\x86\xa0", 10) != 0 || - memcmp(buf + 10, bssl::vector_data(&test_data), 100000)) { + memcmp(buf + 10, test_data.data(), 100000)) { return false; }
diff --git a/crypto/cipher/aead_test.cc b/crypto/cipher/aead_test.cc index a4ddd3b..40812e5 100644 --- a/crypto/cipher/aead_test.cc +++ b/crypto/cipher/aead_test.cc
@@ -23,7 +23,6 @@ #include "../test/file_test.h" #include "../test/scoped_types.h" -#include "../test/stl_compat.h" // This program tests an AEAD against a series of test vectors from a file, @@ -50,8 +49,7 @@ } ScopedEVP_AEAD_CTX ctx; - if (!EVP_AEAD_CTX_init_with_direction(ctx.get(), aead, - bssl::vector_data(&key), key.size(), + if (!EVP_AEAD_CTX_init_with_direction(ctx.get(), aead, key.data(), key.size(), tag.size(), evp_aead_seal)) { t->PrintLine("Failed to init AEAD."); return false; @@ -60,10 +58,9 @@ std::vector<uint8_t> out(in.size() + EVP_AEAD_max_overhead(aead)); if (!t->HasAttribute("NO_SEAL")) { size_t out_len; - if (!EVP_AEAD_CTX_seal(ctx.get(), bssl::vector_data(&out), &out_len, - out.size(), bssl::vector_data(&nonce), nonce.size(), - bssl::vector_data(&in), in.size(), - bssl::vector_data(&ad), ad.size())) { + if (!EVP_AEAD_CTX_seal(ctx.get(), out.data(), &out_len, out.size(), + nonce.data(), nonce.size(), in.data(), in.size(), + ad.data(), ad.size())) { t->PrintLine("Failed to run AEAD."); return false; } @@ -74,24 +71,21 @@ (unsigned)(ct.size() + tag.size())); return false; } - if (!t->ExpectBytesEqual(bssl::vector_data(&ct), ct.size(), - bssl::vector_data(&out), ct.size()) || - !t->ExpectBytesEqual(bssl::vector_data(&tag), tag.size(), - bssl::vector_data(&out) + ct.size(), tag.size())) { + if (!t->ExpectBytesEqual(ct.data(), ct.size(), out.data(), ct.size()) || + !t->ExpectBytesEqual(tag.data(), tag.size(), out.data() + ct.size(), + tag.size())) { return false; } } else { out.resize(ct.size() + tag.size()); - memcpy(bssl::vector_data(&out), bssl::vector_data(&ct), ct.size()); - memcpy(bssl::vector_data(&out) + ct.size(), bssl::vector_data(&tag), - tag.size()); + memcpy(out.data(), ct.data(), ct.size()); + memcpy(out.data() + ct.size(), tag.data(), tag.size()); } // The "stateful" AEADs for implementing pre-AEAD cipher suites need to be // reset after each operation. ctx.Reset(); - if (!EVP_AEAD_CTX_init_with_direction(ctx.get(), aead, - bssl::vector_data(&key), key.size(), + if (!EVP_AEAD_CTX_init_with_direction(ctx.get(), aead, key.data(), key.size(), tag.size(), evp_aead_open)) { t->PrintLine("Failed to init AEAD."); return false; @@ -99,11 +93,9 @@ std::vector<uint8_t> out2(out.size()); size_t out2_len; - int ret = EVP_AEAD_CTX_open(ctx.get(), - bssl::vector_data(&out2), &out2_len, out2.size(), - bssl::vector_data(&nonce), nonce.size(), - bssl::vector_data(&out), out.size(), - bssl::vector_data(&ad), ad.size()); + int ret = EVP_AEAD_CTX_open(ctx.get(), out2.data(), &out2_len, out2.size(), + nonce.data(), nonce.size(), out.data(), + out.size(), ad.data(), ad.size()); if (t->HasAttribute("FAILS")) { if (ret) { t->PrintLine("Decrypted bad data."); @@ -118,16 +110,14 @@ return false; } out2.resize(out2_len); - if (!t->ExpectBytesEqual(bssl::vector_data(&in), in.size(), - bssl::vector_data(&out2), out2.size())) { + if (!t->ExpectBytesEqual(in.data(), in.size(), out2.data(), out2.size())) { return false; } // The "stateful" AEADs for implementing pre-AEAD cipher suites need to be // reset after each operation. ctx.Reset(); - if (!EVP_AEAD_CTX_init_with_direction(ctx.get(), aead, - bssl::vector_data(&key), key.size(), + if (!EVP_AEAD_CTX_init_with_direction(ctx.get(), aead, key.data(), key.size(), tag.size(), evp_aead_open)) { t->PrintLine("Failed to init AEAD."); return false; @@ -136,10 +126,9 @@ // Garbage at the end isn't ignored. out.push_back(0); out2.resize(out.size()); - if (EVP_AEAD_CTX_open(ctx.get(), bssl::vector_data(&out2), &out2_len, - out2.size(), bssl::vector_data(&nonce), nonce.size(), - bssl::vector_data(&out), out.size(), - bssl::vector_data(&ad), ad.size())) { + if (EVP_AEAD_CTX_open(ctx.get(), out2.data(), &out2_len, out2.size(), + nonce.data(), nonce.size(), out.data(), out.size(), + ad.data(), ad.size())) { t->PrintLine("Decrypted bad data with trailing garbage."); return false; } @@ -148,8 +137,7 @@ // The "stateful" AEADs for implementing pre-AEAD cipher suites need to be // reset after each operation. ctx.Reset(); - if (!EVP_AEAD_CTX_init_with_direction(ctx.get(), aead, - bssl::vector_data(&key), key.size(), + if (!EVP_AEAD_CTX_init_with_direction(ctx.get(), aead, key.data(), key.size(), tag.size(), evp_aead_open)) { t->PrintLine("Failed to init AEAD."); return false; @@ -159,10 +147,9 @@ out[0] ^= 0x80; out.resize(out.size() - 1); out2.resize(out.size()); - if (EVP_AEAD_CTX_open(ctx.get(), bssl::vector_data(&out2), &out2_len, - out2.size(), bssl::vector_data(&nonce), nonce.size(), - bssl::vector_data(&out), out.size(), - bssl::vector_data(&ad), ad.size())) { + if (EVP_AEAD_CTX_open(ctx.get(), out2.data(), &out2_len, out2.size(), + nonce.data(), nonce.size(), out.data(), out.size(), + ad.data(), ad.size())) { t->PrintLine("Decrypted bad data with corrupted byte."); return false; }
diff --git a/crypto/cipher/cipher_test.cc b/crypto/cipher/cipher_test.cc index 5f04178..1cbfae9 100644 --- a/crypto/cipher/cipher_test.cc +++ b/crypto/cipher/cipher_test.cc
@@ -63,7 +63,6 @@ #include "../test/file_test.h" #include "../test/scoped_types.h" -#include "../test/stl_compat.h" static const EVP_CIPHER *GetCipher(const std::string &name) { @@ -146,7 +145,7 @@ } if (is_aead && !encrypt && !EVP_CIPHER_CTX_ctrl(ctx.get(), EVP_CTRL_GCM_SET_TAG, tag.size(), - const_cast<uint8_t*>(bssl::vector_data(&tag)))) { + const_cast<uint8_t*>(tag.data()))) { return false; } // The ciphers are run with no padding. For each of the ciphers we test, the @@ -162,10 +161,10 @@ // |EVP_CipherUpdate| calls when empty. int unused, result_len1 = 0, result_len2; if (!EVP_CIPHER_CTX_set_key_length(ctx.get(), key.size()) || - !EVP_CipherInit_ex(ctx.get(), nullptr, nullptr, bssl::vector_data(&key), - bssl::vector_data(&iv), -1) || + !EVP_CipherInit_ex(ctx.get(), nullptr, nullptr, key.data(), iv.data(), + -1) || (!aad.empty() && - !EVP_CipherUpdate(ctx.get(), nullptr, &unused, bssl::vector_data(&aad), + !EVP_CipherUpdate(ctx.get(), nullptr, &unused, aad.data(), aad.size())) || !EVP_CIPHER_CTX_set_padding(ctx.get(), 0)) { t->PrintLine("Operation failed."); @@ -175,28 +174,27 @@ for (size_t i = 0; i < in->size(); i++) { uint8_t c = (*in)[i]; int len; - if (!EVP_CipherUpdate(ctx.get(), bssl::vector_data(&result) + result_len1, - &len, &c, 1)) { + if (!EVP_CipherUpdate(ctx.get(), result.data() + result_len1, &len, &c, + 1)) { t->PrintLine("Operation failed."); return false; } result_len1 += len; } } else if (!in->empty() && - !EVP_CipherUpdate(ctx.get(), bssl::vector_data(&result), - &result_len1, bssl::vector_data(in), - in->size())) { + !EVP_CipherUpdate(ctx.get(), result.data(), &result_len1, + in->data(), in->size())) { t->PrintLine("Operation failed."); return false; } - if (!EVP_CipherFinal_ex(ctx.get(), bssl::vector_data(&result) + result_len1, + if (!EVP_CipherFinal_ex(ctx.get(), result.data() + result_len1, &result_len2)) { t->PrintLine("Operation failed."); return false; } result.resize(result_len1 + result_len2); - if (!t->ExpectBytesEqual(bssl::vector_data(out), out->size(), - bssl::vector_data(&result), result.size())) { + if (!t->ExpectBytesEqual(out->data(), out->size(), result.data(), + result.size())) { return false; } if (encrypt && is_aead) { @@ -207,7 +205,7 @@ } if (!EVP_CIPHER_CTX_ctrl(ctx.get(), EVP_CTRL_GCM_GET_TAG, tag.size(), rtag) || - !t->ExpectBytesEqual(bssl::vector_data(&tag), tag.size(), rtag, + !t->ExpectBytesEqual(tag.data(), tag.size(), rtag, tag.size())) { return false; }
diff --git a/crypto/dh/dh_test.cc b/crypto/dh/dh_test.cc index 16a5ae0..c117bd4 100644 --- a/crypto/dh/dh_test.cc +++ b/crypto/dh/dh_test.cc
@@ -68,7 +68,6 @@ #include "internal.h" #include "../test/scoped_types.h" -#include "../test/stl_compat.h" static bool RunBasicTests(); @@ -167,7 +166,7 @@ printf("\n"); std::vector<uint8_t> key1(DH_size(a.get())); - int ret = DH_compute_key(bssl::vector_data(&key1), b->pub_key, a.get()); + int ret = DH_compute_key(key1.data(), b->pub_key, a.get()); if (ret < 0) { return false; } @@ -180,7 +179,7 @@ printf("\n"); std::vector<uint8_t> key2(DH_size(b.get())); - ret = DH_compute_key(bssl::vector_data(&key2), a->pub_key, b.get()); + ret = DH_compute_key(key2.data(), a->pub_key, b.get()); if (ret < 0) { return false; } @@ -458,17 +457,17 @@ std::vector<uint8_t> Z2(DH_size(dhB.get())); /* Work out shared secrets using both sides and compare * with expected values. */ - int ret1 = DH_compute_key(bssl::vector_data(&Z1), dhB->pub_key, dhA.get()); - int ret2 = DH_compute_key(bssl::vector_data(&Z2), dhA->pub_key, dhB.get()); + int ret1 = DH_compute_key(Z1.data(), dhB->pub_key, dhA.get()); + int ret2 = DH_compute_key(Z2.data(), dhA->pub_key, dhB.get()); if (ret1 < 0 || ret2 < 0) { fprintf(stderr, "DH_compute_key error RFC5114 set %u\n", i + 1); return false; } if (static_cast<size_t>(ret1) != td->Z_len || - memcmp(bssl::vector_data(&Z1), td->Z, td->Z_len) != 0 || + memcmp(Z1.data(), td->Z, td->Z_len) != 0 || static_cast<size_t>(ret2) != td->Z_len || - memcmp(bssl::vector_data(&Z2), td->Z, td->Z_len) != 0) { + memcmp(Z2.data(), td->Z, td->Z_len) != 0) { fprintf(stderr, "Test failed RFC5114 set %u\n", i + 1); return false; }
diff --git a/crypto/ec/ec_test.cc b/crypto/ec/ec_test.cc index 3f45bd0..2088e72 100644 --- a/crypto/ec/ec_test.cc +++ b/crypto/ec/ec_test.cc
@@ -23,7 +23,6 @@ #include <openssl/mem.h> #include "../test/scoped_types.h" -#include "../test/stl_compat.h" // kECKeyWithoutPublic is an ECPrivateKey with the optional publicKey field @@ -80,7 +79,7 @@ static bool EncodeECPrivateKey(std::vector<uint8_t> *out, EC_KEY *key) { int len = i2d_ECPrivateKey(key, NULL); out->resize(len); - uint8_t *outp = bssl::vector_data(out); + uint8_t *outp = out->data(); return i2d_ECPrivateKey(key, &outp) == len; }
diff --git a/crypto/ecdsa/ecdsa_test.cc b/crypto/ecdsa/ecdsa_test.cc index b916509..5e021bd 100644 --- a/crypto/ecdsa/ecdsa_test.cc +++ b/crypto/ecdsa/ecdsa_test.cc
@@ -63,7 +63,6 @@ #include <openssl/rand.h> #include "../test/scoped_types.h" -#include "../test/stl_compat.h" enum Api { kEncodedApi, @@ -118,9 +117,8 @@ size_t buf_len = 2 * bn_len; std::vector<uint8_t> raw_buf(buf_len); // Pad the bignums with leading zeroes. - if (!BN_bn2bin_padded(bssl::vector_data(&raw_buf), bn_len, ecdsa_sig->r) || - !BN_bn2bin_padded(bssl::vector_data(&raw_buf) + bn_len, bn_len, - ecdsa_sig->s)) { + if (!BN_bn2bin_padded(raw_buf.data(), bn_len, ecdsa_sig->r) || + !BN_bn2bin_padded(raw_buf.data() + bn_len, bn_len, ecdsa_sig->s)) { return false; } @@ -129,18 +127,16 @@ uint8_t dirt = raw_buf[11] ? raw_buf[11] : 1; raw_buf[offset] ^= dirt; // Now read the BIGNUMs back in from raw_buf. - if (BN_bin2bn(bssl::vector_data(&raw_buf), bn_len, ecdsa_sig->r) == NULL || - BN_bin2bn(bssl::vector_data(&raw_buf) + bn_len, bn_len, - ecdsa_sig->s) == NULL || + if (BN_bin2bn(raw_buf.data(), bn_len, ecdsa_sig->r) == NULL || + BN_bin2bn(raw_buf.data() + bn_len, bn_len, ecdsa_sig->s) == NULL || !VerifyECDSASig(api, digest, digest_len, ecdsa_sig, eckey, 0)) { return false; } // Sanity check: Undo the modification and verify signature. raw_buf[offset] ^= dirt; - if (BN_bin2bn(bssl::vector_data(&raw_buf), bn_len, ecdsa_sig->r) == NULL || - BN_bin2bn(bssl::vector_data(&raw_buf) + bn_len, bn_len, - ecdsa_sig->s) == NULL || + if (BN_bin2bn(raw_buf.data(), bn_len, ecdsa_sig->r) == NULL || + BN_bin2bn(raw_buf.data() + bn_len, bn_len, ecdsa_sig->s) == NULL || !VerifyECDSASig(api, digest, digest_len, ecdsa_sig, eckey, 1)) { return false; } @@ -221,8 +217,7 @@ // Create a signature. unsigned sig_len = ECDSA_size(eckey.get()); std::vector<uint8_t> signature(sig_len); - if (!ECDSA_sign(0, digest, 20, bssl::vector_data(&signature), &sig_len, - eckey.get())) { + if (!ECDSA_sign(0, digest, 20, signature.data(), &sig_len, eckey.get())) { fprintf(out, " failed\n"); return false; } @@ -230,32 +225,32 @@ fprintf(out, "."); fflush(out); // Verify the signature. - if (!ECDSA_verify(0, digest, 20, bssl::vector_data(&signature), - signature.size(), eckey.get())) { + if (!ECDSA_verify(0, digest, 20, signature.data(), signature.size(), + eckey.get())) { fprintf(out, " failed\n"); return false; } fprintf(out, "."); fflush(out); // Verify the signature with the wrong key. - if (ECDSA_verify(0, digest, 20, bssl::vector_data(&signature), - signature.size(), wrong_eckey.get())) { + if (ECDSA_verify(0, digest, 20, signature.data(), signature.size(), + wrong_eckey.get())) { fprintf(out, " failed\n"); return false; } fprintf(out, "."); fflush(out); // Verify the signature using the wrong digest. - if (ECDSA_verify(0, wrong_digest, 20, bssl::vector_data(&signature), - signature.size(), eckey.get())) { + if (ECDSA_verify(0, wrong_digest, 20, signature.data(), signature.size(), + eckey.get())) { fprintf(out, " failed\n"); return false; } fprintf(out, "."); fflush(out); // Verify a truncated signature. - if (ECDSA_verify(0, digest, 20, bssl::vector_data(&signature), - signature.size() - 1, eckey.get())) { + if (ECDSA_verify(0, digest, 20, signature.data(), signature.size() - 1, + eckey.get())) { fprintf(out, " failed\n"); return false; } @@ -263,7 +258,7 @@ fflush(out); // Verify a tampered signature. ScopedECDSA_SIG ecdsa_sig(ECDSA_SIG_from_bytes( - bssl::vector_data(&signature), signature.size())); + signature.data(), signature.size())); if (!ecdsa_sig || !TestTamperedSig(out, kEncodedApi, digest, 20, ecdsa_sig.get(), eckey.get(), order.get())) { @@ -327,8 +322,8 @@ return false; } std::vector<uint8_t> bytes(order_len, 0xff); - if (!BN_bin2bn(bssl::vector_data(&bytes), bytes.size(), sig->r) || - !BN_bin2bn(bssl::vector_data(&bytes), bytes.size(), sig->s)) { + if (!BN_bin2bn(bytes.data(), bytes.size(), sig->r) || + !BN_bin2bn(bytes.data(), bytes.size(), sig->s)) { return false; } /* Serialize it. */
diff --git a/crypto/evp/evp_extra_test.cc b/crypto/evp/evp_extra_test.cc index bd70040..86476fc 100644 --- a/crypto/evp/evp_extra_test.cc +++ b/crypto/evp/evp_extra_test.cc
@@ -376,16 +376,17 @@ std::vector<uint8_t> sig; sig.resize(sig_len); - if (!EVP_DigestSignFinal(md_ctx.get(), bssl::vector_data(&sig), &sig_len)) { + if (!EVP_DigestSignFinal(md_ctx.get(), sig.data(), &sig_len)) { return false; } sig.resize(sig_len); // Ensure that the signature round-trips. md_ctx.Reset(); - if (!EVP_DigestVerifyInit(md_ctx.get(), NULL, EVP_sha256(), NULL, pkey.get()) || + if (!EVP_DigestVerifyInit(md_ctx.get(), NULL, EVP_sha256(), NULL, + pkey.get()) || !EVP_DigestVerifyUpdate(md_ctx.get(), kMsg, sizeof(kMsg)) || - !EVP_DigestVerifyFinal(md_ctx.get(), bssl::vector_data(&sig), sig_len)) { + !EVP_DigestVerifyFinal(md_ctx.get(), sig.data(), sig_len)) { return false; } @@ -432,7 +433,7 @@ std::vector<uint8_t> sig; sig.resize(sig_len); - if (!EVP_DigestSignFinal(md_ctx, bssl::vector_data(&sig), &sig_len)) { + if (!EVP_DigestSignFinal(md_ctx, sig.data(), &sig_len)) { return false; } sig.resize(sig_len); @@ -442,8 +443,7 @@ if (!EVP_DigestVerifyInitFromAlgorithm(md_ctx_verify.get(), algor.get(), pkey) || !EVP_DigestVerifyUpdate(md_ctx_verify.get(), kMsg, sizeof(kMsg)) || - !EVP_DigestVerifyFinal(md_ctx_verify.get(), bssl::vector_data(&sig), - sig_len)) { + !EVP_DigestVerifyFinal(md_ctx_verify.get(), sig.data(), sig_len)) { return false; } @@ -602,7 +602,7 @@ // Copy the input into a |malloc|'d vector to flag memory errors. std::vector<uint8_t> copy(kExampleBadECKeyDER2, kExampleBadECKeyDER2 + sizeof(kExampleBadECKeyDER2)); - derp = bssl::vector_data(©); + derp = copy.data(); pkey.reset(d2i_PrivateKey(EVP_PKEY_EC, nullptr, &derp, copy.size())); if (pkey) { fprintf(stderr, "Imported invalid EC key #2.\n");
diff --git a/crypto/evp/evp_test.cc b/crypto/evp/evp_test.cc index c7ac908..7fedc15 100644 --- a/crypto/evp/evp_test.cc +++ b/crypto/evp/evp_test.cc
@@ -78,7 +78,6 @@ #include "../test/file_test.h" #include "../test/scoped_types.h" -#include "../test/stl_compat.h" // evp_test dispatches between multiple test types. PrivateKey tests take a key @@ -179,8 +178,8 @@ } if (t->GetType() == "Verify") { - if (!EVP_PKEY_verify(ctx.get(), bssl::vector_data(&output), output.size(), - bssl::vector_data(&input), input.size())) { + if (!EVP_PKEY_verify(ctx.get(), output.data(), output.size(), input.data(), + input.size())) { // ECDSA sometimes doesn't push an error code. Push one on the error queue // so it's distinguishable from other errors. OPENSSL_PUT_ERROR(USER, ERR_R_EVP_LIB); @@ -191,18 +190,15 @@ size_t len; std::vector<uint8_t> actual; - if (!key_op(ctx.get(), nullptr, &len, bssl::vector_data(&input), - input.size())) { + if (!key_op(ctx.get(), nullptr, &len, input.data(), input.size())) { return false; } actual.resize(len); - if (!key_op(ctx.get(), bssl::vector_data(&actual), &len, - bssl::vector_data(&input), input.size())) { + if (!key_op(ctx.get(), actual.data(), &len, input.data(), input.size())) { return false; } actual.resize(len); - if (!t->ExpectBytesEqual(bssl::vector_data(&output), output.size(), - bssl::vector_data(&actual), len)) { + if (!t->ExpectBytesEqual(output.data(), output.size(), actual.data(), len)) { return false; } return true;
diff --git a/crypto/hmac/hmac_test.cc b/crypto/hmac/hmac_test.cc index d438b70..da390ef 100644 --- a/crypto/hmac/hmac_test.cc +++ b/crypto/hmac/hmac_test.cc
@@ -66,7 +66,6 @@ #include "../test/file_test.h" #include "../test/scoped_types.h" -#include "../test/stl_compat.h" static const EVP_MD *GetDigest(const std::string &name) { @@ -107,33 +106,28 @@ // Test using the one-shot API. uint8_t mac[EVP_MAX_MD_SIZE]; unsigned mac_len; - if (nullptr == HMAC(digest, bssl::vector_data(&key), key.size(), - bssl::vector_data(&input), input.size(), mac, - &mac_len) || - !t->ExpectBytesEqual(bssl::vector_data(&output), output.size(), mac, - mac_len)) { + if (nullptr == HMAC(digest, key.data(), key.size(), input.data(), + input.size(), mac, &mac_len) || + !t->ExpectBytesEqual(output.data(), output.size(), mac, mac_len)) { t->PrintLine("One-shot API failed."); return false; } // Test using HMAC_CTX. ScopedHMAC_CTX ctx; - if (!HMAC_Init_ex(ctx.get(), bssl::vector_data(&key), key.size(), digest, - nullptr) || - !HMAC_Update(ctx.get(), bssl::vector_data(&input), input.size()) || + if (!HMAC_Init_ex(ctx.get(), key.data(), key.size(), digest, nullptr) || + !HMAC_Update(ctx.get(), input.data(), input.size()) || !HMAC_Final(ctx.get(), mac, &mac_len) || - !t->ExpectBytesEqual(bssl::vector_data(&output), output.size(), mac, - mac_len)) { + !t->ExpectBytesEqual(output.data(), output.size(), mac, mac_len)) { t->PrintLine("HMAC_CTX failed."); return false; } // Test that an HMAC_CTX may be reset with the same key. if (!HMAC_Init_ex(ctx.get(), nullptr, 0, digest, nullptr) || - !HMAC_Update(ctx.get(), bssl::vector_data(&input), input.size()) || + !HMAC_Update(ctx.get(), input.data(), input.size()) || !HMAC_Final(ctx.get(), mac, &mac_len) || - !t->ExpectBytesEqual(bssl::vector_data(&output), output.size(), mac, - mac_len)) { + !t->ExpectBytesEqual(output.data(), output.size(), mac, mac_len)) { t->PrintLine("HMAC_CTX with reset failed."); return false; } @@ -150,8 +144,7 @@ } } if (!HMAC_Final(ctx.get(), mac, &mac_len) || - !t->ExpectBytesEqual(bssl::vector_data(&output), output.size(), mac, - mac_len)) { + !t->ExpectBytesEqual(output.data(), output.size(), mac, mac_len)) { t->PrintLine("HMAC_CTX streaming failed."); return false; }
diff --git a/crypto/poly1305/poly1305_test.cc b/crypto/poly1305/poly1305_test.cc index 0526075..3a72668 100644 --- a/crypto/poly1305/poly1305_test.cc +++ b/crypto/poly1305/poly1305_test.cc
@@ -21,7 +21,6 @@ #include <openssl/poly1305.h> #include "../test/file_test.h" -#include "../test/stl_compat.h" // |CRYPTO_poly1305_finish| requires a 16-byte-aligned output. @@ -46,22 +45,22 @@ // Test single-shot operation. poly1305_state state; - CRYPTO_poly1305_init(&state, bssl::vector_data(&key)); - CRYPTO_poly1305_update(&state, bssl::vector_data(&in), in.size()); + CRYPTO_poly1305_init(&state, key.data()); + CRYPTO_poly1305_update(&state, in.data(), in.size()); ALIGNED uint8_t out[16]; CRYPTO_poly1305_finish(&state, out); - if (!t->ExpectBytesEqual(out, 16, bssl::vector_data(&mac), mac.size())) { + if (!t->ExpectBytesEqual(out, 16, mac.data(), mac.size())) { t->PrintLine("Single-shot Poly1305 failed."); return false; } // Test streaming byte-by-byte. - CRYPTO_poly1305_init(&state, bssl::vector_data(&key)); + CRYPTO_poly1305_init(&state, key.data()); for (size_t i = 0; i < in.size(); i++) { CRYPTO_poly1305_update(&state, &in[i], 1); } CRYPTO_poly1305_finish(&state, out); - if (!t->ExpectBytesEqual(out, 16, bssl::vector_data(&mac), mac.size())) { + if (!t->ExpectBytesEqual(out, 16, mac.data(), mac.size())) { t->PrintLine("Streaming Poly1305 failed."); return false; }
diff --git a/crypto/test/file_test.cc b/crypto/test/file_test.cc index 6723350..4752f04 100644 --- a/crypto/test/file_test.cc +++ b/crypto/test/file_test.cc
@@ -22,8 +22,6 @@ #include <openssl/err.h> -#include "stl_compat.h" - FileTest::FileTest(const char *path) { file_ = fopen(path, "r");
diff --git a/crypto/test/scoped_types.h b/crypto/test/scoped_types.h index 2ce4526..590f926 100644 --- a/crypto/test/scoped_types.h +++ b/crypto/test/scoped_types.h
@@ -18,6 +18,8 @@ #include <stdint.h> #include <stdio.h> +#include <memory> + #include <openssl/aead.h> #include <openssl/bio.h> #include <openssl/bn.h> @@ -34,8 +36,6 @@ #include <openssl/stack.h> #include <openssl/x509.h> -#include "stl_compat.h" - template<typename T, void (*func)(T*)> struct OpenSSLDeleter { @@ -66,11 +66,11 @@ }; template<typename T, void (*func)(T*)> -using ScopedOpenSSLType = bssl::unique_ptr<T, OpenSSLDeleter<T, func>>; +using ScopedOpenSSLType = std::unique_ptr<T, OpenSSLDeleter<T, func>>; template<typename StackType, typename T, void (*func)(T*)> using ScopedOpenSSLStack = - bssl::unique_ptr<StackType, OpenSSLStackDeleter<StackType, T, func>>; + std::unique_ptr<StackType, OpenSSLStackDeleter<StackType, T, func>>; template<typename T, typename CleanupRet, void (*init_func)(T*), CleanupRet (*cleanup_func)(T*)> @@ -129,9 +129,9 @@ using ScopedHMAC_CTX = ScopedOpenSSLContext<HMAC_CTX, void, HMAC_CTX_init, HMAC_CTX_cleanup>; -using ScopedOpenSSLBytes = bssl::unique_ptr<uint8_t, OpenSSLFree<uint8_t>>; -using ScopedOpenSSLString = bssl::unique_ptr<char, OpenSSLFree<char>>; +using ScopedOpenSSLBytes = std::unique_ptr<uint8_t, OpenSSLFree<uint8_t>>; +using ScopedOpenSSLString = std::unique_ptr<char, OpenSSLFree<char>>; -using ScopedFILE = bssl::unique_ptr<FILE, FileCloser>; +using ScopedFILE = std::unique_ptr<FILE, FileCloser>; #endif // OPENSSL_HEADER_CRYPTO_TEST_SCOPED_TYPES_H
diff --git a/crypto/test/stl_compat.h b/crypto/test/stl_compat.h deleted file mode 100644 index 1997a45..0000000 --- a/crypto/test/stl_compat.h +++ /dev/null
@@ -1,144 +0,0 @@ -/* Copyright (c) 2015, Google Inc. - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY - * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ - -#ifndef OPENSSL_HEADER_CRYPTO_TEST_STL_COMPAT_H -#define OPENSSL_HEADER_CRYPTO_TEST_STL_COMPAT_H - -#include <assert.h> - -#include <vector> - - -// This header contains re-implementations of library functions from C++11. They -// will be replaced with their standard counterparts once Chromium has C++11 -// library support in its toolchain. - -namespace bssl { - -// vector_data is a reimplementation of |std::vector::data| from C++11. -template <class T> -static T *vector_data(std::vector<T> *out) { - return out->empty() ? nullptr : &(*out)[0]; -} - -template <class T> -static const T *vector_data(const std::vector<T> *out) { - return out->empty() ? nullptr : &(*out)[0]; -} - -// remove_reference is a reimplementation of |std::remove_reference| from C++11. -template <class T> -struct remove_reference { - using type = T; -}; - -template <class T> -struct remove_reference<T&> { - using type = T; -}; - -template <class T> -struct remove_reference<T&&> { - using type = T; -}; - -// move is a reimplementation of |std::move| from C++11. -template <class T> -typename remove_reference<T>::type &&move(T &&t) { - return static_cast<typename remove_reference<T>::type&&>(t); -} - -// default_delete is a partial reimplementation of |std::default_delete| from -// C++11. -template <class T> -struct default_delete { - void operator()(T *t) const { - enum { type_must_be_complete = sizeof(T) }; - delete t; - } -}; - -// nullptr_t is |std::nullptr_t| from C++11. -using nullptr_t = decltype(nullptr); - -// unique_ptr is a partial reimplementation of |std::unique_ptr| from C++11. It -// intentionally does not support stateful deleters to avoid having to bother -// with the empty member optimization. -template <class T, class Deleter = default_delete<T>> -class unique_ptr { - public: - unique_ptr() : ptr_(nullptr) {} - unique_ptr(nullptr_t) : ptr_(nullptr) {} - unique_ptr(T *ptr) : ptr_(ptr) {} - unique_ptr(const unique_ptr &u) = delete; - - unique_ptr(unique_ptr &&u) : ptr_(nullptr) { - reset(u.release()); - } - - ~unique_ptr() { - reset(); - } - - unique_ptr &operator=(nullptr_t) { - reset(); - return *this; - } - - unique_ptr &operator=(unique_ptr &&u) { - reset(u.release()); - return *this; - } - - unique_ptr& operator=(const unique_ptr &u) = delete; - - explicit operator bool() const { - return ptr_ != nullptr; - } - - T &operator*() const { - assert(ptr_ != nullptr); - return *ptr_; - } - - T *operator->() const { - assert(ptr_ != nullptr); - return ptr_; - } - - T *get() const { - return ptr_; - } - - T *release() { - T *ptr = ptr_; - ptr_ = nullptr; - return ptr; - } - - void reset(T *ptr = nullptr) { - if (ptr_ != nullptr) { - Deleter()(ptr_); - } - ptr_ = ptr; - } - - private: - T *ptr_; -}; - -} // namespace bssl - - -#endif // OPENSSL_HEADER_CRYPTO_TEST_STL_COMPAT_H
diff --git a/ssl/ssl_test.cc b/ssl/ssl_test.cc index 0cd42a2..dffe729 100644 --- a/ssl/ssl_test.cc +++ b/ssl/ssl_test.cc
@@ -521,7 +521,7 @@ } out->resize(len); - if (!EVP_DecodeBase64(bssl::vector_data(out), &len, len, (const uint8_t *)in, + if (!EVP_DecodeBase64(out->data(), &len, len, (const uint8_t *)in, strlen(in))) { fprintf(stderr, "EVP_DecodeBase64 failed\n"); return false; @@ -541,8 +541,7 @@ } // Verify the SSL_SESSION decodes. - ScopedSSL_SESSION session(SSL_SESSION_from_bytes(bssl::vector_data(&input), - input.size())); + ScopedSSL_SESSION session(SSL_SESSION_from_bytes(input.data(), input.size())); if (!session) { fprintf(stderr, "SSL_SESSION_from_bytes failed\n"); return false; @@ -558,7 +557,7 @@ } encoded.reset(encoded_raw); if (encoded_len != input.size() || - memcmp(bssl::vector_data(&input), encoded.get(), input.size()) != 0) { + memcmp(input.data(), encoded.get(), input.size()) != 0) { fprintf(stderr, "SSL_SESSION_to_bytes did not round-trip\n"); hexdump(stderr, "Before: ", input.data(), input.size()); hexdump(stderr, "After: ", encoded_raw, encoded_len); @@ -566,9 +565,9 @@ } // Verify the SSL_SESSION also decodes with the legacy API. - cptr = bssl::vector_data(&input); + cptr = input.data(); session.reset(d2i_SSL_SESSION(NULL, &cptr, input.size())); - if (!session || cptr != bssl::vector_data(&input) + input.size()) { + if (!session || cptr != input.data() + input.size()) { fprintf(stderr, "d2i_SSL_SESSION failed\n"); return false; } @@ -596,7 +595,7 @@ fprintf(stderr, "i2d_SSL_SESSION did not advance ptr correctly\n"); return false; } - if (memcmp(bssl::vector_data(&input), encoded.get(), input.size()) != 0) { + if (memcmp(input.data(), encoded.get(), input.size()) != 0) { fprintf(stderr, "i2d_SSL_SESSION did not round-trip\n"); return false; } @@ -611,8 +610,7 @@ } // Verify that the SSL_SESSION fails to decode. - ScopedSSL_SESSION session(SSL_SESSION_from_bytes(bssl::vector_data(&input), - input.size())); + ScopedSSL_SESSION session(SSL_SESSION_from_bytes(input.data(), input.size())); if (session) { fprintf(stderr, "SSL_SESSION_from_bytes unexpectedly succeeded\n"); return false; @@ -700,8 +698,7 @@ if (!DecodeBase64(&der, kOpenSSLSession)) { return nullptr; } - ScopedSSL_SESSION session(SSL_SESSION_from_bytes(bssl::vector_data(&der), - der.size())); + ScopedSSL_SESSION session(SSL_SESSION_from_bytes(der.data(), der.size())); if (!session) { return nullptr; }
diff --git a/ssl/test/bssl_shim.cc b/ssl/test/bssl_shim.cc index b309449..22ce889 100644 --- a/ssl/test/bssl_shim.cc +++ b/ssl/test/bssl_shim.cc
@@ -173,8 +173,8 @@ return ssl_private_key_failure; } test_state->private_key_result.resize(len); - if (!EVP_PKEY_sign(ctx.get(), bssl::vector_data( - &test_state->private_key_result), &len, in, in_len)) { + if (!EVP_PKEY_sign(ctx.get(), test_state->private_key_result.data(), &len, in, + in_len)) { return ssl_private_key_failure; } test_state->private_key_result.resize(len); @@ -203,7 +203,7 @@ fprintf(stderr, "Output buffer too small.\n"); return ssl_private_key_failure; } - memcpy(out, bssl::vector_data(&test_state->private_key_result), + memcpy(out, test_state->private_key_result.data(), test_state->private_key_result.size()); *out_len = test_state->private_key_result.size(); @@ -230,8 +230,7 @@ } RSA *rsa = pkey->pkey.rsa; test_state->private_key_result.resize(RSA_size(rsa)); - if (!RSA_decrypt(rsa, out_len, - bssl::vector_data(&test_state->private_key_result), + if (!RSA_decrypt(rsa, out_len, test_state->private_key_result.data(), RSA_size(rsa), in, in_len, RSA_NO_PADDING)) { return ssl_private_key_failure; } @@ -263,7 +262,7 @@ fprintf(stderr, "Output buffer too small.\n"); return ssl_private_key_failure; } - memcpy(out, bssl::vector_data(&test_state->private_key_result), + memcpy(out, test_state->private_key_result.data(), test_state->private_key_result.size()); *out_len = test_state->private_key_result.size();