Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Unified Diff: content/child/webcrypto/generate_key_result.h

Issue 512023002: Refactor the interface for generating keys. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use a new return type "GenerateKeyPairResult" to encapsulate secretkey vs keypair Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/child/webcrypto/generate_key_result.h
diff --git a/content/child/webcrypto/generate_key_result.h b/content/child/webcrypto/generate_key_result.h
new file mode 100644
index 0000000000000000000000000000000000000000..0c52fbaabf9ea01de9283451337acba3d9bc37d4
--- /dev/null
+++ b/content/child/webcrypto/generate_key_result.h
@@ -0,0 +1,64 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_CHILD_WEBCRYPTO_GENERATE_KEY_RESULT_H_
+#define CONTENT_CHILD_WEBCRYPTO_GENERATE_KEY_RESULT_H_
+
+#include "content/common/content_export.h"
+#include "third_party/WebKit/public/platform/WebCrypto.h"
+
+namespace content {
+
+namespace webcrypto {
+
+// This is the result object when generating keys. It encapsulates either a
+// secret key, or a public/private key pair.
+class CONTENT_EXPORT GenerateKeyResult {
+ public:
+ enum Type {
+ // An empty (or "null") result.
+ TYPE_NULL,
+
+ // The result is a secret key, accessible through secret_key()
+ TYPE_SECRET_KEY,
+
+ // The result is a public/private key pair, accessible through public_key()
+ // and private_key()
+ TYPE_PUBLIC_PRIVATE_KEY_PAIR
+ };
+
+ // Initializes a "null" instance.
+ GenerateKeyResult();
+
+ Type type() const;
+
+ // Changes the type of the result. To subsequently assign the key(s) use the
+ // mutable_* methods.
+ void set_type(Type type);
+
+ const blink::WebCryptoKey& secret_key() const;
+ const blink::WebCryptoKey& public_key() const;
+ const blink::WebCryptoKey& private_key() const;
+
+ blink::WebCryptoKey* mutable_secret_key();
+ blink::WebCryptoKey* mutable_public_key();
+ blink::WebCryptoKey* mutable_private_key();
+
+ // Sends the key(s) to the Blink result. Should not be called for "null"
+ // results.
+ void Complete(blink::WebCryptoResult* out) const;
+
+ private:
+ Type type_;
+
+ blink::WebCryptoKey secret_key_;
+ blink::WebCryptoKey public_key_;
+ blink::WebCryptoKey private_key_;
Ryan Sleevi 2014/10/17 21:01:58 since blink::WebCryptoKey types are direct-assigna
eroman 2014/10/17 22:43:12 Done. I agree mutable_ was a bit odd and not idiom
+};
+
+} // namespace webcrypto
+
+} // namespace content
+
+#endif // CONTENT_CHILD_WEBCRYPTO_GENERATE_KEY_RESULT_H_

Powered by Google App Engine
This is Rietveld 408576698