| 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 if (!SupportsAesGcm()) { | 106 if (!SupportsAesGcm()) { |
| 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(CreateAesGcmKeyGenAlgorithm(kKeyLen[i]), true, | 116 GenerateSecretKey( |
| 117 blink::WebCryptoKeyUsageDecrypt, &key)); | 117 CreateAesGcmKeyGenAlgorithm(kKeyLen[i]), true, 0, &key)); |
| 118 } | 118 } |
| 119 } | 119 } |
| 120 | 120 |
| 121 TEST(WebCryptoAesGcmTest, GenerateKeyEmptyUsage) { | |
| 122 if (!SupportsAesGcm()) { | |
| 123 LOG(WARNING) << "AES GCM not supported, skipping tests"; | |
| 124 return; | |
| 125 } | |
| 126 | |
| 127 blink::WebCryptoKey key; | |
| 128 EXPECT_EQ(Status::ErrorCreateKeyEmptyUsages(), | |
| 129 GenerateSecretKey(CreateAesGcmKeyGenAlgorithm(256), true, 0, &key)); | |
| 130 } | |
| 131 | |
| 132 TEST(WebCryptoAesGcmTest, ImportExportJwk) { | 121 TEST(WebCryptoAesGcmTest, ImportExportJwk) { |
| 133 // Some Linux test runners may not have a new enough version of NSS. | 122 // Some Linux test runners may not have a new enough version of NSS. |
| 134 if (!SupportsAesGcm()) { | 123 if (!SupportsAesGcm()) { |
| 135 LOG(WARNING) << "AES GCM not supported, skipping tests"; | 124 LOG(WARNING) << "AES GCM not supported, skipping tests"; |
| 136 return; | 125 return; |
| 137 } | 126 } |
| 138 | 127 |
| 139 const blink::WebCryptoAlgorithm algorithm = | 128 const blink::WebCryptoAlgorithm algorithm = |
| 140 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesGcm); | 129 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesGcm); |
| 141 | 130 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 &plain_text)); | 261 &plain_text)); |
| 273 } | 262 } |
| 274 } | 263 } |
| 275 } | 264 } |
| 276 | 265 |
| 277 } // namespace | 266 } // namespace |
| 278 | 267 |
| 279 } // namespace webcrypto | 268 } // namespace webcrypto |
| 280 | 269 |
| 281 } // namespace content | 270 } // namespace content |
| OLD | NEW |