OLD | NEW |
---|---|
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. |
29 * | |
27 * @param {KeyType} type The type of the new key. | 30 * @param {KeyType} type The type of the new key. |
28 * @param {ArrayBuffer} publicKeySpki The Subject Public Key Info in DER | 31 * @param {ArrayBuffer} publicKeySpki The Subject Public Key Info in DER |
29 * encoding. | 32 * encoding. |
30 * @param {KeyAlgorithm} algorithm The algorithm identifier. | 33 * @param {KeyAlgorithm} algorithm The algorithm identifier. |
31 * @param {KeyUsage[]} usages The allowed key usages. | 34 * @param {KeyUsage[]} usages The allowed key usages. |
32 * @param {boolean} extractable Whether the key is extractable. | 35 * @param {boolean} extractable Whether the key is extractable. |
33 * @constructor | 36 * @constructor |
34 */ | 37 */ |
35 var KeyImpl = function(type, publicKeySpki, algorithm, usages, extractable) { | 38 function KeyImpl(type, publicKeySpki, algorithm, usages, extractable) { |
36 this.type = type; | 39 this.type = type; |
37 this.spki = publicKeySpki; | 40 this.spki = publicKeySpki; |
38 this.algorithm = algorithm; | 41 this.algorithm = algorithm; |
39 this.usages = usages; | 42 this.usages = usages; |
40 this.extractable = extractable; | 43 this.extractable = extractable; |
44 } | |
45 $Object.setPrototypeOf(KeyImpl, null); | |
46 $Object.setPrototypeOf(KeyImpl.prototype, null); | |
47 | |
48 /** | |
49 * The public base class of Key. | |
50 */ | |
51 function KeyBase() { | |
Devlin
2016/04/26 22:41:25
nit: let's do "function KeyBase() {}" (one line)
robwu
2016/04/26 23:14:33
Done.
| |
52 } | |
53 KeyBase.prototype = { | |
54 constructor: KeyBase, | |
55 get algorithm() { | |
56 return utils.deepCopy(privates(this).impl.algorithm); | |
57 }, | |
41 }; | 58 }; |
42 | 59 |
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() { | 60 function Key() { |
53 privates(Key).constructPrivate(this, arguments); | 61 privates(Key).constructPrivate(this, arguments); |
54 } | 62 } |
55 utils.expose(Key, KeyImpl, { | 63 utils.expose(Key, KeyImpl, { |
56 superclass: KeyBase, | 64 superclass: KeyBase, |
57 readonly: [ | 65 readonly: [ |
58 'extractable', | 66 'extractable', |
59 'type', | 67 'type', |
60 'usages', | 68 'usages', |
61 ], | 69 ], |
62 }); | 70 }); |
63 | 71 |
64 /** | 72 /** |
65 * Returns |key|'s Subject Public Key Info. Throws an exception if |key| is not | 73 * Returns |key|'s Subject Public Key Info. Throws an exception if |key| is not |
66 * a valid Key object. | 74 * a valid Key object. |
75 * | |
67 * @param {Key} key | 76 * @param {Key} key |
68 * @return {ArrayBuffer} The Subject Public Key Info in DER encoding of |key|. | 77 * @return {ArrayBuffer} The Subject Public Key Info in DER encoding of |key|. |
69 */ | 78 */ |
70 function getSpki(key) { | 79 function getSpki(key) { |
71 if (!privates(key)) | 80 if (!privates(key)) |
72 throw new Error('Invalid key object.'); | 81 throw new Error('Invalid key object.'); |
73 var keyImpl = privates(key).impl; | 82 var keyImpl = privates(key).impl; |
74 if (!keyImpl || !keyImpl.spki) | 83 if (!keyImpl || !keyImpl.spki) |
75 throw new Error('Invalid key object.'); | 84 throw new Error('Invalid key object.'); |
76 return keyImpl.spki; | 85 return keyImpl.spki; |
77 } | 86 } |
78 | 87 |
79 exports.$set('Key', Key); | 88 exports.$set('Key', Key); |
80 exports.$set('KeyType', KeyType); | 89 exports.$set('KeyType', KeyType); |
81 exports.$set('KeyUsage', KeyUsage); | 90 exports.$set('KeyUsage', KeyUsage); |
82 exports.$set('getSpki', getSpki); | 91 exports.$set('getSpki', getSpki); |
OLD | NEW |