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 */ |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 | 42 |
43 var KeyBase = function() {}; | 43 var KeyBase = function() {}; |
44 | 44 |
45 Object.defineProperty(KeyBase.prototype, 'algorithm', { | 45 Object.defineProperty(KeyBase.prototype, 'algorithm', { |
46 enumerable: true, | 46 enumerable: true, |
47 get: function() { | 47 get: function() { |
48 return utils.deepCopy(privates(this).impl.algorithm); | 48 return utils.deepCopy(privates(this).impl.algorithm); |
49 } | 49 } |
50 }); | 50 }); |
51 | 51 |
52 var Key = utils.expose( | 52 function Key() { |
53 'Key', | 53 privates(Key).constructPrivate(this, arguments); |
54 KeyImpl, | 54 } |
55 {superclass: KeyBase, readonly: ['extractable', 'type', 'usages']}); | 55 utils.expose(Key, KeyImpl, { |
| 56 superclass: KeyBase, |
| 57 readonly: [ |
| 58 'extractable', |
| 59 'type', |
| 60 'usages', |
| 61 ], |
| 62 }); |
56 | 63 |
57 /** | 64 /** |
58 * Returns |key|'s Subject Public Key Info. Throws an exception if |key| is not | 65 * Returns |key|'s Subject Public Key Info. Throws an exception if |key| is not |
59 * a valid Key object. | 66 * a valid Key object. |
60 * @param {Key} key | 67 * @param {Key} key |
61 * @return {ArrayBuffer} The Subject Public Key Info in DER encoding of |key|. | 68 * @return {ArrayBuffer} The Subject Public Key Info in DER encoding of |key|. |
62 */ | 69 */ |
63 function getSpki(key) { | 70 function getSpki(key) { |
64 if (!privates(key)) | 71 if (!privates(key)) |
65 throw new Error('Invalid key object.'); | 72 throw new Error('Invalid key object.'); |
66 var keyImpl = privates(key).impl; | 73 var keyImpl = privates(key).impl; |
67 if (!keyImpl || !keyImpl.spki) | 74 if (!keyImpl || !keyImpl.spki) |
68 throw new Error('Invalid key object.'); | 75 throw new Error('Invalid key object.'); |
69 return keyImpl.spki; | 76 return keyImpl.spki; |
70 } | 77 } |
71 | 78 |
72 exports.$set('Key', Key); | 79 exports.$set('Key', Key); |
73 exports.$set('KeyType', KeyType); | 80 exports.$set('KeyType', KeyType); |
74 exports.$set('KeyUsage', KeyUsage); | 81 exports.$set('KeyUsage', KeyUsage); |
75 exports.$set('getSpki', getSpki); | 82 exports.$set('getSpki', getSpki); |
OLD | NEW |