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

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

Issue 332233002: enterprise.platformKeys: Copy-on-read the 'algorithm' member of Key objects. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changed to copy-on-read. Created 6 years, 6 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
index 7d146cc69acc1193153a4b3355984d5eca741bf8..11ffa64ed2dd949611168d7182e063c98532a9ac 100644
--- a/chrome/renderer/resources/extensions/enterprise_platform_keys/key.js
+++ b/chrome/renderer/resources/extensions/enterprise_platform_keys/key.js
@@ -22,6 +22,36 @@ var KeyUsage = {
verify: 'verify'
};
+// Copies |value| recursively. |value| must not contain cyclic references.
+// Copies only nested structures of non-object types (like number), Array,
+// Uint8Array and the directly owned properties of objects (it ignores
+// prototypes).
+function deepCopy(value) {
+ if (value === null)
+ return null;
+ if (typeof(value) !== 'object')
+ return value;
+
+ var copy = null;
+ if (Array.isArray(value) ) {
+ copy = new Array();
+ for (var i = 0; i < value.length; i++)
+ copy[i] = deepCopy(value[i]);
+ } else if (value.__proto__.constructor.name === 'Uint8Array') {
+ copy = new Uint8Array(value.length);
+ for (var i = 0; i < value.length; i++)
+ copy[i] = value[i];
+ } else {
+ copy = new Object();
+ for (var key in value) {
+ if (!value.hasOwnProperty(key))
+ continue;
+ copy[key] = deepCopy(value[key]);
+ }
+ }
+ return copy;
+}
+
/**
* Implementation of WebCrypto.Key used in enterprise.platformKeys.
* @param {KeyType} type The type of the new key.
@@ -40,10 +70,19 @@ var KeyImpl = function(type, publicKeySpki, algorithm, usages, extractable) {
this.extractable = extractable;
};
-var Key =
- utils.expose('Key',
- KeyImpl,
- {readonly:['extractable', 'type', 'algorithm', 'usages']});
+var KeyBase = function() {};
+
+Object.defineProperty(KeyBase.prototype, 'algorithm', {
+ enumerable: true,
+ get: function() {
+ return deepCopy(privates(this).impl.algorithm);
+ }
+});
+
+var Key = utils.expose(
+ 'Key',
+ KeyImpl,
+ {superclass: KeyBase, readonly: ['extractable', 'type', 'usages']});
/**
* Returns |key|'s Subject Public Key Info. Throws an exception if |key| is not

Powered by Google App Engine
This is Rietveld 408576698