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/test/test_helpers.h" | 5 #include "content/child/webcrypto/test/test_helpers.h" |
6 | 6 |
7 #include <set> | |
8 | |
7 #include "base/file_util.h" | 9 #include "base/file_util.h" |
8 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
9 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
10 #include "base/logging.h" | 12 #include "base/logging.h" |
11 #include "base/path_service.h" | 13 #include "base/path_service.h" |
12 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
13 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
15 #include "base/values.h" | 17 #include "base/values.h" |
16 #include "content/child/webcrypto/algorithm_dispatch.h" | 18 #include "content/child/webcrypto/algorithm_dispatch.h" |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 }; | 234 }; |
233 | 235 |
234 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kDigestNameToId); ++i) { | 236 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kDigestNameToId); ++i) { |
235 if (kDigestNameToId[i].name == algorithm_name) | 237 if (kDigestNameToId[i].name == algorithm_name) |
236 return CreateAlgorithm(kDigestNameToId[i].id); | 238 return CreateAlgorithm(kDigestNameToId[i].id); |
237 } | 239 } |
238 | 240 |
239 return blink::WebCryptoAlgorithm::createNull(); | 241 return blink::WebCryptoAlgorithm::createNull(); |
240 } | 242 } |
241 | 243 |
242 // Returns true if any of the vectors in the input list have identical content. | |
243 // Dumb O(n^2) implementation but should be fast enough for the input sizes that | |
244 // are used. | |
245 bool CopiesExist(const std::vector<std::vector<uint8_t> >& bufs) { | 244 bool CopiesExist(const std::vector<std::vector<uint8_t> >& bufs) { |
245 std::set<std::vector<uint8_t> > values; | |
246 for (size_t i = 0; i < bufs.size(); ++i) { | 246 for (size_t i = 0; i < bufs.size(); ++i) { |
247 for (size_t j = i + 1; j < bufs.size(); ++j) { | 247 if (!values.insert(bufs[i]).second) { |
248 if (CryptoData(bufs[i]) == CryptoData(bufs[j])) | 248 return true; |
249 return true; | |
250 } | 249 } |
Ryan Sleevi
2014/08/27 17:15:58
This seems to be memory intensive.
Why not just s
eroman
2014/08/27 18:47:06
Done. I also modified it to sort a vector of indic
| |
251 } | 250 } |
252 return false; | 251 return false; |
253 } | 252 } |
254 | 253 |
255 blink::WebCryptoAlgorithm CreateAesKeyGenAlgorithm( | 254 blink::WebCryptoAlgorithm CreateAesKeyGenAlgorithm( |
256 blink::WebCryptoAlgorithmId aes_alg_id, | 255 blink::WebCryptoAlgorithmId aes_alg_id, |
257 unsigned short length) { | 256 unsigned short length) { |
258 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( | 257 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( |
259 aes_alg_id, new blink::WebCryptoAesKeyGenParams(length)); | 258 aes_alg_id, new blink::WebCryptoAesKeyGenParams(length)); |
260 } | 259 } |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
557 // Export the key in raw format and compare to the original. | 556 // Export the key in raw format and compare to the original. |
558 std::vector<uint8_t> key_raw_out; | 557 std::vector<uint8_t> key_raw_out; |
559 ASSERT_EQ(Status::Success(), | 558 ASSERT_EQ(Status::Success(), |
560 ExportKey(blink::WebCryptoKeyFormatRaw, key, &key_raw_out)); | 559 ExportKey(blink::WebCryptoKeyFormatRaw, key, &key_raw_out)); |
561 EXPECT_BYTES_EQ_HEX(key_hex, key_raw_out); | 560 EXPECT_BYTES_EQ_HEX(key_hex, key_raw_out); |
562 } | 561 } |
563 | 562 |
564 } // namespace webcrypto | 563 } // namespace webcrypto |
565 | 564 |
566 } // namesapce content | 565 } // namesapce content |
OLD | NEW |