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

Side by Side Diff: chrome/renderer/resources/extensions/platform_keys/key.js

Issue 1939833003: Sanitize inheritance in callers of utils.expose (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
Patch Set: Created 4 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 var utils = require('utils'); 5 var utils = require('utils');
6 6
7 /** 7 /**
8 * Enum of possible key types (subset of WebCrypto.KeyType). 8 * Enum of possible key types (subset of WebCrypto.KeyType).
9 * @enum {string} 9 * @enum {string}
10 */ 10 */
11 var KeyType = { 11 var KeyType = {
12 __proto__: null,
12 public: 'public', 13 public: 'public',
13 private: 'private' 14 private: 'private'
14 }; 15 };
15 16
16 /** 17 /**
17 * Enum of possible key usages (subset of WebCrypto.KeyUsage). 18 * Enum of possible key usages (subset of WebCrypto.KeyUsage).
18 * @enum {string} 19 * @enum {string}
19 */ 20 */
20 var KeyUsage = { 21 var KeyUsage = {
22 __proto__: null,
21 sign: 'sign', 23 sign: 'sign',
22 verify: 'verify' 24 verify: 'verify'
23 }; 25 };
24 26
25 /** 27 /**
26 * Implementation of WebCrypto.Key used in enterprise.platformKeys. 28 * Implementation of WebCrypto.Key used in enterprise.platformKeys.
27 * @param {KeyType} type The type of the new key. 29 * @param {KeyType} type The type of the new key.
28 * @param {ArrayBuffer} publicKeySpki The Subject Public Key Info in DER 30 * @param {ArrayBuffer} publicKeySpki The Subject Public Key Info in DER
29 * encoding. 31 * encoding.
30 * @param {KeyAlgorithm} algorithm The algorithm identifier. 32 * @param {KeyAlgorithm} algorithm The algorithm identifier.
31 * @param {KeyUsage[]} usages The allowed key usages. 33 * @param {KeyUsage[]} usages The allowed key usages.
32 * @param {boolean} extractable Whether the key is extractable. 34 * @param {boolean} extractable Whether the key is extractable.
33 * @constructor 35 * @constructor
34 */ 36 */
35 var KeyImpl = function(type, publicKeySpki, algorithm, usages, extractable) { 37 function KeyImpl(type, publicKeySpki, algorithm, usages, extractable) {
36 this.type = type; 38 this.type = type;
37 this.spki = publicKeySpki; 39 this.spki = publicKeySpki;
38 this.algorithm = algorithm; 40 this.algorithm = algorithm;
39 this.usages = usages; 41 this.usages = usages;
40 this.extractable = extractable; 42 this.extractable = extractable;
43 }
44 $Object.setPrototypeOf(KeyImpl.prototype, null);
45
46 /**
47 * The public base class of Key.
48 */
49 function KeyBase() {}
50 KeyBase.prototype = {
51 constructor: KeyBase,
52 get algorithm() {
53 return utils.deepCopy(privates(this).impl.algorithm);
54 },
41 }; 55 };
42 56
43 var KeyBase = function() {};
44
45 Object.defineProperty(KeyBase.prototype, 'algorithm', {
46 enumerable: true,
47 get: function() {
48 return utils.deepCopy(privates(this).impl.algorithm);
49 }
50 });
51
52 function Key() { 57 function Key() {
53 privates(Key).constructPrivate(this, arguments); 58 privates(Key).constructPrivate(this, arguments);
54 } 59 }
55 utils.expose(Key, KeyImpl, { 60 utils.expose(Key, KeyImpl, {
56 superclass: KeyBase, 61 superclass: KeyBase,
57 readonly: [ 62 readonly: [
58 'extractable', 63 'extractable',
59 'type', 64 'type',
60 'usages', 65 'usages',
61 ], 66 ],
(...skipping 11 matching lines...) Expand all
73 var keyImpl = privates(key).impl; 78 var keyImpl = privates(key).impl;
74 if (!keyImpl || !keyImpl.spki) 79 if (!keyImpl || !keyImpl.spki)
75 throw new Error('Invalid key object.'); 80 throw new Error('Invalid key object.');
76 return keyImpl.spki; 81 return keyImpl.spki;
77 } 82 }
78 83
79 exports.$set('Key', Key); 84 exports.$set('Key', Key);
80 exports.$set('KeyType', KeyType); 85 exports.$set('KeyType', KeyType);
81 exports.$set('KeyUsage', KeyUsage); 86 exports.$set('KeyUsage', KeyUsage);
82 exports.$set('getSpki', getSpki); 87 exports.$set('getSpki', getSpki);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698