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; |