Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(613)

Side by Side Diff: components/webcrypto/algorithms/secret_key_util.cc

Issue 1461703009: Switch //components from vector_as_array to vector::data. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: eroman comment Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/webcrypto/algorithms/secret_key_util.h" 5 #include "components/webcrypto/algorithms/secret_key_util.h"
6 6
7 #include <openssl/rand.h> 7 #include <openssl/rand.h>
8 8
9 #include "base/stl_util.h"
10 #include "components/webcrypto/algorithms/util.h" 9 #include "components/webcrypto/algorithms/util.h"
11 #include "components/webcrypto/blink_key_handle.h" 10 #include "components/webcrypto/blink_key_handle.h"
12 #include "components/webcrypto/crypto_data.h" 11 #include "components/webcrypto/crypto_data.h"
13 #include "components/webcrypto/generate_key_result.h" 12 #include "components/webcrypto/generate_key_result.h"
14 #include "components/webcrypto/jwk.h" 13 #include "components/webcrypto/jwk.h"
15 #include "components/webcrypto/status.h" 14 #include "components/webcrypto/status.h"
16 #include "crypto/openssl_util.h" 15 #include "crypto/openssl_util.h"
17 16
18 namespace webcrypto { 17 namespace webcrypto {
19 18
20 Status GenerateWebCryptoSecretKey(const blink::WebCryptoKeyAlgorithm& algorithm, 19 Status GenerateWebCryptoSecretKey(const blink::WebCryptoKeyAlgorithm& algorithm,
21 bool extractable, 20 bool extractable,
22 blink::WebCryptoKeyUsageMask usages, 21 blink::WebCryptoKeyUsageMask usages,
23 unsigned int keylen_bits, 22 unsigned int keylen_bits,
24 GenerateKeyResult* result) { 23 GenerateKeyResult* result) {
25 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); 24 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE);
26 25
27 unsigned int keylen_bytes = NumBitsToBytes(keylen_bits); 26 unsigned int keylen_bytes = NumBitsToBytes(keylen_bits);
28 std::vector<unsigned char> random_bytes(keylen_bytes, 0); 27 std::vector<uint8_t> random_bytes(keylen_bytes, 0);
29 28
30 if (keylen_bytes > 0) { 29 if (keylen_bytes > 0) {
31 if (!RAND_bytes(vector_as_array(&random_bytes), keylen_bytes)) 30 if (!RAND_bytes(random_bytes.data(), keylen_bytes))
32 return Status::OperationError(); 31 return Status::OperationError();
33 TruncateToBitLength(keylen_bits, &random_bytes); 32 TruncateToBitLength(keylen_bits, &random_bytes);
34 } 33 }
35 34
36 result->AssignSecretKey(blink::WebCryptoKey::create( 35 result->AssignSecretKey(blink::WebCryptoKey::create(
37 CreateSymmetricKeyHandle(CryptoData(random_bytes)), 36 CreateSymmetricKeyHandle(CryptoData(random_bytes)),
38 blink::WebCryptoKeyTypeSecret, extractable, algorithm, usages)); 37 blink::WebCryptoKeyTypeSecret, extractable, algorithm, usages));
39 38
40 return Status::Success(); 39 return Status::Success();
41 } 40 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 std::string jwk_k_value; 81 std::string jwk_k_value;
83 status = jwk->GetBytes("k", &jwk_k_value); 82 status = jwk->GetBytes("k", &jwk_k_value);
84 if (status.IsError()) 83 if (status.IsError())
85 return status; 84 return status;
86 raw_key_data->assign(jwk_k_value.begin(), jwk_k_value.end()); 85 raw_key_data->assign(jwk_k_value.begin(), jwk_k_value.end());
87 86
88 return Status::Success(); 87 return Status::Success();
89 } 88 }
90 89
91 } // namespace webcrypto 90 } // namespace webcrypto
OLDNEW
« no previous file with comments | « components/webcrypto/algorithms/rsa_ssa_unittest.cc ('k') | components/webcrypto/algorithms/sha.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698