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 "base/stl_util.h" | 5 #include "base/stl_util.h" |
6 #include "content/child/webcrypto/algorithm_dispatch.h" | 6 #include "content/child/webcrypto/algorithm_dispatch.h" |
7 #include "content/child/webcrypto/crypto_data.h" | 7 #include "content/child/webcrypto/crypto_data.h" |
8 #include "content/child/webcrypto/status.h" | 8 #include "content/child/webcrypto/status.h" |
9 #include "content/child/webcrypto/test/test_helpers.h" | 9 #include "content/child/webcrypto/test/test_helpers.h" |
10 #include "content/child/webcrypto/webcrypto_util.h" | 10 #include "content/child/webcrypto/webcrypto_util.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 LOG(WARNING) << "AES GCM not supported, skipping tests"; | 107 LOG(WARNING) << "AES GCM not supported, skipping tests"; |
108 return; | 108 return; |
109 } | 109 } |
110 | 110 |
111 const unsigned short kKeyLen[] = {0, 127, 257}; | 111 const unsigned short kKeyLen[] = {0, 127, 257}; |
112 blink::WebCryptoKey key; | 112 blink::WebCryptoKey key; |
113 for (size_t i = 0; i < arraysize(kKeyLen); ++i) { | 113 for (size_t i = 0; i < arraysize(kKeyLen); ++i) { |
114 SCOPED_TRACE(i); | 114 SCOPED_TRACE(i); |
115 EXPECT_EQ(Status::ErrorGenerateKeyLength(), | 115 EXPECT_EQ(Status::ErrorGenerateKeyLength(), |
116 GenerateSecretKey( | 116 GenerateSecretKey( |
117 CreateAesGcmKeyGenAlgorithm(kKeyLen[i]), true, 0, &key)); | 117 CreateAesGcmKeyGenAlgorithm(kKeyLen[i]), true, |
| 118 blink::WebCryptoKeyUsageDecrypt, &key)); |
118 } | 119 } |
119 } | 120 } |
120 | 121 |
| 122 TEST(WebCryptoAesGcmTest, GenerateKeyEmptyUsage) { |
| 123 if (!SupportsAesGcm()) { |
| 124 LOG(WARNING) << "AES GCM not supported, skipping tests"; |
| 125 return; |
| 126 } |
| 127 |
| 128 blink::WebCryptoKey key; |
| 129 EXPECT_EQ(Status::ErrorCreateKeyBadUsages(), |
| 130 GenerateSecretKey(CreateAesGcmKeyGenAlgorithm(256), true, 0, &key)); |
| 131 } |
| 132 |
121 TEST(WebCryptoAesGcmTest, ImportExportJwk) { | 133 TEST(WebCryptoAesGcmTest, ImportExportJwk) { |
122 // Some Linux test runners may not have a new enough version of NSS. | 134 // Some Linux test runners may not have a new enough version of NSS. |
123 if (!SupportsAesGcm()) { | 135 if (!SupportsAesGcm()) { |
124 LOG(WARNING) << "AES GCM not supported, skipping tests"; | 136 LOG(WARNING) << "AES GCM not supported, skipping tests"; |
125 return; | 137 return; |
126 } | 138 } |
127 | 139 |
128 const blink::WebCryptoAlgorithm algorithm = | 140 const blink::WebCryptoAlgorithm algorithm = |
129 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesGcm); | 141 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesGcm); |
130 | 142 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 &plain_text)); | 273 &plain_text)); |
262 } | 274 } |
263 } | 275 } |
264 } | 276 } |
265 | 277 |
266 } // namespace | 278 } // namespace |
267 | 279 |
268 } // namespace webcrypto | 280 } // namespace webcrypto |
269 | 281 |
270 } // namespace content | 282 } // namespace content |
OLD | NEW |