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