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

Side by Side Diff: content/child/webcrypto/nss/aes_key_nss.cc

Issue 777403004: [WebCrypto] Throw syntaxError if keyUsage is empty in ImportKey (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated issues in ecdh tests and other review comments. Created 6 years 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/nss/aes_key_nss.h" 5 #include "content/child/webcrypto/nss/aes_key_nss.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "content/child/webcrypto/crypto_data.h" 8 #include "content/child/webcrypto/crypto_data.h"
9 #include "content/child/webcrypto/jwk.h" 9 #include "content/child/webcrypto/jwk.h"
10 #include "content/child/webcrypto/nss/key_nss.h" 10 #include "content/child/webcrypto/nss/key_nss.h"
(...skipping 21 matching lines...) Expand all
32 blink::WebCryptoKeyUsageDecrypt | 32 blink::WebCryptoKeyUsageDecrypt |
33 blink::WebCryptoKeyUsageWrapKey | 33 blink::WebCryptoKeyUsageWrapKey |
34 blink::WebCryptoKeyUsageUnwrapKey), 34 blink::WebCryptoKeyUsageUnwrapKey),
35 jwk_suffix_(jwk_suffix) { 35 jwk_suffix_(jwk_suffix) {
36 } 36 }
37 37
38 Status AesAlgorithm::GenerateKey(const blink::WebCryptoAlgorithm& algorithm, 38 Status AesAlgorithm::GenerateKey(const blink::WebCryptoAlgorithm& algorithm,
39 bool extractable, 39 bool extractable,
40 blink::WebCryptoKeyUsageMask usages, 40 blink::WebCryptoKeyUsageMask usages,
41 GenerateKeyResult* result) const { 41 GenerateKeyResult* result) const {
42 Status status = CheckKeyCreationUsages(all_key_usages_, usages); 42 Status status = CheckKeyCreationUsages(all_key_usages_, usages, false);
43 if (status.IsError()) 43 if (status.IsError())
44 return status; 44 return status;
45 45
46 unsigned int keylen_bits; 46 unsigned int keylen_bits;
47 status = GetAesKeyGenLengthInBits(algorithm.aesKeyGenParams(), &keylen_bits); 47 status = GetAesKeyGenLengthInBits(algorithm.aesKeyGenParams(), &keylen_bits);
48 if (status.IsError()) 48 if (status.IsError())
49 return status; 49 return status;
50 50
51 return GenerateSecretKeyNss( 51 return GenerateSecretKeyNss(
52 blink::WebCryptoKeyAlgorithm::createAes(algorithm.id(), keylen_bits), 52 blink::WebCryptoKeyAlgorithm::createAes(algorithm.id(), keylen_bits),
53 extractable, usages, keylen_bits, CKM_AES_KEY_GEN, result); 53 extractable, usages, keylen_bits, CKM_AES_KEY_GEN, result);
54 } 54 }
55 55
56 Status AesAlgorithm::VerifyKeyUsagesBeforeImportKey( 56 Status AesAlgorithm::VerifyKeyUsagesBeforeImportKey(
57 blink::WebCryptoKeyFormat format, 57 blink::WebCryptoKeyFormat format,
58 blink::WebCryptoKeyUsageMask usages) const { 58 blink::WebCryptoKeyUsageMask usages) const {
59 switch (format) { 59 switch (format) {
60 case blink::WebCryptoKeyFormatRaw: 60 case blink::WebCryptoKeyFormatRaw:
61 case blink::WebCryptoKeyFormatJwk: 61 case blink::WebCryptoKeyFormatJwk:
62 return CheckKeyCreationUsages(all_key_usages_, usages); 62 return CheckKeyCreationUsages(all_key_usages_, usages, false);
63 default: 63 default:
64 return Status::ErrorUnsupportedImportKeyFormat(); 64 return Status::ErrorUnsupportedImportKeyFormat();
65 } 65 }
66 } 66 }
67 Status AesAlgorithm::ImportKeyRaw(const CryptoData& key_data, 67 Status AesAlgorithm::ImportKeyRaw(const CryptoData& key_data,
68 const blink::WebCryptoAlgorithm& algorithm, 68 const blink::WebCryptoAlgorithm& algorithm,
69 bool extractable, 69 bool extractable,
70 blink::WebCryptoKeyUsageMask usages, 70 blink::WebCryptoKeyUsageMask usages,
71 blink::WebCryptoKey* key) const { 71 blink::WebCryptoKey* key) const {
72 const unsigned int keylen_bytes = key_data.byte_length(); 72 const unsigned int keylen_bytes = key_data.byte_length();
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 Status AesAlgorithm::GetKeyLength( 136 Status AesAlgorithm::GetKeyLength(
137 const blink::WebCryptoAlgorithm& key_length_algorithm, 137 const blink::WebCryptoAlgorithm& key_length_algorithm,
138 bool* has_length_bits, 138 bool* has_length_bits,
139 unsigned int* length_bits) const { 139 unsigned int* length_bits) const {
140 return GetAesKeyLength(key_length_algorithm, has_length_bits, length_bits); 140 return GetAesKeyLength(key_length_algorithm, has_length_bits, length_bits);
141 } 141 }
142 142
143 } // namespace webcrypto 143 } // namespace webcrypto
144 144
145 } // namespace content 145 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/child/webcrypto/nss/hmac_nss.cc » ('j') | content/test/data/webcrypto/ecdh.json » ('J')

Powered by Google App Engine
This is Rietveld 408576698