Chromium Code Reviews| 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 | |
| 132 // Even though this is unexpected, I chose not to use | |
|
eroman
2014/12/05 23:49:48
Remove this comment. "I" will become unclear over
nharper
2014/12/05 23:58:08
Done.
| |
| 133 // Status::ErrorUnexpected() so that we can present a better error to the | |
| 134 // user. | |
| 135 // TODO(nharper): This should be instrumented with http://crbug.com/428806 | |
| 136 return Status::ErrorCreateKeyEmptyUsages(); | |
| 137 } | |
| 138 return status; | |
| 115 } | 139 } |
| 116 | 140 |
| 117 Status ImportKey(blink::WebCryptoKeyFormat format, | 141 Status ImportKey(blink::WebCryptoKeyFormat format, |
| 118 const CryptoData& key_data, | 142 const CryptoData& key_data, |
| 119 const blink::WebCryptoAlgorithm& algorithm, | 143 const blink::WebCryptoAlgorithm& algorithm, |
| 120 bool extractable, | 144 bool extractable, |
| 121 blink::WebCryptoKeyUsageMask usages, | 145 blink::WebCryptoKeyUsageMask usages, |
| 122 blink::WebCryptoKey* key) { | 146 blink::WebCryptoKey* key) { |
| 123 const AlgorithmImplementation* impl = NULL; | 147 const AlgorithmImplementation* impl = NULL; |
| 124 Status status = GetAlgorithmImplementation(algorithm.id(), &impl); | 148 Status status = GetAlgorithmImplementation(algorithm.id(), &impl); |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 288 return false; | 312 return false; |
| 289 | 313 |
| 290 status = impl->DeserializeKeyForClone(algorithm, type, extractable, usages, | 314 status = impl->DeserializeKeyForClone(algorithm, type, extractable, usages, |
| 291 key_data, key); | 315 key_data, key); |
| 292 return status.IsSuccess(); | 316 return status.IsSuccess(); |
| 293 } | 317 } |
| 294 | 318 |
| 295 } // namespace webcrypto | 319 } // namespace webcrypto |
| 296 | 320 |
| 297 } // namespace content | 321 } // namespace content |
| OLD | NEW |