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

Unified Diff: chrome/renderer/resources/extensions/enterprise_platform_keys/enterprise_platform_keys_key.js

Issue 214863002: Extension API enterprise.platformKeys. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments. Splitted custom_binding, added comments... Created 6 years, 7 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: chrome/renderer/resources/extensions/enterprise_platform_keys/enterprise_platform_keys_key.js
diff --git a/chrome/renderer/resources/extensions/enterprise_platform_keys/enterprise_platform_keys_key.js b/chrome/renderer/resources/extensions/enterprise_platform_keys/enterprise_platform_keys_key.js
new file mode 100644
index 0000000000000000000000000000000000000000..dcde3c7c6d9c8301fdaccfcb266c1d485b3b57de
--- /dev/null
+++ b/chrome/renderer/resources/extensions/enterprise_platform_keys/enterprise_platform_keys_key.js
@@ -0,0 +1,78 @@
+// 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.
+
+var utils = require('utils');
+var intersect = require('enterprise.platformKeys.utils').intersect;
not at google - send to devlin 2014/05/05 21:09:24 given these files are in the enterprise_platform_k
+
+/**
+ * Enum of possible key types (subset of WebCrypto.KeyType).
not at google - send to devlin 2014/05/05 21:09:24 why is it a subset? will your code still work if y
pneubeck (no reviews) 2014/05/05 21:28:23 WebCrypto has the additional KeyType 'secret' for
not at google - send to devlin 2014/05/05 21:44:49 oh, no, not what I meant. I meant that maybe these
pneubeck (no reviews) 2014/05/06 14:07:21 WebCrypto defines only: typedef DOMString KeyType;
not at google - send to devlin 2014/05/07 00:00:12 Symbolic constants are nice, I won't argue with th
+ * @enum {string}
+ */
+var KeyType = {
+ public: 'public',
+ private: 'private'
+};
+
+/**
+ * Enum of possible key usages (subset of WebCrypto.KeyUsage).
+ * @enum {string}
+ */
+var KeyUsage = {
+ sign: 'sign',
+ verify: 'verify'
+};
+
+/**
+ * Implementation of WebCrypto.Key used in enterprise.platformKeys.
+ * @param {KeyType} type The type of the new key.
+ * @param {ArrayBuffer} publicKeySpki The Subject Public Key Info in DER
+ * encoding.
+ * @param {KeyAlgorithm} algorithm The algorithm identifier.
+ * @param {KeyUsage[]} usages The allowed key usages.
+ * @param {boolean} extractable Whether the key is extractable.
+ * @constructor
+ */
+var KeyImpl = function(type, publicKeySpki, algorithm, usages, extractable) {
+ this.type = type;
+ this.spki = publicKeySpki;
+ this.algorithm = algorithm;
+ this.usages = usages;
+ this.extractable = extractable;
+};
+
+var Key =
+ utils.expose('Key',
+ KeyImpl,
+ {readonly:['extractable', 'type', 'algorithm', 'usages']});
+
+/**
+ * Implementation of WebCrypto.KeyPair used in enterprise.platformKeys.
+ * @param {ArrayBuffer} publicKeySpki The Subject Public Key Info in DER
+ * encoding.
+ * @param {KeyAlgorithm} algorithm The algorithm identifier.
+ * @param {KeyUsage[]} usages The allowed key usages.
+ * @constructor
+ */
+var KeyPairImpl = function(publicKeySpki, algorithm, usages) {
+ this.publicKey = new Key(KeyType.public,
+ publicKeySpki,
+ algorithm,
+ intersect([KeyUsage.verify], usages),
+ true /* extractable */);
+ this.privateKey = new Key(KeyType.private,
+ publicKeySpki,
+ algorithm,
+ intersect([KeyUsage.sign], usages),
+ false /* not extractable */);
+};
+
+var KeyPair = utils.expose('KeyPair',
+ KeyPairImpl,
+ {readonly:['publicKey', 'privateKey']});
+
+exports.Key = Key;
not at google - send to devlin 2014/05/05 21:09:24 ideally (from an OO perspective) you would only ex
+exports.KeyPair = KeyPair;
+exports.KeyImpl = KeyImpl;
not at google - send to devlin 2014/05/05 21:09:24 exposing the Impl is unusual
pneubeck (no reviews) 2014/05/06 14:07:21 Done.
+exports.KeyType = KeyType;
+exports.KeyUsage = KeyUsage;

Powered by Google App Engine
This is Rietveld 408576698