blob: 4c2fe203760b5ec96fed819ece692fe9f14ebb10 [file] [log] [blame]
eroman9b747eaf2014-10-18 22:03:281// 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
erg56f12322015-04-17 00:51:485#ifndef COMPONENTS_WEBCRYPTO_GENERATE_KEY_RESULT_H_
6#define COMPONENTS_WEBCRYPTO_GENERATE_KEY_RESULT_H_
eroman9b747eaf2014-10-18 22:03:287
eroman9b747eaf2014-10-18 22:03:288#include "third_party/WebKit/public/platform/WebCrypto.h"
9
eroman9b747eaf2014-10-18 22:03:2810namespace webcrypto {
11
12// This is the result object when generating keys. It encapsulates either a
13// secret key, or a public/private key pair.
erg56f12322015-04-17 00:51:4814class GenerateKeyResult {
eroman9b747eaf2014-10-18 22:03:2815 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
erg56f12322015-04-17 00:51:4855#endif // COMPONENTS_WEBCRYPTO_GENERATE_KEY_RESULT_H_