Index: content/child/webcrypto/algorithm_registry.cc |
diff --git a/content/child/webcrypto/algorithm_registry.cc b/content/child/webcrypto/algorithm_registry.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1c76329a3e0252d2bec4c39c14e3b07eb5079ddd |
--- /dev/null |
+++ b/content/child/webcrypto/algorithm_registry.cc |
@@ -0,0 +1,91 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "content/child/webcrypto/algorithm_registry.h" |
+ |
+#include <map> |
+ |
+#include "base/lazy_instance.h" |
+#include "base/stl_util.h" |
+#include "content/child/webcrypto/algorithm.h" |
+#include "content/child/webcrypto/status.h" |
+#if defined(USE_OPENSSL) |
+// TODO(eroman): |
+#else |
+#include "content/child/webcrypto/nss/algorithms_nss.h" |
+#include "crypto/nss_util.h" |
+#endif |
+ |
+namespace content { |
+ |
+namespace webcrypto { |
+ |
+namespace { |
+ |
+class CryptoAlgorithmRegistry { |
+ public: |
+ CryptoAlgorithmRegistry() { |
+#if defined(USE_OPENSSL) |
+// TODO(eroman): |
+#else |
+ crypto::EnsureNSSInit(); |
+ |
+ Register(blink::WebCryptoAlgorithmIdSha1, CreateShaImplementation()); |
+ Register(blink::WebCryptoAlgorithmIdSha256, CreateShaImplementation()); |
+ Register(blink::WebCryptoAlgorithmIdSha384, CreateShaImplementation()); |
+ Register(blink::WebCryptoAlgorithmIdSha512, CreateShaImplementation()); |
+ |
+ Register(blink::WebCryptoAlgorithmIdAesGcm, CreateAesGcmImplementation()); |
+ Register(blink::WebCryptoAlgorithmIdAesCbc, CreateAesCbcImplementation()); |
+ Register(blink::WebCryptoAlgorithmIdAesKw, CreateAesKwImplementation()); |
+ Register(blink::WebCryptoAlgorithmIdHmac, CreateHmacImplementation()); |
+ Register(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
+ CreateRsaSsaImplementation()); |
+ Register(blink::WebCryptoAlgorithmIdRsaOaep, CreateRsaOaepImplementation()); |
+#endif |
+ } |
+ |
+ ~CryptoAlgorithmRegistry() { |
+ STLDeleteContainerPairSecondPointers(algorithms_.begin(), |
+ algorithms_.end()); |
+ } |
+ |
+ const AlgorithmImplementation* GetAlgorithm( |
+ blink::WebCryptoAlgorithmId id) const { |
+ IdToAlgorithmMap::const_iterator it = algorithms_.find(id); |
+ if (it == algorithms_.end()) |
+ return NULL; |
+ return it->second; |
+ } |
+ |
+ private: |
+ void Register(blink::WebCryptoAlgorithmId id, |
+ AlgorithmImplementation* algorithm) { |
+ DCHECK(algorithms_.find(id) == algorithms_.end()) |
+ << "Registered algorithm twice"; |
+ algorithms_[id] = algorithm; |
+ } |
+ |
+ typedef std::map<blink::WebCryptoAlgorithmId, AlgorithmImplementation*> |
+ IdToAlgorithmMap; |
+ |
+ IdToAlgorithmMap algorithms_; |
+}; |
+ |
+} // namespace |
+ |
+base::LazyInstance<CryptoAlgorithmRegistry> g_algorithm_registry = |
+ LAZY_INSTANCE_INITIALIZER; |
+ |
+Status GetAlgorithmFromRegistry(blink::WebCryptoAlgorithmId id, |
+ const AlgorithmImplementation** impl) { |
+ *impl = g_algorithm_registry.Get().GetAlgorithm(id); |
+ if (!*impl) |
+ return Status::ErrorUnexpected(); |
+ return Status::Success(); |
+} |
+ |
+} // namespace webcrypto |
+ |
+} // namespace content |