OLD | NEW |
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 { | |
15 | |
16 namespace webcrypto { | 14 namespace webcrypto { |
17 | 15 |
18 namespace { | 16 namespace { |
19 | 17 |
20 // Converts a (big-endian) WebCrypto BigInteger, with or without leading zeros, | 18 // Converts a (big-endian) WebCrypto BigInteger, with or without leading zeros, |
21 // to unsigned int. | 19 // to unsigned int. |
22 bool BigIntegerToUint(const uint8_t* data, | 20 bool BigIntegerToUint(const uint8_t* data, |
23 unsigned int data_size, | 21 unsigned int data_size, |
24 unsigned int* result) { | 22 unsigned int* result) { |
25 if (data_size == 0) | 23 if (data_size == 0) |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 blink::WebCryptoKeyUsageMask usages) { | 233 blink::WebCryptoKeyUsageMask usages) { |
236 switch (format) { | 234 switch (format) { |
237 case blink::WebCryptoKeyFormatSpki: | 235 case blink::WebCryptoKeyFormatSpki: |
238 return CheckKeyCreationUsages(all_public_key_usages, usages, true); | 236 return CheckKeyCreationUsages(all_public_key_usages, usages, true); |
239 case blink::WebCryptoKeyFormatPkcs8: | 237 case blink::WebCryptoKeyFormatPkcs8: |
240 return CheckKeyCreationUsages(all_private_key_usages, usages, false); | 238 return CheckKeyCreationUsages(all_private_key_usages, usages, false); |
241 case blink::WebCryptoKeyFormatJwk: { | 239 case blink::WebCryptoKeyFormatJwk: { |
242 // The JWK could represent either a public key or private key. The usages | 240 // 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 | 241 // must make sense for one of the two. The usages will be checked again by |
244 // ImportKeyJwk() once the key type has been determined. | 242 // ImportKeyJwk() once the key type has been determined. |
245 if (CheckKeyCreationUsages( | 243 if (CheckKeyCreationUsages(all_public_key_usages, usages, true) |
246 all_public_key_usages, usages, true).IsError() && | 244 .IsError() && |
247 CheckKeyCreationUsages( | 245 CheckKeyCreationUsages(all_private_key_usages, usages, false) |
248 all_private_key_usages, usages, false).IsError()) { | 246 .IsError()) { |
249 return Status::ErrorCreateKeyBadUsages(); | 247 return Status::ErrorCreateKeyBadUsages(); |
250 } | 248 } |
251 return Status::Success(); | 249 return Status::Success(); |
252 } | 250 } |
253 default: | 251 default: |
254 return Status::ErrorUnsupportedImportKeyFormat(); | 252 return Status::ErrorUnsupportedImportKeyFormat(); |
255 } | 253 } |
256 } | 254 } |
257 | 255 |
258 void TruncateToBitLength(size_t length_bits, std::vector<uint8_t>* bytes) { | 256 void TruncateToBitLength(size_t length_bits, std::vector<uint8_t>* bytes) { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 *public_usages = combined_usages & all_public_usages; | 319 *public_usages = combined_usages & all_public_usages; |
322 *private_usages = combined_usages & all_private_usages; | 320 *private_usages = combined_usages & all_private_usages; |
323 | 321 |
324 if (*private_usages == 0) | 322 if (*private_usages == 0) |
325 return Status::ErrorCreateKeyEmptyUsages(); | 323 return Status::ErrorCreateKeyEmptyUsages(); |
326 | 324 |
327 return Status::Success(); | 325 return Status::Success(); |
328 } | 326 } |
329 | 327 |
330 } // namespace webcrypto | 328 } // namespace webcrypto |
331 | |
332 } // namespace content | |
OLD | NEW |