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

Side by Side Diff: content/child/webcrypto/test/test_helpers.cc

Issue 512023002: Refactor the interface for generating keys. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Run git-cl format Created 6 years, 2 months 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
« no previous file with comments | « content/child/webcrypto/test/test_helpers.h ('k') | content/child/webcrypto/webcrypto_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/test/test_helpers.h" 5 #include "content/child/webcrypto/test/test_helpers.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
11 #include "base/json/json_writer.h" 11 #include "base/json/json_writer.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/path_service.h" 13 #include "base/path_service.h"
14 #include "base/stl_util.h" 14 #include "base/stl_util.h"
15 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
16 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
17 #include "base/values.h" 17 #include "base/values.h"
18 #include "content/child/webcrypto/algorithm_dispatch.h" 18 #include "content/child/webcrypto/algorithm_dispatch.h"
19 #include "content/child/webcrypto/crypto_data.h" 19 #include "content/child/webcrypto/crypto_data.h"
20 #include "content/child/webcrypto/generate_key_result.h"
20 #include "content/child/webcrypto/jwk.h" 21 #include "content/child/webcrypto/jwk.h"
21 #include "content/child/webcrypto/status.h" 22 #include "content/child/webcrypto/status.h"
22 #include "content/child/webcrypto/webcrypto_util.h" 23 #include "content/child/webcrypto/webcrypto_util.h"
23 #include "content/public/common/content_paths.h" 24 #include "content/public/common/content_paths.h"
24 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" 25 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h"
25 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" 26 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h"
26 #include "third_party/re2/re2/re2.h" 27 #include "third_party/re2/re2/re2.h"
27 28
28 #if !defined(USE_OPENSSL) 29 #if !defined(USE_OPENSSL)
29 #include <nss.h> 30 #include <nss.h>
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 EXPECT_EQ(true, key.extractable()); 574 EXPECT_EQ(true, key.extractable());
574 EXPECT_EQ(usages, key.usages()); 575 EXPECT_EQ(usages, key.usages());
575 576
576 // Export the key in raw format and compare to the original. 577 // Export the key in raw format and compare to the original.
577 std::vector<uint8_t> key_raw_out; 578 std::vector<uint8_t> key_raw_out;
578 ASSERT_EQ(Status::Success(), 579 ASSERT_EQ(Status::Success(),
579 ExportKey(blink::WebCryptoKeyFormatRaw, key, &key_raw_out)); 580 ExportKey(blink::WebCryptoKeyFormatRaw, key, &key_raw_out));
580 EXPECT_BYTES_EQ_HEX(key_hex, key_raw_out); 581 EXPECT_BYTES_EQ_HEX(key_hex, key_raw_out);
581 } 582 }
582 583
584 Status GenerateSecretKey(const blink::WebCryptoAlgorithm& algorithm,
585 bool extractable,
586 blink::WebCryptoKeyUsageMask usage_mask,
587 blink::WebCryptoKey* key) {
588 GenerateKeyResult result;
589 Status status = GenerateKey(algorithm, extractable, usage_mask, &result);
590 if (status.IsError())
591 return status;
592
593 if (result.type() != GenerateKeyResult::TYPE_SECRET_KEY)
594 return Status::ErrorUnexpected();
595
596 *key = result.secret_key();
597
598 return Status::Success();
599 }
600
601 Status GenerateKeyPair(const blink::WebCryptoAlgorithm& algorithm,
602 bool extractable,
603 blink::WebCryptoKeyUsageMask usage_mask,
604 blink::WebCryptoKey* public_key,
605 blink::WebCryptoKey* private_key) {
606 GenerateKeyResult result;
607 Status status = GenerateKey(algorithm, extractable, usage_mask, &result);
608 if (status.IsError())
609 return status;
610
611 if (result.type() != GenerateKeyResult::TYPE_PUBLIC_PRIVATE_KEY_PAIR)
612 return Status::ErrorUnexpected();
613
614 *public_key = result.public_key();
615 *private_key = result.private_key();
616
617 return Status::Success();
618 }
619
583 } // namespace webcrypto 620 } // namespace webcrypto
584 621
585 } // namesapce content 622 } // namesapce content
OLDNEW
« no previous file with comments | « content/child/webcrypto/test/test_helpers.h ('k') | content/child/webcrypto/webcrypto_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698