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

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

Issue 214863002: Extension API enterprise.platformKeys. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Asynchronous calls revisited. 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/key.js
diff --git a/chrome/renderer/resources/extensions/enterprise_platform_keys/key.js b/chrome/renderer/resources/extensions/enterprise_platform_keys/key.js
new file mode 100644
index 0000000000000000000000000000000000000000..7d146cc69acc1193153a4b3355984d5eca741bf8
--- /dev/null
+++ b/chrome/renderer/resources/extensions/enterprise_platform_keys/key.js
@@ -0,0 +1,66 @@
+// 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');
+
+/**
+ * Enum of possible key types (subset of WebCrypto.KeyType).
+ * @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']});
+
+/**
+ * Returns |key|'s Subject Public Key Info. Throws an exception if |key| is not
+ * a valid Key object.
+ * @param {Key} key
+ * @return {ArrayBuffer} The Subject Public Key Info in DER encoding of |key|.
+ */
+function getSpki(key) {
+ if (!privates(key))
+ throw new Error('Invalid key object.');
+ var keyImpl = privates(key).impl;
+ if (!keyImpl || !keyImpl.spki)
+ throw new Error('Invalid key object.');
+ return keyImpl.spki;
+}
+
+exports.Key = Key;
+exports.KeyType = KeyType;
+exports.KeyUsage = KeyUsage;
+exports.getSpki = getSpki;

Powered by Google App Engine
This is Rietveld 408576698