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

Side by Side Diff: components/webcrypto/webcrypto_util.cc

Issue 1077273002: html_viewer: Move webcrypto to a place where html_viewer can use it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Copy the msvs_disabled_warnings to the new target. Created 5 years, 8 months 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/child/webcrypto/webcrypto_util.h" 5 #include "components/webcrypto/webcrypto_util.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/numerics/safe_math.h" 8 #include "base/numerics/safe_math.h"
9 #include "content/child/webcrypto/status.h" 9 #include "components/webcrypto/status.h"
10 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" 10 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h"
11 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" 11 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h"
12 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" 12 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h"
13 13
14 namespace content { 14 namespace components {
15 15
16 namespace webcrypto { 16 namespace webcrypto {
17 17
18 namespace { 18 namespace {
19 19
20 // Converts a (big-endian) WebCrypto BigInteger, with or without leading zeros, 20 // Converts a (big-endian) WebCrypto BigInteger, with or without leading zeros,
21 // to unsigned int. 21 // to unsigned int.
22 bool BigIntegerToUint(const uint8_t* data, 22 bool BigIntegerToUint(const uint8_t* data,
23 unsigned int data_size, 23 unsigned int data_size,
24 unsigned int* result) { 24 unsigned int* result) {
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 blink::WebCryptoKeyUsageMask usages) { 235 blink::WebCryptoKeyUsageMask usages) {
236 switch (format) { 236 switch (format) {
237 case blink::WebCryptoKeyFormatSpki: 237 case blink::WebCryptoKeyFormatSpki:
238 return CheckKeyCreationUsages(all_public_key_usages, usages, true); 238 return CheckKeyCreationUsages(all_public_key_usages, usages, true);
239 case blink::WebCryptoKeyFormatPkcs8: 239 case blink::WebCryptoKeyFormatPkcs8:
240 return CheckKeyCreationUsages(all_private_key_usages, usages, false); 240 return CheckKeyCreationUsages(all_private_key_usages, usages, false);
241 case blink::WebCryptoKeyFormatJwk: { 241 case blink::WebCryptoKeyFormatJwk: {
242 // The JWK could represent either a public key or private key. The usages 242 // The JWK could represent either a public key or private key. The usages
243 // must make sense for one of the two. The usages will be checked again by 243 // must make sense for one of the two. The usages will be checked again by
244 // ImportKeyJwk() once the key type has been determined. 244 // ImportKeyJwk() once the key type has been determined.
245 if (CheckKeyCreationUsages( 245 if (CheckKeyCreationUsages(all_public_key_usages, usages, true)
246 all_public_key_usages, usages, true).IsError() && 246 .IsError() &&
247 CheckKeyCreationUsages( 247 CheckKeyCreationUsages(all_private_key_usages, usages, false)
248 all_private_key_usages, usages, false).IsError()) { 248 .IsError()) {
249 return Status::ErrorCreateKeyBadUsages(); 249 return Status::ErrorCreateKeyBadUsages();
250 } 250 }
251 return Status::Success(); 251 return Status::Success();
252 } 252 }
253 default: 253 default:
254 return Status::ErrorUnsupportedImportKeyFormat(); 254 return Status::ErrorUnsupportedImportKeyFormat();
255 } 255 }
256 } 256 }
257 257
258 void TruncateToBitLength(size_t length_bits, std::vector<uint8_t>* bytes) { 258 void TruncateToBitLength(size_t length_bits, std::vector<uint8_t>* bytes) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 *private_usages = combined_usages & all_private_usages; 322 *private_usages = combined_usages & all_private_usages;
323 323
324 if (*private_usages == 0) 324 if (*private_usages == 0)
325 return Status::ErrorCreateKeyEmptyUsages(); 325 return Status::ErrorCreateKeyEmptyUsages();
326 326
327 return Status::Success(); 327 return Status::Success();
328 } 328 }
329 329
330 } // namespace webcrypto 330 } // namespace webcrypto
331 331
332 } // namespace content 332 } // namespace components
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698