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/algorithm_dispatch.h" | 5 #include "content/child/webcrypto/algorithm_dispatch.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "content/child/webcrypto/algorithm_implementation.h" | 8 #include "content/child/webcrypto/algorithm_implementation.h" |
9 #include "content/child/webcrypto/algorithm_registry.h" | 9 #include "content/child/webcrypto/algorithm_registry.h" |
10 #include "content/child/webcrypto/crypto_data.h" | 10 #include "content/child/webcrypto/crypto_data.h" |
| 11 #include "content/child/webcrypto/generate_key_result.h" |
11 #include "content/child/webcrypto/platform_crypto.h" | 12 #include "content/child/webcrypto/platform_crypto.h" |
12 #include "content/child/webcrypto/status.h" | 13 #include "content/child/webcrypto/status.h" |
13 #include "content/child/webcrypto/webcrypto_util.h" | 14 #include "content/child/webcrypto/webcrypto_util.h" |
14 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" | 15 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" |
15 | 16 |
16 namespace content { | 17 namespace content { |
17 | 18 |
18 namespace webcrypto { | 19 namespace webcrypto { |
19 | 20 |
20 namespace { | 21 namespace { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 | 105 |
105 Status GenerateKey(const blink::WebCryptoAlgorithm& algorithm, | 106 Status GenerateKey(const blink::WebCryptoAlgorithm& algorithm, |
106 bool extractable, | 107 bool extractable, |
107 blink::WebCryptoKeyUsageMask usages, | 108 blink::WebCryptoKeyUsageMask usages, |
108 GenerateKeyResult* result) { | 109 GenerateKeyResult* result) { |
109 const AlgorithmImplementation* impl = NULL; | 110 const AlgorithmImplementation* impl = NULL; |
110 Status status = GetAlgorithmImplementation(algorithm.id(), &impl); | 111 Status status = GetAlgorithmImplementation(algorithm.id(), &impl); |
111 if (status.IsError()) | 112 if (status.IsError()) |
112 return status; | 113 return status; |
113 | 114 |
114 return impl->GenerateKey(algorithm, extractable, usages, result); | 115 status = impl->GenerateKey(algorithm, extractable, usages, result); |
| 116 if (status.IsError()) |
| 117 return status; |
| 118 |
| 119 const blink::WebCryptoKey* key = NULL; |
| 120 if (result->type() == GenerateKeyResult::TYPE_SECRET_KEY) |
| 121 key = &result->secret_key(); |
| 122 if (result->type() == GenerateKeyResult::TYPE_PUBLIC_PRIVATE_KEY_PAIR) |
| 123 key = &result->private_key(); |
| 124 if (key == NULL) |
| 125 return Status::ErrorUnexpected(); |
| 126 |
| 127 // This should only fail if an algorithm is implemented incorrectly and |
| 128 // does not do its own check of the usages. |
| 129 if (key->usages() == 0) { |
| 130 DCHECK(false) << "Key usages for generateKey() must not be empty"; |
| 131 return Status::ErrorCreateKeyEmptyUsages(); |
| 132 } |
| 133 return status; |
115 } | 134 } |
116 | 135 |
117 Status ImportKey(blink::WebCryptoKeyFormat format, | 136 Status ImportKey(blink::WebCryptoKeyFormat format, |
118 const CryptoData& key_data, | 137 const CryptoData& key_data, |
119 const blink::WebCryptoAlgorithm& algorithm, | 138 const blink::WebCryptoAlgorithm& algorithm, |
120 bool extractable, | 139 bool extractable, |
121 blink::WebCryptoKeyUsageMask usages, | 140 blink::WebCryptoKeyUsageMask usages, |
122 blink::WebCryptoKey* key) { | 141 blink::WebCryptoKey* key) { |
123 const AlgorithmImplementation* impl = NULL; | 142 const AlgorithmImplementation* impl = NULL; |
124 Status status = GetAlgorithmImplementation(algorithm.id(), &impl); | 143 Status status = GetAlgorithmImplementation(algorithm.id(), &impl); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 return false; | 307 return false; |
289 | 308 |
290 status = impl->DeserializeKeyForClone(algorithm, type, extractable, usages, | 309 status = impl->DeserializeKeyForClone(algorithm, type, extractable, usages, |
291 key_data, key); | 310 key_data, key); |
292 return status.IsSuccess(); | 311 return status.IsSuccess(); |
293 } | 312 } |
294 | 313 |
295 } // namespace webcrypto | 314 } // namespace webcrypto |
296 | 315 |
297 } // namespace content | 316 } // namespace content |
OLD | NEW |