generate_key_result.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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_GENERATE_KEY_RESULT_H_
  5. #define COMPONENTS_WEBCRYPTO_GENERATE_KEY_RESULT_H_
  6. #include "third_party/blink/public/platform/web_crypto.h"
  7. namespace webcrypto {
  8. // This is the result object when generating keys. It encapsulates either a
  9. // secret key, or a public/private key pair.
  10. class GenerateKeyResult {
  11. public:
  12. enum Type {
  13. // An empty (or "null") result.
  14. TYPE_NULL,
  15. // The result is a secret key, accessible through secret_key()
  16. TYPE_SECRET_KEY,
  17. // The result is a public/private key pair, accessible through public_key()
  18. // and private_key()
  19. TYPE_PUBLIC_PRIVATE_KEY_PAIR
  20. };
  21. // Initializes a "null" instance.
  22. GenerateKeyResult();
  23. Type type() const;
  24. const blink::WebCryptoKey& secret_key() const;
  25. const blink::WebCryptoKey& public_key() const;
  26. const blink::WebCryptoKey& private_key() const;
  27. void AssignSecretKey(const blink::WebCryptoKey& key);
  28. void AssignKeyPair(const blink::WebCryptoKey& public_key,
  29. const blink::WebCryptoKey& private_key);
  30. // Sends the key(s) to the Blink result. Should not be called for "null"
  31. // results.
  32. void Complete(blink::WebCryptoResult* out) const;
  33. private:
  34. Type type_;
  35. blink::WebCryptoKey secret_key_;
  36. blink::WebCryptoKey public_key_;
  37. blink::WebCryptoKey private_key_;
  38. };
  39. } // namespace webcrypto
  40. #endif // COMPONENTS_WEBCRYPTO_GENERATE_KEY_RESULT_H_