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