Switch //components from vector_as_array to vector::data.
BUG=556678 Review URL: https://codereview.chromium.org/1461703009 Cr-Commit-Position: refs/heads/master@{#360926}
This commit is contained in:
components
gcm_driver
crypto
html_viewer
ownership
webcrypto
algorithms
aes_cbc.ccaes_cbc_unittest.ccaes_ctr.ccaes_ctr_unittest.ccaes_gcm_unittest.ccec.ccecdh.ccecdsa.cchkdf.cchmac.cchmac_unittest.ccpbkdf2.ccrsa.ccrsa_oaep.ccrsa_oaep_unittest.ccrsa_sign.ccrsa_ssa_unittest.ccsecret_key_util.ccsha.ccsha_unittest.cctest_helpers.ccutil.cc
crypto_data.ccwebcrypto_impl.cc@@ -9,7 +9,6 @@
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "crypto/ec_private_key.h"
|
||||
|
||||
namespace gcm {
|
||||
@@ -72,11 +71,10 @@ bool CreateP256KeyPair(std::string* out_private_key,
|
||||
return false;
|
||||
}
|
||||
|
||||
out_private_key->assign(
|
||||
reinterpret_cast<const char*>(vector_as_array(&private_key)),
|
||||
private_key.size());
|
||||
out_private_key->assign(reinterpret_cast<const char*>(private_key.data()),
|
||||
private_key.size());
|
||||
out_public_key_x509->assign(
|
||||
reinterpret_cast<const char*>(vector_as_array(&public_key_x509)),
|
||||
reinterpret_cast<const char*>(public_key_x509.data()),
|
||||
public_key_x509.size());
|
||||
|
||||
// Concatenate the leading 0x04 byte and the two uncompressed points.
|
||||
|
@@ -8,7 +8,6 @@
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "base/rand_util.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "base/synchronization/waitable_event.h"
|
||||
#include "base/thread_task_runner_handle.h"
|
||||
#include "base/threading/platform_thread.h"
|
||||
@@ -290,8 +289,7 @@ blink::WebWaitableEvent* BlinkPlatformImpl::waitMultipleEvents(
|
||||
std::vector<base::WaitableEvent*> events;
|
||||
for (size_t i = 0; i < web_events.size(); ++i)
|
||||
events.push_back(static_cast<WebWaitableEventImpl*>(web_events[i])->impl());
|
||||
size_t idx = base::WaitableEvent::WaitMany(
|
||||
vector_as_array(&events), events.size());
|
||||
size_t idx = base::WaitableEvent::WaitMany(events.data(), events.size());
|
||||
DCHECK_LT(idx, web_events.size());
|
||||
return web_events[idx];
|
||||
}
|
||||
|
@@ -12,7 +12,6 @@
|
||||
#include "base/macros.h"
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "components/ownership/ownership_export.h"
|
||||
#include "crypto/scoped_nss_types.h"
|
||||
|
||||
@@ -34,7 +33,7 @@ class OWNERSHIP_EXPORT PublicKey
|
||||
bool is_loaded() const { return !data_.empty(); }
|
||||
|
||||
std::string as_string() {
|
||||
return std::string(reinterpret_cast<const char*>(vector_as_array(&data_)),
|
||||
return std::string(reinterpret_cast<const char*>(data_.data()),
|
||||
data_.size());
|
||||
}
|
||||
|
||||
|
@@ -47,8 +47,7 @@ bool OwnerKeyUtilImpl::ImportPublicKey(std::vector<uint8>* output) {
|
||||
|
||||
// Get the key data off of disk
|
||||
int data_read =
|
||||
base::ReadFile(public_key_file_,
|
||||
reinterpret_cast<char*>(vector_as_array(output)),
|
||||
base::ReadFile(public_key_file_, reinterpret_cast<char*>(output->data()),
|
||||
safe_file_size);
|
||||
return data_read == safe_file_size;
|
||||
}
|
||||
|
@@ -12,7 +12,6 @@
|
||||
#include "base/files/file_util.h"
|
||||
#include "base/files/scoped_temp_dir.h"
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
namespace ownership {
|
||||
@@ -70,10 +69,9 @@ TEST_F(OwnerKeyUtilImplTest, ImportPublicKey) {
|
||||
std::vector<uint8> public_key(kTestKeyData,
|
||||
kTestKeyData + sizeof(kTestKeyData));
|
||||
ASSERT_EQ(static_cast<int>(public_key.size()),
|
||||
base::WriteFile(
|
||||
key_file_,
|
||||
reinterpret_cast<const char*>(vector_as_array(&public_key)),
|
||||
public_key.size()));
|
||||
base::WriteFile(key_file_,
|
||||
reinterpret_cast<const char*>(public_key.data()),
|
||||
public_key.size()));
|
||||
EXPECT_TRUE(util_->IsPublicKeyPresent());
|
||||
|
||||
std::vector<uint8> from_disk;
|
||||
|
@@ -7,7 +7,6 @@
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/numerics/safe_math.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "components/webcrypto/algorithms/aes.h"
|
||||
#include "components/webcrypto/algorithms/util.h"
|
||||
#include "components/webcrypto/blink_key_handle.h"
|
||||
@@ -77,15 +76,13 @@ Status AesCbcEncryptDecrypt(EncryptOrDecrypt cipher_operation,
|
||||
|
||||
buffer->resize(output_max_len.ValueOrDie());
|
||||
|
||||
unsigned char* const buffer_data = vector_as_array(buffer);
|
||||
|
||||
int output_len = 0;
|
||||
if (!EVP_CipherUpdate(context.get(), buffer_data, &output_len, data.bytes(),
|
||||
data.byte_length())) {
|
||||
if (!EVP_CipherUpdate(context.get(), buffer->data(), &output_len,
|
||||
data.bytes(), data.byte_length())) {
|
||||
return Status::OperationError();
|
||||
}
|
||||
int final_output_chunk_len = 0;
|
||||
if (!EVP_CipherFinal_ex(context.get(), buffer_data + output_len,
|
||||
if (!EVP_CipherFinal_ex(context.get(), buffer->data() + output_len,
|
||||
&final_output_chunk_len)) {
|
||||
return Status::OperationError();
|
||||
}
|
||||
|
@@ -2,7 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "base/stl_util.h"
|
||||
#include "base/values.h"
|
||||
#include "components/webcrypto/algorithm_dispatch.h"
|
||||
#include "components/webcrypto/algorithms/test_helpers.h"
|
||||
@@ -20,7 +19,7 @@ blink::WebCryptoAlgorithm CreateAesCbcAlgorithm(
|
||||
const std::vector<uint8_t>& iv) {
|
||||
return blink::WebCryptoAlgorithm::adoptParamsAndCreate(
|
||||
blink::WebCryptoAlgorithmIdAesCbc,
|
||||
new blink::WebCryptoAesCbcParams(vector_as_array(&iv),
|
||||
new blink::WebCryptoAesCbcParams(iv.data(),
|
||||
static_cast<unsigned int>(iv.size())));
|
||||
}
|
||||
|
||||
|
@@ -8,7 +8,6 @@
|
||||
#include "base/logging.h"
|
||||
#include "base/macros.h"
|
||||
#include "base/numerics/safe_math.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "components/webcrypto/algorithms/aes.h"
|
||||
#include "components/webcrypto/algorithms/util.h"
|
||||
#include "components/webcrypto/blink_key_handle.h"
|
||||
@@ -104,8 +103,7 @@ crypto::ScopedBIGNUM GetCounter(const CryptoData& counter_block,
|
||||
counter_block.bytes() + counter_block.byte_length());
|
||||
counter[0] &= ~(0xFF << counter_length_remainder_bits);
|
||||
|
||||
return crypto::ScopedBIGNUM(
|
||||
BN_bin2bn(vector_as_array(&counter), counter.size(), NULL));
|
||||
return crypto::ScopedBIGNUM(BN_bin2bn(counter.data(), counter.size(), NULL));
|
||||
}
|
||||
|
||||
// Returns a counter block with the counter bits all set all zero.
|
||||
@@ -206,7 +204,7 @@ Status AesCtrEncryptDecrypt(const blink::WebCryptoAlgorithm& algorithm,
|
||||
// wrapping-around, do it as a single call into BoringSSL.
|
||||
if (BN_cmp(num_blocks_until_reset.get(), num_output_blocks.get()) >= 0) {
|
||||
return AesCtrEncrypt128BitCounter(cipher, CryptoData(raw_key), data,
|
||||
counter_block, vector_as_array(buffer));
|
||||
counter_block, buffer->data());
|
||||
}
|
||||
|
||||
// Otherwise the encryption needs to be done in 2 parts. The first part using
|
||||
@@ -222,7 +220,7 @@ Status AesCtrEncryptDecrypt(const blink::WebCryptoAlgorithm& algorithm,
|
||||
// Encrypt the first part (before wrap-around).
|
||||
Status status = AesCtrEncrypt128BitCounter(
|
||||
cipher, CryptoData(raw_key), CryptoData(data.bytes(), input_size_part1),
|
||||
counter_block, vector_as_array(buffer));
|
||||
counter_block, buffer->data());
|
||||
if (status.IsError())
|
||||
return status;
|
||||
|
||||
@@ -234,8 +232,7 @@ Status AesCtrEncryptDecrypt(const blink::WebCryptoAlgorithm& algorithm,
|
||||
cipher, CryptoData(raw_key),
|
||||
CryptoData(data.bytes() + input_size_part1,
|
||||
data.byte_length() - input_size_part1),
|
||||
CryptoData(counter_block_part2),
|
||||
vector_as_array(buffer) + input_size_part1);
|
||||
CryptoData(counter_block_part2), buffer->data() + input_size_part1);
|
||||
}
|
||||
|
||||
class AesCtrImplementation : public AesAlgorithm {
|
||||
|
@@ -2,7 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "base/stl_util.h"
|
||||
#include "base/values.h"
|
||||
#include "components/webcrypto/algorithm_dispatch.h"
|
||||
#include "components/webcrypto/algorithms/test_helpers.h"
|
||||
@@ -22,7 +21,7 @@ blink::WebCryptoAlgorithm CreateAesCtrAlgorithm(
|
||||
return blink::WebCryptoAlgorithm::adoptParamsAndCreate(
|
||||
blink::WebCryptoAlgorithmIdAesCtr,
|
||||
new blink::WebCryptoAesCtrParams(
|
||||
length_bits, vector_as_array(&counter),
|
||||
length_bits, counter.data(),
|
||||
static_cast<unsigned int>(counter.size())));
|
||||
}
|
||||
|
||||
@@ -140,8 +139,8 @@ TEST_F(WebCryptoAesCtrTest, OverflowAndRepeatCounter) {
|
||||
|
||||
// 16 and 17 AES blocks worth of data respectively (AES blocks are 16 bytes
|
||||
// long).
|
||||
CryptoData input_16(vector_as_array(&buffer), 256);
|
||||
CryptoData input_17(vector_as_array(&buffer), 272);
|
||||
CryptoData input_16(buffer.data(), 256);
|
||||
CryptoData input_17(buffer.data(), 272);
|
||||
|
||||
std::vector<uint8_t> output;
|
||||
|
||||
|
@@ -2,7 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "base/stl_util.h"
|
||||
#include "base/values.h"
|
||||
#include "components/webcrypto/algorithm_dispatch.h"
|
||||
#include "components/webcrypto/algorithms/test_helpers.h"
|
||||
@@ -24,8 +23,8 @@ blink::WebCryptoAlgorithm CreateAesGcmAlgorithm(
|
||||
return blink::WebCryptoAlgorithm::adoptParamsAndCreate(
|
||||
blink::WebCryptoAlgorithmIdAesGcm,
|
||||
new blink::WebCryptoAesGcmParams(
|
||||
vector_as_array(&iv), static_cast<unsigned int>(iv.size()), true,
|
||||
vector_as_array(&additional_data),
|
||||
iv.data(), static_cast<unsigned int>(iv.size()), true,
|
||||
additional_data.data(),
|
||||
static_cast<unsigned int>(additional_data.size()), true,
|
||||
tag_length_bits));
|
||||
}
|
||||
|
@@ -10,7 +10,6 @@
|
||||
#include <openssl/pkcs12.h>
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "components/webcrypto/algorithms/asymmetric_key_util.h"
|
||||
#include "components/webcrypto/algorithms/util.h"
|
||||
#include "components/webcrypto/blink_key_handle.h"
|
||||
@@ -159,10 +158,8 @@ Status WritePaddedBIGNUM(const std::string& member_name,
|
||||
size_t padded_length,
|
||||
JwkWriter* jwk) {
|
||||
std::vector<uint8_t> padded_bytes(padded_length);
|
||||
if (!BN_bn2bin_padded(vector_as_array(&padded_bytes), padded_bytes.size(),
|
||||
value)) {
|
||||
if (!BN_bn2bin_padded(padded_bytes.data(), padded_bytes.size(), value))
|
||||
return Status::OperationError();
|
||||
}
|
||||
jwk->SetBytes(member_name, CryptoData(padded_bytes));
|
||||
return Status::Success();
|
||||
}
|
||||
|
@@ -7,7 +7,6 @@
|
||||
#include <openssl/evp.h>
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "components/webcrypto/algorithm_implementation.h"
|
||||
#include "components/webcrypto/algorithms/ec.h"
|
||||
#include "components/webcrypto/algorithms/util.h"
|
||||
@@ -112,9 +111,8 @@ class EcdhImplementation : public EcAlgorithm {
|
||||
// buffer than field_size_bytes).
|
||||
derived_bytes->resize(NumBitsToBytes(length_bits));
|
||||
|
||||
int result =
|
||||
ECDH_compute_key(vector_as_array(derived_bytes), derived_bytes->size(),
|
||||
public_key_point, private_key_ec.get(), 0);
|
||||
int result = ECDH_compute_key(derived_bytes->data(), derived_bytes->size(),
|
||||
public_key_point, private_key_ec.get(), 0);
|
||||
if (result < 0 || static_cast<size_t>(result) != derived_bytes->size())
|
||||
return Status::OperationError();
|
||||
|
||||
|
@@ -7,7 +7,6 @@
|
||||
#include <openssl/evp.h>
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "components/webcrypto/algorithm_implementation.h"
|
||||
#include "components/webcrypto/algorithms/ec.h"
|
||||
#include "components/webcrypto/algorithms/util.h"
|
||||
@@ -66,16 +65,11 @@ Status ConvertDerSignatureToWebCryptoSignature(
|
||||
std::vector<uint8_t>* signature) {
|
||||
crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE);
|
||||
|
||||
const unsigned char* der_data = vector_as_array(signature);
|
||||
crypto::ScopedECDSA_SIG ecdsa_sig(
|
||||
d2i_ECDSA_SIG(NULL, &der_data, static_cast<long>(signature->size())));
|
||||
ECDSA_SIG_from_bytes(signature->data(), signature->size()));
|
||||
if (!ecdsa_sig.get())
|
||||
return Status::ErrorUnexpected();
|
||||
|
||||
// |der_data| is updated to point to past the end of the DER structure.
|
||||
if (der_data != vector_as_array(signature) + signature->size())
|
||||
return Status::ErrorUnexpected();
|
||||
|
||||
// Determine the maximum length of r and s.
|
||||
size_t order_size_bytes;
|
||||
Status status = GetEcGroupOrderSize(key, &order_size_bytes);
|
||||
@@ -84,7 +78,7 @@ Status ConvertDerSignatureToWebCryptoSignature(
|
||||
|
||||
signature->resize(order_size_bytes * 2);
|
||||
|
||||
if (!BN_bn2bin_padded(vector_as_array(signature), order_size_bytes,
|
||||
if (!BN_bn2bin_padded(signature->data(), order_size_bytes,
|
||||
ecdsa_sig.get()->r)) {
|
||||
return Status::ErrorUnexpected();
|
||||
}
|
||||
@@ -149,7 +143,7 @@ Status ConvertWebCryptoSignatureToDerSignature(
|
||||
|
||||
// DER-encode the signature.
|
||||
der_signature->resize(der_encoding_size);
|
||||
uint8_t* result = vector_as_array(der_signature);
|
||||
uint8_t* result = der_signature->data();
|
||||
if (0 > i2d_ECDSA_SIG(ecdsa_sig.get(), &result))
|
||||
return Status::OperationError();
|
||||
|
||||
@@ -205,7 +199,7 @@ class EcdsaImplementation : public EcAlgorithm {
|
||||
}
|
||||
|
||||
buffer->resize(sig_len);
|
||||
if (!EVP_DigestSignFinal(ctx.get(), vector_as_array(buffer), &sig_len))
|
||||
if (!EVP_DigestSignFinal(ctx.get(), buffer->data(), &sig_len))
|
||||
return Status::OperationError();
|
||||
buffer->resize(sig_len);
|
||||
|
||||
@@ -250,7 +244,7 @@ class EcdsaImplementation : public EcAlgorithm {
|
||||
}
|
||||
|
||||
*signature_match =
|
||||
1 == EVP_DigestVerifyFinal(ctx.get(), vector_as_array(&der_signature),
|
||||
1 == EVP_DigestVerifyFinal(ctx.get(), der_signature.data(),
|
||||
der_signature.size());
|
||||
return Status::Success();
|
||||
}
|
||||
|
@@ -6,7 +6,6 @@
|
||||
#include <openssl/hkdf.h>
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "components/webcrypto/algorithm_implementation.h"
|
||||
#include "components/webcrypto/algorithms/secret_key_util.h"
|
||||
#include "components/webcrypto/algorithms/util.h"
|
||||
@@ -69,10 +68,10 @@ class HkdfImplementation : public AlgorithmImplementation {
|
||||
// Algorithm dispatch checks that the algorithm in |base_key| matches
|
||||
// |algorithm|.
|
||||
const std::vector<uint8_t>& raw_key = GetSymmetricKeyData(base_key);
|
||||
if (!HKDF(vector_as_array(derived_bytes), derived_bytes_len,
|
||||
digest_algorithm, vector_as_array(&raw_key), raw_key.size(),
|
||||
params->salt().data(), params->salt().size(),
|
||||
params->info().data(), params->info().size())) {
|
||||
if (!HKDF(derived_bytes->data(), derived_bytes_len, digest_algorithm,
|
||||
raw_key.data(), raw_key.size(), params->salt().data(),
|
||||
params->salt().size(), params->info().data(),
|
||||
params->info().size())) {
|
||||
uint32_t error = ERR_get_error();
|
||||
if (ERR_GET_LIB(error) == ERR_LIB_HKDF &&
|
||||
ERR_GET_REASON(error) == HKDF_R_OUTPUT_TOO_LARGE) {
|
||||
|
@@ -6,7 +6,6 @@
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/numerics/safe_math.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "components/webcrypto/algorithm_implementation.h"
|
||||
#include "components/webcrypto/algorithms/secret_key_util.h"
|
||||
#include "components/webcrypto/algorithms/util.h"
|
||||
@@ -95,12 +94,12 @@ Status SignHmac(const std::vector<uint8_t>& raw_key,
|
||||
|
||||
buffer->resize(hmac_expected_length);
|
||||
crypto::ScopedOpenSSLSafeSizeBuffer<EVP_MAX_MD_SIZE> hmac_result(
|
||||
vector_as_array(buffer), hmac_expected_length);
|
||||
buffer->data(), hmac_expected_length);
|
||||
|
||||
unsigned int hmac_actual_length;
|
||||
unsigned char* const success = HMAC(
|
||||
digest_algorithm, vector_as_array(&raw_key), raw_key.size(), data.bytes(),
|
||||
data.byte_length(), hmac_result.safe_buffer(), &hmac_actual_length);
|
||||
unsigned char* const success =
|
||||
HMAC(digest_algorithm, raw_key.data(), raw_key.size(), data.bytes(),
|
||||
data.byte_length(), hmac_result.safe_buffer(), &hmac_actual_length);
|
||||
if (!success || hmac_actual_length != hmac_expected_length)
|
||||
return Status::OperationError();
|
||||
|
||||
@@ -250,10 +249,9 @@ class HmacImplementation : public AlgorithmImplementation {
|
||||
return status;
|
||||
|
||||
// Do not allow verification of truncated MACs.
|
||||
*signature_match =
|
||||
result.size() == signature.byte_length() &&
|
||||
crypto::SecureMemEqual(vector_as_array(&result), signature.bytes(),
|
||||
signature.byte_length());
|
||||
*signature_match = result.size() == signature.byte_length() &&
|
||||
crypto::SecureMemEqual(result.data(), signature.bytes(),
|
||||
signature.byte_length());
|
||||
|
||||
return Status::Success();
|
||||
}
|
||||
|
@@ -3,7 +3,6 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "base/values.h"
|
||||
#include "components/webcrypto/algorithm_dispatch.h"
|
||||
#include "components/webcrypto/algorithms/test_helpers.h"
|
||||
@@ -92,7 +91,7 @@ TEST_F(WebCryptoHmacTest, HMACSampleSets) {
|
||||
// Ensure truncated signature does not verify by passing one less byte.
|
||||
EXPECT_EQ(Status::Success(),
|
||||
Verify(algorithm, key,
|
||||
CryptoData(vector_as_array(&output),
|
||||
CryptoData(output.data(),
|
||||
static_cast<unsigned int>(output.size()) - 1),
|
||||
CryptoData(test_message), &signature_match));
|
||||
EXPECT_FALSE(signature_match);
|
||||
|
@@ -76,10 +76,9 @@ class Pbkdf2Implementation : public AlgorithmImplementation {
|
||||
const std::vector<uint8_t>& password = GetSymmetricKeyData(base_key);
|
||||
|
||||
if (!PKCS5_PBKDF2_HMAC(
|
||||
reinterpret_cast<const char*>(vector_as_array(&password)),
|
||||
password.size(), params->salt().data(), params->salt().size(),
|
||||
params->iterations(), digest_algorithm, keylen_bytes,
|
||||
vector_as_array(derived_bytes))) {
|
||||
reinterpret_cast<const char*>(password.data()), password.size(),
|
||||
params->salt().data(), params->salt().size(), params->iterations(),
|
||||
digest_algorithm, keylen_bytes, derived_bytes->data())) {
|
||||
return Status::OperationError();
|
||||
}
|
||||
return Status::Success();
|
||||
|
@@ -7,7 +7,6 @@
|
||||
#include <openssl/evp.h>
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "components/webcrypto/algorithms/asymmetric_key_util.h"
|
||||
#include "components/webcrypto/algorithms/util.h"
|
||||
#include "components/webcrypto/blink_key_handle.h"
|
||||
@@ -232,7 +231,7 @@ Status ImportRsaPublicKey(const blink::WebCryptoAlgorithm& algorithm,
|
||||
// Converts a BIGNUM to a big endian byte array.
|
||||
std::vector<uint8_t> BIGNUMToVector(const BIGNUM* n) {
|
||||
std::vector<uint8_t> v(BN_num_bytes(n));
|
||||
BN_bn2bin(n, vector_as_array(&v));
|
||||
BN_bn2bin(n, v.data());
|
||||
return v;
|
||||
}
|
||||
|
||||
|
@@ -4,7 +4,6 @@
|
||||
|
||||
#include <openssl/evp.h>
|
||||
|
||||
#include "base/stl_util.h"
|
||||
#include "components/webcrypto/algorithms/rsa.h"
|
||||
#include "components/webcrypto/algorithms/util.h"
|
||||
#include "components/webcrypto/blink_key_handle.h"
|
||||
@@ -80,8 +79,8 @@ Status CommonEncryptDecrypt(InitFunc init_func,
|
||||
buffer->resize(outlen);
|
||||
|
||||
// Do the actual encryption/decryption.
|
||||
if (!encrypt_decrypt_func(ctx.get(), vector_as_array(buffer), &outlen,
|
||||
data.bytes(), data.byte_length())) {
|
||||
if (!encrypt_decrypt_func(ctx.get(), buffer->data(), &outlen, data.bytes(),
|
||||
data.byte_length())) {
|
||||
return Status::OperationError();
|
||||
}
|
||||
buffer->resize(outlen);
|
||||
|
@@ -4,7 +4,6 @@
|
||||
|
||||
#include "base/base64url.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "components/webcrypto/algorithm_dispatch.h"
|
||||
#include "components/webcrypto/algorithms/test_helpers.h"
|
||||
#include "components/webcrypto/crypto_data.h"
|
||||
@@ -24,7 +23,7 @@ blink::WebCryptoAlgorithm CreateRsaOaepAlgorithm(
|
||||
return blink::WebCryptoAlgorithm::adoptParamsAndCreate(
|
||||
blink::WebCryptoAlgorithmIdRsaOaep,
|
||||
new blink::WebCryptoRsaOaepParams(
|
||||
!label.empty(), vector_as_array(&label),
|
||||
!label.empty(), label.data(),
|
||||
static_cast<unsigned int>(label.size())));
|
||||
}
|
||||
|
||||
@@ -33,7 +32,7 @@ std::string Base64EncodeUrlSafe(const std::vector<uint8_t>& input) {
|
||||
// https://tools.ietf.org/html/draft-ietf-jose-json-web-signature-36#section-2
|
||||
std::string base64url_encoded;
|
||||
base::Base64UrlEncode(
|
||||
base::StringPiece(reinterpret_cast<const char*>(vector_as_array(&input)),
|
||||
base::StringPiece(reinterpret_cast<const char*>(input.data()),
|
||||
input.size()),
|
||||
base::Base64UrlEncodePolicy::OMIT_PADDING, &base64url_encoded);
|
||||
return base64url_encoded;
|
||||
|
@@ -3,7 +3,6 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "base/numerics/safe_math.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "components/webcrypto/algorithms/rsa_sign.h"
|
||||
#include "components/webcrypto/algorithms/util.h"
|
||||
#include "components/webcrypto/blink_key_handle.h"
|
||||
@@ -102,7 +101,7 @@ Status RsaSign(const blink::WebCryptoKey& key,
|
||||
}
|
||||
|
||||
buffer->resize(sig_len);
|
||||
if (!EVP_DigestSignFinal(ctx.get(), vector_as_array(buffer), &sig_len))
|
||||
if (!EVP_DigestSignFinal(ctx.get(), buffer->data(), &sig_len))
|
||||
return Status::OperationError();
|
||||
|
||||
buffer->resize(sig_len);
|
||||
|
@@ -3,7 +3,6 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "base/values.h"
|
||||
#include "components/webcrypto/algorithm_dispatch.h"
|
||||
#include "components/webcrypto/algorithms/test_helpers.h"
|
||||
@@ -546,7 +545,7 @@ TEST_F(WebCryptoRsaSsaTest, SignVerifyFailures) {
|
||||
// Ensure truncated signature does not verify by passing one less byte.
|
||||
EXPECT_EQ(Status::Success(),
|
||||
Verify(algorithm, public_key,
|
||||
CryptoData(vector_as_array(&signature),
|
||||
CryptoData(signature.data(),
|
||||
static_cast<unsigned int>(signature.size()) - 1),
|
||||
CryptoData(data), &signature_match));
|
||||
EXPECT_FALSE(signature_match);
|
||||
|
@@ -6,7 +6,6 @@
|
||||
|
||||
#include <openssl/rand.h>
|
||||
|
||||
#include "base/stl_util.h"
|
||||
#include "components/webcrypto/algorithms/util.h"
|
||||
#include "components/webcrypto/blink_key_handle.h"
|
||||
#include "components/webcrypto/crypto_data.h"
|
||||
@@ -25,10 +24,10 @@ Status GenerateWebCryptoSecretKey(const blink::WebCryptoKeyAlgorithm& algorithm,
|
||||
crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE);
|
||||
|
||||
unsigned int keylen_bytes = NumBitsToBytes(keylen_bits);
|
||||
std::vector<unsigned char> random_bytes(keylen_bytes, 0);
|
||||
std::vector<uint8_t> random_bytes(keylen_bytes, 0);
|
||||
|
||||
if (keylen_bytes > 0) {
|
||||
if (!RAND_bytes(vector_as_array(&random_bytes), keylen_bytes))
|
||||
if (!RAND_bytes(random_bytes.data(), keylen_bytes))
|
||||
return Status::OperationError();
|
||||
TruncateToBitLength(keylen_bits, &random_bytes);
|
||||
}
|
||||
|
@@ -7,7 +7,6 @@
|
||||
#include <vector>
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "components/webcrypto/algorithm_implementation.h"
|
||||
#include "components/webcrypto/algorithms/util.h"
|
||||
#include "components/webcrypto/crypto_data.h"
|
||||
@@ -58,9 +57,8 @@ class DigestorImpl : public blink::WebCryptoDigestor {
|
||||
Status FinishWithVectorAndStatus(std::vector<uint8_t>* result) {
|
||||
const int hash_expected_size = EVP_MD_CTX_size(digest_context_.get());
|
||||
result->resize(hash_expected_size);
|
||||
unsigned char* const hash_buffer = vector_as_array(result);
|
||||
unsigned int hash_buffer_size; // ignored
|
||||
return FinishInternal(hash_buffer, &hash_buffer_size);
|
||||
return FinishInternal(result->data(), &hash_buffer_size);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@@ -3,7 +3,6 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "base/values.h"
|
||||
#include "components/webcrypto/algorithm_dispatch.h"
|
||||
#include "components/webcrypto/algorithms/test_helpers.h"
|
||||
@@ -69,7 +68,7 @@ TEST_F(WebCryptoShaTest, DigestSampleSetsInChunks) {
|
||||
size_t chunk_length = std::min(kChunkSizeBytes, length - chunk_index);
|
||||
std::vector<uint8_t> chunk(begin, begin + chunk_length);
|
||||
ASSERT_TRUE(chunk.size() > 0);
|
||||
EXPECT_TRUE(digestor->consume(vector_as_array(&chunk),
|
||||
EXPECT_TRUE(digestor->consume(chunk.data(),
|
||||
static_cast<unsigned int>(chunk.size())));
|
||||
chunk_index = chunk_index + chunk_length;
|
||||
begin = begin + chunk_length;
|
||||
|
@@ -12,7 +12,6 @@
|
||||
#include "base/json/json_writer.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/path_service.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "base/values.h"
|
||||
@@ -110,10 +109,10 @@ blink::WebCryptoAlgorithm CreateRsaHashedKeyGenAlgorithm(
|
||||
const std::vector<uint8_t>& public_exponent) {
|
||||
DCHECK(blink::WebCryptoAlgorithm::isHash(hash_id));
|
||||
return blink::WebCryptoAlgorithm::adoptParamsAndCreate(
|
||||
algorithm_id, new blink::WebCryptoRsaHashedKeyGenParams(
|
||||
CreateAlgorithm(hash_id), modulus_length,
|
||||
vector_as_array(&public_exponent),
|
||||
static_cast<unsigned int>(public_exponent.size())));
|
||||
algorithm_id,
|
||||
new blink::WebCryptoRsaHashedKeyGenParams(
|
||||
CreateAlgorithm(hash_id), modulus_length, public_exponent.data(),
|
||||
static_cast<unsigned int>(public_exponent.size())));
|
||||
}
|
||||
|
||||
std::vector<uint8_t> Corrupted(const std::vector<uint8_t>& input) {
|
||||
@@ -388,8 +387,8 @@ Status ImportKeyJwkFromDict(const base::DictionaryValue& dict,
|
||||
|
||||
scoped_ptr<base::DictionaryValue> GetJwkDictionary(
|
||||
const std::vector<uint8_t>& json) {
|
||||
base::StringPiece json_string(
|
||||
reinterpret_cast<const char*>(vector_as_array(&json)), json.size());
|
||||
base::StringPiece json_string(reinterpret_cast<const char*>(json.data()),
|
||||
json.size());
|
||||
scoped_ptr<base::Value> value = base::JSONReader::Read(json_string);
|
||||
EXPECT_TRUE(value.get());
|
||||
EXPECT_TRUE(value->IsType(base::Value::TYPE_DICTIONARY));
|
||||
|
@@ -9,7 +9,6 @@
|
||||
#include <openssl/digest.h>
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "components/webcrypto/crypto_data.h"
|
||||
#include "components/webcrypto/status.h"
|
||||
#include "crypto/openssl_util.h"
|
||||
@@ -87,8 +86,8 @@ Status AeadEncryptDecrypt(EncryptOrDecrypt mode,
|
||||
if (!aead_alg)
|
||||
return Status::ErrorUnexpected();
|
||||
|
||||
if (!EVP_AEAD_CTX_init(&ctx, aead_alg, vector_as_array(&raw_key),
|
||||
raw_key.size(), tag_length_bytes, NULL)) {
|
||||
if (!EVP_AEAD_CTX_init(&ctx, aead_alg, raw_key.data(), raw_key.size(),
|
||||
tag_length_bytes, NULL)) {
|
||||
return Status::OperationError();
|
||||
}
|
||||
|
||||
@@ -103,7 +102,7 @@ Status AeadEncryptDecrypt(EncryptOrDecrypt mode,
|
||||
|
||||
buffer->resize(data.byte_length() - tag_length_bytes);
|
||||
|
||||
ok = EVP_AEAD_CTX_open(&ctx, vector_as_array(buffer), &len, buffer->size(),
|
||||
ok = EVP_AEAD_CTX_open(&ctx, buffer->data(), &len, buffer->size(),
|
||||
iv.bytes(), iv.byte_length(), data.bytes(),
|
||||
data.byte_length(), additional_data.bytes(),
|
||||
additional_data.byte_length());
|
||||
@@ -112,7 +111,7 @@ Status AeadEncryptDecrypt(EncryptOrDecrypt mode,
|
||||
// the output buffer is too small).
|
||||
buffer->resize(data.byte_length() + EVP_AEAD_max_overhead(aead_alg));
|
||||
|
||||
ok = EVP_AEAD_CTX_seal(&ctx, vector_as_array(buffer), &len, buffer->size(),
|
||||
ok = EVP_AEAD_CTX_seal(&ctx, buffer->data(), &len, buffer->size(),
|
||||
iv.bytes(), iv.byte_length(), data.bytes(),
|
||||
data.byte_length(), additional_data.bytes(),
|
||||
additional_data.byte_length());
|
||||
|
@@ -3,7 +3,6 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "components/webcrypto/crypto_data.h"
|
||||
#include "base/stl_util.h"
|
||||
|
||||
namespace webcrypto {
|
||||
|
||||
@@ -15,9 +14,8 @@ CryptoData::CryptoData(const unsigned char* bytes, unsigned int byte_length)
|
||||
}
|
||||
|
||||
CryptoData::CryptoData(const std::vector<unsigned char>& bytes)
|
||||
: bytes_(vector_as_array(&bytes)),
|
||||
byte_length_(static_cast<unsigned int>(bytes.size())) {
|
||||
}
|
||||
: bytes_(bytes.data()),
|
||||
byte_length_(static_cast<unsigned int>(bytes.size())) {}
|
||||
|
||||
CryptoData::CryptoData(const std::string& bytes)
|
||||
: bytes_(bytes.size() ? reinterpret_cast<const unsigned char*>(bytes.data())
|
||||
|
@@ -10,7 +10,6 @@
|
||||
#include "base/logging.h"
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "base/single_thread_task_runner.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "base/task_runner.h"
|
||||
#include "base/thread_task_runner_handle.h"
|
||||
#include "base/threading/sequenced_worker_pool.h"
|
||||
@@ -118,7 +117,7 @@ void CompleteWithBufferOrError(const Status& status,
|
||||
// theoretically this could overflow.
|
||||
CompleteWithError(Status::ErrorUnexpected(), result);
|
||||
} else {
|
||||
result->completeWithBuffer(vector_as_array(&buffer),
|
||||
result->completeWithBuffer(buffer.data(),
|
||||
static_cast<unsigned int>(buffer.size()));
|
||||
}
|
||||
}
|
||||
@@ -467,7 +466,7 @@ void DoExportKeyReply(scoped_ptr<ExportKeyState> state) {
|
||||
CompleteWithError(state->status, &state->result);
|
||||
} else {
|
||||
state->result.completeWithJson(
|
||||
reinterpret_cast<const char*>(vector_as_array(&state->buffer)),
|
||||
reinterpret_cast<const char*>(state->buffer.data()),
|
||||
static_cast<unsigned int>(state->buffer.size()));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user