eroman | 9b747eaf | 2014-10-18 22:03:28 | [diff] [blame] | 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 | |
erg | 56f1232 | 2015-04-17 00:51:48 | [diff] [blame] | 5 | #ifndef COMPONENTS_WEBCRYPTO_GENERATE_KEY_RESULT_H_ |
| 6 | #define COMPONENTS_WEBCRYPTO_GENERATE_KEY_RESULT_H_ |
eroman | 9b747eaf | 2014-10-18 22:03:28 | [diff] [blame] | 7 | |
eroman | 9b747eaf | 2014-10-18 22:03:28 | [diff] [blame] | 8 | #include "third_party/WebKit/public/platform/WebCrypto.h" |
| 9 | |
eroman | 9b747eaf | 2014-10-18 22:03:28 | [diff] [blame] | 10 | namespace webcrypto { |
| 11 | |
| 12 | // This is the result object when generating keys. It encapsulates either a |
| 13 | // secret key, or a public/private key pair. |
erg | 56f1232 | 2015-04-17 00:51:48 | [diff] [blame] | 14 | class GenerateKeyResult { |
eroman | 9b747eaf | 2014-10-18 22:03:28 | [diff] [blame] | 15 | public: |
| 16 | enum Type { |
| 17 | // An empty (or "null") result. |
| 18 | TYPE_NULL, |
| 19 | |
| 20 | // The result is a secret key, accessible through secret_key() |
| 21 | TYPE_SECRET_KEY, |
| 22 | |
| 23 | // The result is a public/private key pair, accessible through public_key() |
| 24 | // and private_key() |
| 25 | TYPE_PUBLIC_PRIVATE_KEY_PAIR |
| 26 | }; |
| 27 | |
| 28 | // Initializes a "null" instance. |
| 29 | GenerateKeyResult(); |
| 30 | |
| 31 | Type type() const; |
| 32 | |
| 33 | const blink::WebCryptoKey& secret_key() const; |
| 34 | const blink::WebCryptoKey& public_key() const; |
| 35 | const blink::WebCryptoKey& private_key() const; |
| 36 | |
| 37 | void AssignSecretKey(const blink::WebCryptoKey& key); |
| 38 | void AssignKeyPair(const blink::WebCryptoKey& public_key, |
| 39 | const blink::WebCryptoKey& private_key); |
| 40 | |
| 41 | // Sends the key(s) to the Blink result. Should not be called for "null" |
| 42 | // results. |
| 43 | void Complete(blink::WebCryptoResult* out) const; |
| 44 | |
| 45 | private: |
| 46 | Type type_; |
| 47 | |
| 48 | blink::WebCryptoKey secret_key_; |
| 49 | blink::WebCryptoKey public_key_; |
| 50 | blink::WebCryptoKey private_key_; |
| 51 | }; |
| 52 | |
| 53 | } // namespace webcrypto |
| 54 | |
erg | 56f1232 | 2015-04-17 00:51:48 | [diff] [blame] | 55 | #endif // COMPONENTS_WEBCRYPTO_GENERATE_KEY_RESULT_H_ |