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

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

Issue 675453003: Add tests for RSA private key import using JWK when p and q are swapped. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 1 month 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/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"
(...skipping 21 matching lines...) Expand all
32 32
33 #include "crypto/nss_util.h" 33 #include "crypto/nss_util.h"
34 #include "crypto/scoped_nss_types.h" 34 #include "crypto/scoped_nss_types.h"
35 #endif 35 #endif
36 36
37 namespace content { 37 namespace content {
38 38
39 namespace webcrypto { 39 namespace webcrypto {
40 40
41 void PrintTo(const Status& status, ::std::ostream* os) { 41 void PrintTo(const Status& status, ::std::ostream* os) {
42 if (status.IsSuccess()) 42 *os << StatusToString(status);
43 *os << "Success";
44 else
45 *os << "Error type: " << status.error_type()
46 << " Error details: " << status.error_details();
47 } 43 }
48 44
49 bool operator==(const Status& a, const Status& b) { 45 bool operator==(const Status& a, const Status& b) {
50 if (a.IsSuccess() != b.IsSuccess()) 46 if (a.IsSuccess() != b.IsSuccess())
51 return false; 47 return false;
52 if (a.IsSuccess()) 48 if (a.IsSuccess())
53 return true; 49 return true;
54 return a.error_type() == b.error_type() && 50 return a.error_type() == b.error_type() &&
55 a.error_details() == b.error_details(); 51 a.error_details() == b.error_details();
56 } 52 }
57 53
58 bool operator!=(const Status& a, const Status& b) { 54 bool operator!=(const Status& a, const Status& b) {
59 return !(a == b); 55 return !(a == b);
60 } 56 }
61 57
62 void PrintTo(const CryptoData& data, ::std::ostream* os) { 58 void PrintTo(const CryptoData& data, ::std::ostream* os) {
63 *os << "[" << base::HexEncode(data.bytes(), data.byte_length()) << "]"; 59 *os << "[" << base::HexEncode(data.bytes(), data.byte_length()) << "]";
64 } 60 }
65 61
66 bool operator==(const CryptoData& a, const CryptoData& b) { 62 bool operator==(const CryptoData& a, const CryptoData& b) {
67 return a.byte_length() == b.byte_length() && 63 return a.byte_length() == b.byte_length() &&
68 memcmp(a.bytes(), b.bytes(), a.byte_length()) == 0; 64 memcmp(a.bytes(), b.bytes(), a.byte_length()) == 0;
69 } 65 }
70 66
71 bool operator!=(const CryptoData& a, const CryptoData& b) { 67 bool operator!=(const CryptoData& a, const CryptoData& b) {
72 return !(a == b); 68 return !(a == b);
73 } 69 }
74 70
71 static std::string ErrorTypeToString(blink::WebCryptoErrorType type) {
72 switch (type) {
73 case blink::WebCryptoErrorTypeNotSupported:
74 return "NotSupported";
75 case blink::WebCryptoErrorTypeType:
76 return "TypeError";
77 case blink::WebCryptoErrorTypeData:
78 return "DataError";
79 case blink::WebCryptoErrorTypeSyntax:
80 return "SyntaxError";
81 case blink::WebCryptoErrorTypeOperation:
82 return "OperationError";
83 case blink::WebCryptoErrorTypeUnknown:
84 return "UnknownError";
85 case blink::WebCryptoErrorTypeInvalidState:
86 return "InvalidState";
87 case blink::WebCryptoErrorTypeInvalidAccess:
88 return "InvalidAccess";
89 }
90
91 return "?";
92 }
93
94 std::string StatusToString(const Status& status) {
95 if (status.IsSuccess())
96 return "Success";
97
98 std::string result = ErrorTypeToString(status.error_type());
99 if (!status.error_details().empty())
100 result += ": " + status.error_details();
101 return result;
102 }
103
75 bool SupportsAesGcm() { 104 bool SupportsAesGcm() {
76 std::vector<uint8_t> key_raw(16, 0); 105 std::vector<uint8_t> key_raw(16, 0);
77 106
78 blink::WebCryptoKey key; 107 blink::WebCryptoKey key;
79 Status status = ImportKey(blink::WebCryptoKeyFormatRaw, 108 Status status = ImportKey(blink::WebCryptoKeyFormatRaw,
80 CryptoData(key_raw), 109 CryptoData(key_raw),
81 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesGcm), 110 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesGcm),
82 true, 111 true,
83 blink::WebCryptoKeyUsageEncrypt, 112 blink::WebCryptoKeyUsageEncrypt,
84 &key); 113 &key);
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 660
632 *public_key = result.public_key(); 661 *public_key = result.public_key();
633 *private_key = result.private_key(); 662 *private_key = result.private_key();
634 663
635 return Status::Success(); 664 return Status::Success();
636 } 665 }
637 666
638 } // namespace webcrypto 667 } // namespace webcrypto
639 668
640 } // namesapce content 669 } // namesapce content
OLDNEW
« no previous file with comments | « content/child/webcrypto/test/test_helpers.h ('k') | content/test/data/webcrypto/bad_rsa_keys.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698