| 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" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 const CryptoData& data, | 95 const CryptoData& data, |
| 96 std::vector<uint8_t>* buffer) { | 96 std::vector<uint8_t>* buffer) { |
| 97 const AlgorithmImplementation* impl = NULL; | 97 const AlgorithmImplementation* impl = NULL; |
| 98 Status status = GetAlgorithmImplementation(algorithm.id(), &impl); | 98 Status status = GetAlgorithmImplementation(algorithm.id(), &impl); |
| 99 if (status.IsError()) | 99 if (status.IsError()) |
| 100 return status; | 100 return status; |
| 101 | 101 |
| 102 return impl->Digest(algorithm, data, buffer); | 102 return impl->Digest(algorithm, data, buffer); |
| 103 } | 103 } |
| 104 | 104 |
| 105 Status GenerateSecretKey(const blink::WebCryptoAlgorithm& algorithm, | 105 Status GenerateKey(const blink::WebCryptoAlgorithm& algorithm, |
| 106 bool extractable, | 106 bool extractable, |
| 107 blink::WebCryptoKeyUsageMask usage_mask, | 107 blink::WebCryptoKeyUsageMask usage_mask, |
| 108 blink::WebCryptoKey* key) { | 108 blink::WebCryptoKey* public_key, |
| 109 blink::WebCryptoKey* private_key) { |
| 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 status = impl->VerifyKeyUsagesBeforeGenerateKey(usage_mask); | 115 return impl->GenerateKey( |
| 115 if (status.IsError()) | 116 algorithm, extractable, usage_mask, public_key, private_key); |
| 116 return status; | |
| 117 | |
| 118 return impl->GenerateSecretKey(algorithm, extractable, usage_mask, key); | |
| 119 } | |
| 120 | |
| 121 Status GenerateKeyPair(const blink::WebCryptoAlgorithm& algorithm, | |
| 122 bool extractable, | |
| 123 blink::WebCryptoKeyUsageMask combined_usage_mask, | |
| 124 blink::WebCryptoKey* public_key, | |
| 125 blink::WebCryptoKey* private_key) { | |
| 126 const AlgorithmImplementation* impl = NULL; | |
| 127 Status status = GetAlgorithmImplementation(algorithm.id(), &impl); | |
| 128 if (status.IsError()) | |
| 129 return status; | |
| 130 | |
| 131 blink::WebCryptoKeyUsageMask public_usage_mask; | |
| 132 blink::WebCryptoKeyUsageMask private_usage_mask; | |
| 133 status = impl->VerifyKeyUsagesBeforeGenerateKeyPair( | |
| 134 combined_usage_mask, &public_usage_mask, &private_usage_mask); | |
| 135 if (status.IsError()) | |
| 136 return status; | |
| 137 | |
| 138 return impl->GenerateKeyPair(algorithm, | |
| 139 extractable, | |
| 140 public_usage_mask, | |
| 141 private_usage_mask, | |
| 142 public_key, | |
| 143 private_key); | |
| 144 } | 117 } |
| 145 | 118 |
| 146 // Note that this function may be called from the target Blink thread. | 119 // Note that this function may be called from the target Blink thread. |
| 147 Status ImportKey(blink::WebCryptoKeyFormat format, | 120 Status ImportKey(blink::WebCryptoKeyFormat format, |
| 148 const CryptoData& key_data, | 121 const CryptoData& key_data, |
| 149 const blink::WebCryptoAlgorithm& algorithm, | 122 const blink::WebCryptoAlgorithm& algorithm, |
| 150 bool extractable, | 123 bool extractable, |
| 151 blink::WebCryptoKeyUsageMask usage_mask, | 124 blink::WebCryptoKeyUsageMask usage_mask, |
| 152 blink::WebCryptoKey* key) { | 125 blink::WebCryptoKey* key) { |
| 153 const AlgorithmImplementation* impl = NULL; | 126 const AlgorithmImplementation* impl = NULL; |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 | 249 |
| 277 scoped_ptr<blink::WebCryptoDigestor> CreateDigestor( | 250 scoped_ptr<blink::WebCryptoDigestor> CreateDigestor( |
| 278 blink::WebCryptoAlgorithmId algorithm) { | 251 blink::WebCryptoAlgorithmId algorithm) { |
| 279 PlatformInit(); | 252 PlatformInit(); |
| 280 return CreatePlatformDigestor(algorithm); | 253 return CreatePlatformDigestor(algorithm); |
| 281 } | 254 } |
| 282 | 255 |
| 283 } // namespace webcrypto | 256 } // namespace webcrypto |
| 284 | 257 |
| 285 } // namespace content | 258 } // namespace content |
| OLD | NEW |