| 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_registry.h" | 5 #include "content/child/webcrypto/algorithm_registry.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "content/child/webcrypto/algorithm_implementation.h" | 8 #include "content/child/webcrypto/algorithm_implementation.h" |
| 9 #include "content/child/webcrypto/platform_crypto.h" | 9 #include "content/child/webcrypto/platform_crypto.h" |
| 10 #include "content/child/webcrypto/status.h" | 10 #include "content/child/webcrypto/status.h" |
| 11 | 11 |
| 12 namespace content { | 12 namespace content { |
| 13 | 13 |
| 14 namespace webcrypto { | 14 namespace webcrypto { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 // This class is used as a singleton. All methods must be threadsafe. |
| 18 class AlgorithmRegistry { | 19 class AlgorithmRegistry { |
| 19 public: | 20 public: |
| 20 AlgorithmRegistry() | 21 AlgorithmRegistry() |
| 21 : sha_(CreatePlatformShaImplementation()), | 22 : sha_(CreatePlatformShaImplementation()), |
| 22 aes_gcm_(CreatePlatformAesGcmImplementation()), | 23 aes_gcm_(CreatePlatformAesGcmImplementation()), |
| 23 aes_cbc_(CreatePlatformAesCbcImplementation()), | 24 aes_cbc_(CreatePlatformAesCbcImplementation()), |
| 24 aes_ctr_(CreatePlatformAesCtrImplementation()), | 25 aes_ctr_(CreatePlatformAesCtrImplementation()), |
| 25 aes_kw_(CreatePlatformAesKwImplementation()), | 26 aes_kw_(CreatePlatformAesKwImplementation()), |
| 26 hmac_(CreatePlatformHmacImplementation()), | 27 hmac_(CreatePlatformHmacImplementation()), |
| 27 rsa_ssa_(CreatePlatformRsaSsaImplementation()), | 28 rsa_ssa_(CreatePlatformRsaSsaImplementation()), |
| (...skipping 22 matching lines...) Expand all Loading... |
| 50 case blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5: | 51 case blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5: |
| 51 return rsa_ssa_.get(); | 52 return rsa_ssa_.get(); |
| 52 case blink::WebCryptoAlgorithmIdRsaOaep: | 53 case blink::WebCryptoAlgorithmIdRsaOaep: |
| 53 return rsa_oaep_.get(); | 54 return rsa_oaep_.get(); |
| 54 default: | 55 default: |
| 55 return NULL; | 56 return NULL; |
| 56 } | 57 } |
| 57 } | 58 } |
| 58 | 59 |
| 59 private: | 60 private: |
| 60 scoped_ptr<AlgorithmImplementation> sha_; | 61 const scoped_ptr<AlgorithmImplementation> sha_; |
| 61 scoped_ptr<AlgorithmImplementation> aes_gcm_; | 62 const scoped_ptr<AlgorithmImplementation> aes_gcm_; |
| 62 scoped_ptr<AlgorithmImplementation> aes_cbc_; | 63 const scoped_ptr<AlgorithmImplementation> aes_cbc_; |
| 63 scoped_ptr<AlgorithmImplementation> aes_ctr_; | 64 const scoped_ptr<AlgorithmImplementation> aes_ctr_; |
| 64 scoped_ptr<AlgorithmImplementation> aes_kw_; | 65 const scoped_ptr<AlgorithmImplementation> aes_kw_; |
| 65 scoped_ptr<AlgorithmImplementation> hmac_; | 66 const scoped_ptr<AlgorithmImplementation> hmac_; |
| 66 scoped_ptr<AlgorithmImplementation> rsa_ssa_; | 67 const scoped_ptr<AlgorithmImplementation> rsa_ssa_; |
| 67 scoped_ptr<AlgorithmImplementation> rsa_oaep_; | 68 const scoped_ptr<AlgorithmImplementation> rsa_oaep_; |
| 68 }; | 69 }; |
| 69 | 70 |
| 70 } // namespace | 71 } // namespace |
| 71 | 72 |
| 72 base::LazyInstance<AlgorithmRegistry>::Leaky g_algorithm_registry = | 73 base::LazyInstance<AlgorithmRegistry>::Leaky g_algorithm_registry = |
| 73 LAZY_INSTANCE_INITIALIZER; | 74 LAZY_INSTANCE_INITIALIZER; |
| 74 | 75 |
| 75 Status GetAlgorithmImplementation(blink::WebCryptoAlgorithmId id, | 76 Status GetAlgorithmImplementation(blink::WebCryptoAlgorithmId id, |
| 76 const AlgorithmImplementation** impl) { | 77 const AlgorithmImplementation** impl) { |
| 77 *impl = g_algorithm_registry.Get().GetAlgorithm(id); | 78 *impl = g_algorithm_registry.Get().GetAlgorithm(id); |
| 78 if (*impl) | 79 if (*impl) |
| 79 return Status::Success(); | 80 return Status::Success(); |
| 80 return Status::ErrorUnsupported(); | 81 return Status::ErrorUnsupported(); |
| 81 } | 82 } |
| 82 | 83 |
| 83 } // namespace webcrypto | 84 } // namespace webcrypto |
| 84 | 85 |
| 85 } // namespace content | 86 } // namespace content |
| OLD | NEW |