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

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: 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 24 matching lines...) Expand all
35 blink::WebCryptoKeyUsageDecrypt | 35 blink::WebCryptoKeyUsageDecrypt |
36 blink::WebCryptoKeyUsageWrapKey | 36 blink::WebCryptoKeyUsageWrapKey |
37 blink::WebCryptoKeyUsageUnwrapKey), 37 blink::WebCryptoKeyUsageUnwrapKey),
38 jwk_suffix_(jwk_suffix) { 38 jwk_suffix_(jwk_suffix) {
39 } 39 }
40 40
41 Status AesAlgorithm::GenerateKey(const blink::WebCryptoAlgorithm& algorithm, 41 Status AesAlgorithm::GenerateKey(const blink::WebCryptoAlgorithm& algorithm,
42 bool extractable, 42 bool extractable,
43 blink::WebCryptoKeyUsageMask usages, 43 blink::WebCryptoKeyUsageMask usages,
44 GenerateKeyResult* result) const { 44 GenerateKeyResult* result) const {
45 Status status = CheckKeyCreationUsages(all_key_usages_, usages); 45 Status status = CheckKeyCreationUsages(all_key_usages_, usages, false);
eroman 2014/12/09 21:04:46 This may as well just pass true, and then remove t
Habib Virji 2014/12/15 18:48:55 Done.
46 if (status.IsError()) 46 if (status.IsError())
47 return status; 47 return status;
48 48
49 unsigned int keylen_bits; 49 unsigned int keylen_bits;
50 status = GetAesKeyGenLengthInBits(algorithm.aesKeyGenParams(), &keylen_bits); 50 status = GetAesKeyGenLengthInBits(algorithm.aesKeyGenParams(), &keylen_bits);
51 if (status.IsError()) 51 if (status.IsError())
52 return status; 52 return status;
53 53
54 return GenerateSecretKeyNss( 54 return GenerateSecretKeyNss(
55 blink::WebCryptoKeyAlgorithm::createAes(algorithm.id(), keylen_bits), 55 blink::WebCryptoKeyAlgorithm::createAes(algorithm.id(), keylen_bits),
56 extractable, usages, keylen_bits / 8, CKM_AES_KEY_GEN, result); 56 extractable, usages, keylen_bits / 8, CKM_AES_KEY_GEN, result);
57 } 57 }
58 58
59 Status AesAlgorithm::VerifyKeyUsagesBeforeImportKey( 59 Status AesAlgorithm::VerifyKeyUsagesBeforeImportKey(
60 blink::WebCryptoKeyFormat format, 60 blink::WebCryptoKeyFormat format,
61 blink::WebCryptoKeyUsageMask usages) const { 61 blink::WebCryptoKeyUsageMask usages) const {
62 switch (format) { 62 switch (format) {
63 case blink::WebCryptoKeyFormatRaw: 63 case blink::WebCryptoKeyFormatRaw:
64 case blink::WebCryptoKeyFormatJwk: 64 case blink::WebCryptoKeyFormatJwk:
65 return CheckKeyCreationUsages(all_key_usages_, usages); 65 return CheckKeyCreationUsages(all_key_usages_, usages, true);
66 default: 66 default:
67 return Status::ErrorUnsupportedImportKeyFormat(); 67 return Status::ErrorUnsupportedImportKeyFormat();
68 } 68 }
69 } 69 }
70 Status AesAlgorithm::ImportKeyRaw(const CryptoData& key_data, 70 Status AesAlgorithm::ImportKeyRaw(const CryptoData& key_data,
71 const blink::WebCryptoAlgorithm& algorithm, 71 const blink::WebCryptoAlgorithm& algorithm,
72 bool extractable, 72 bool extractable,
73 blink::WebCryptoKeyUsageMask usages, 73 blink::WebCryptoKeyUsageMask usages,
74 blink::WebCryptoKey* key) const { 74 blink::WebCryptoKey* key) const {
75 const unsigned int keylen_bytes = key_data.byte_length(); 75 const unsigned int keylen_bytes = key_data.byte_length();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 blink::WebCryptoKeyUsageMask usages, 133 blink::WebCryptoKeyUsageMask usages,
134 const CryptoData& key_data, 134 const CryptoData& key_data,
135 blink::WebCryptoKey* key) const { 135 blink::WebCryptoKey* key) const {
136 return ImportKeyRaw(key_data, CreateAlgorithm(algorithm.id()), extractable, 136 return ImportKeyRaw(key_data, CreateAlgorithm(algorithm.id()), extractable,
137 usages, key); 137 usages, key);
138 } 138 }
139 139
140 } // namespace webcrypto 140 } // namespace webcrypto
141 141
142 } // namespace content 142 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/child/webcrypto/nss/hmac_nss.cc » ('j') | content/child/webcrypto/nss/hmac_nss.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698