webcrypto_impl.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. #ifndef COMPONENTS_WEBCRYPTO_WEBCRYPTO_IMPL_H_
  5. #define COMPONENTS_WEBCRYPTO_WEBCRYPTO_IMPL_H_
  6. #include "base/compiler_specific.h"
  7. #include "base/task/single_thread_task_runner.h"
  8. #include "third_party/blink/public/platform/web_crypto.h"
  9. #include "third_party/blink/public/platform/web_crypto_algorithm.h"
  10. #include "third_party/blink/public/platform/web_vector.h"
  11. namespace webcrypto {
  12. // Wrapper around the Blink WebCrypto asynchronous interface, which forwards to
  13. // the synchronous OpenSSL implementation.
  14. //
  15. // WebCryptoImpl is threadsafe.
  16. //
  17. // EnsureInit() must be called prior to using methods on WebCryptoImpl().
  18. class WebCryptoImpl : public blink::WebCrypto {
  19. public:
  20. WebCryptoImpl();
  21. WebCryptoImpl(const WebCryptoImpl&) = delete;
  22. WebCryptoImpl& operator=(const WebCryptoImpl&) = delete;
  23. ~WebCryptoImpl() override;
  24. void Encrypt(
  25. const blink::WebCryptoAlgorithm& algorithm,
  26. const blink::WebCryptoKey& key,
  27. blink::WebVector<unsigned char> data,
  28. blink::WebCryptoResult result,
  29. scoped_refptr<base::SingleThreadTaskRunner> task_runner) override;
  30. void Decrypt(
  31. const blink::WebCryptoAlgorithm& algorithm,
  32. const blink::WebCryptoKey& key,
  33. blink::WebVector<unsigned char> data,
  34. blink::WebCryptoResult result,
  35. scoped_refptr<base::SingleThreadTaskRunner> task_runner) override;
  36. void Digest(const blink::WebCryptoAlgorithm& algorithm,
  37. blink::WebVector<unsigned char> data,
  38. blink::WebCryptoResult result,
  39. scoped_refptr<base::SingleThreadTaskRunner> task_runner) override;
  40. void GenerateKey(
  41. const blink::WebCryptoAlgorithm& algorithm,
  42. bool extractable,
  43. blink::WebCryptoKeyUsageMask usages,
  44. blink::WebCryptoResult result,
  45. scoped_refptr<base::SingleThreadTaskRunner> task_runner) override;
  46. void ImportKey(
  47. blink::WebCryptoKeyFormat format,
  48. blink::WebVector<unsigned char> key_data,
  49. const blink::WebCryptoAlgorithm& algorithm,
  50. bool extractable,
  51. blink::WebCryptoKeyUsageMask usages,
  52. blink::WebCryptoResult result,
  53. scoped_refptr<base::SingleThreadTaskRunner> task_runner) override;
  54. void ExportKey(
  55. blink::WebCryptoKeyFormat format,
  56. const blink::WebCryptoKey& key,
  57. blink::WebCryptoResult result,
  58. scoped_refptr<base::SingleThreadTaskRunner> task_runner) override;
  59. void Sign(const blink::WebCryptoAlgorithm& algorithm,
  60. const blink::WebCryptoKey& key,
  61. blink::WebVector<unsigned char> data,
  62. blink::WebCryptoResult result,
  63. scoped_refptr<base::SingleThreadTaskRunner> task_runner) override;
  64. void VerifySignature(
  65. const blink::WebCryptoAlgorithm& algorithm,
  66. const blink::WebCryptoKey& key,
  67. blink::WebVector<unsigned char> signature,
  68. blink::WebVector<unsigned char> data,
  69. blink::WebCryptoResult result,
  70. scoped_refptr<base::SingleThreadTaskRunner> task_runner) override;
  71. void WrapKey(
  72. blink::WebCryptoKeyFormat format,
  73. const blink::WebCryptoKey& key,
  74. const blink::WebCryptoKey& wrapping_key,
  75. const blink::WebCryptoAlgorithm& wrap_algorithm,
  76. blink::WebCryptoResult result,
  77. scoped_refptr<base::SingleThreadTaskRunner> task_runner) override;
  78. void UnwrapKey(
  79. blink::WebCryptoKeyFormat format,
  80. blink::WebVector<unsigned char> wrapped_key,
  81. const blink::WebCryptoKey& wrapping_key,
  82. const blink::WebCryptoAlgorithm& unwrap_algorithm,
  83. const blink::WebCryptoAlgorithm& unwrapped_key_algorithm,
  84. bool extractable,
  85. blink::WebCryptoKeyUsageMask usages,
  86. blink::WebCryptoResult result,
  87. scoped_refptr<base::SingleThreadTaskRunner> task_runner) override;
  88. void DeriveBits(
  89. const blink::WebCryptoAlgorithm& algorithm,
  90. const blink::WebCryptoKey& base_key,
  91. unsigned int length_bits,
  92. blink::WebCryptoResult result,
  93. scoped_refptr<base::SingleThreadTaskRunner> task_runner) override;
  94. void DeriveKey(
  95. const blink::WebCryptoAlgorithm& algorithm,
  96. const blink::WebCryptoKey& base_key,
  97. const blink::WebCryptoAlgorithm& import_algorithm,
  98. const blink::WebCryptoAlgorithm& key_length_algorithm,
  99. bool extractable,
  100. blink::WebCryptoKeyUsageMask usages,
  101. blink::WebCryptoResult result,
  102. scoped_refptr<base::SingleThreadTaskRunner> task_runner) override;
  103. bool DeserializeKeyForClone(const blink::WebCryptoKeyAlgorithm& algorithm,
  104. blink::WebCryptoKeyType type,
  105. bool extractable,
  106. blink::WebCryptoKeyUsageMask usages,
  107. const unsigned char* key_data,
  108. unsigned key_data_size,
  109. blink::WebCryptoKey& key) override;
  110. bool SerializeKeyForClone(const blink::WebCryptoKey& key,
  111. blink::WebVector<unsigned char>& key_data) override;
  112. };
  113. } // namespace webcrypto
  114. #endif // COMPONENTS_WEBCRYPTO_WEBCRYPTO_IMPL_H_