OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/child/webcrypto/algorithm_registry.h" |
| 6 |
| 7 #include "base/lazy_instance.h" |
| 8 #include "content/child/webcrypto/algorithm_implementation.h" |
| 9 #include "content/child/webcrypto/platform_crypto.h" |
| 10 #include "content/child/webcrypto/status.h" |
| 11 |
| 12 namespace content { |
| 13 |
| 14 namespace webcrypto { |
| 15 |
| 16 namespace { |
| 17 |
| 18 class AlgorithmRegistry { |
| 19 public: |
| 20 AlgorithmRegistry() |
| 21 : sha_(CreatePlatformShaImplementation()), |
| 22 aes_gcm_(CreatePlatformAesGcmImplementation()), |
| 23 aes_cbc_(CreatePlatformAesCbcImplementation()), |
| 24 aes_kw_(CreatePlatformAesKwImplementation()), |
| 25 hmac_(CreatePlatformHmacImplementation()), |
| 26 rsa_ssa_(CreatePlatformRsaSsaImplementation()), |
| 27 rsa_oaep_(CreatePlatformRsaOaepImplementation()) { |
| 28 PlatformInit(); |
| 29 } |
| 30 |
| 31 const AlgorithmImplementation* GetAlgorithm( |
| 32 blink::WebCryptoAlgorithmId id) const { |
| 33 switch (id) { |
| 34 case blink::WebCryptoAlgorithmIdSha1: |
| 35 case blink::WebCryptoAlgorithmIdSha256: |
| 36 case blink::WebCryptoAlgorithmIdSha384: |
| 37 case blink::WebCryptoAlgorithmIdSha512: |
| 38 return sha_.get(); |
| 39 case blink::WebCryptoAlgorithmIdAesGcm: |
| 40 return aes_gcm_.get(); |
| 41 case blink::WebCryptoAlgorithmIdAesCbc: |
| 42 return aes_cbc_.get(); |
| 43 case blink::WebCryptoAlgorithmIdAesKw: |
| 44 return aes_kw_.get(); |
| 45 case blink::WebCryptoAlgorithmIdHmac: |
| 46 return hmac_.get(); |
| 47 case blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5: |
| 48 return rsa_ssa_.get(); |
| 49 case blink::WebCryptoAlgorithmIdRsaOaep: |
| 50 return rsa_oaep_.get(); |
| 51 default: |
| 52 return NULL; |
| 53 } |
| 54 } |
| 55 |
| 56 private: |
| 57 scoped_ptr<AlgorithmImplementation> sha_; |
| 58 scoped_ptr<AlgorithmImplementation> aes_gcm_; |
| 59 scoped_ptr<AlgorithmImplementation> aes_cbc_; |
| 60 scoped_ptr<AlgorithmImplementation> aes_kw_; |
| 61 scoped_ptr<AlgorithmImplementation> hmac_; |
| 62 scoped_ptr<AlgorithmImplementation> rsa_ssa_; |
| 63 scoped_ptr<AlgorithmImplementation> rsa_oaep_; |
| 64 }; |
| 65 |
| 66 } // namespace |
| 67 |
| 68 base::LazyInstance<AlgorithmRegistry>::Leaky g_algorithm_registry = |
| 69 LAZY_INSTANCE_INITIALIZER; |
| 70 |
| 71 Status GetAlgorithmImplementation(blink::WebCryptoAlgorithmId id, |
| 72 const AlgorithmImplementation** impl) { |
| 73 *impl = g_algorithm_registry.Get().GetAlgorithm(id); |
| 74 if (*impl) |
| 75 return Status::Success(); |
| 76 return Status::ErrorUnsupported(); |
| 77 } |
| 78 |
| 79 } // namespace webcrypto |
| 80 |
| 81 } // namespace content |
OLD | NEW |