OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 var internalAPI = require('platformKeys.internalAPI'); | 6 var internalAPI = require('platformKeys.internalAPI'); |
7 var keyModule = require('platformKeys.Key'); | 7 var keyModule = require('platformKeys.Key'); |
8 var getSpki = keyModule.getSpki; | 8 var getSpki = keyModule.getSpki; |
9 var KeyUsage = keyModule.KeyUsage; | 9 var KeyUsage = keyModule.KeyUsage; |
10 | 10 |
11 var normalizeAlgorithm = | 11 var normalizeAlgorithm = |
12 requireNative('platform_keys_natives').NormalizeAlgorithm; | 12 requireNative('platform_keys_natives').NormalizeAlgorithm; |
13 | 13 |
14 // This error is thrown by the internal and public API's token functions and | 14 // This error is thrown by the internal and public API's token functions and |
15 // must be rethrown by this custom binding. Keep this in sync with the C++ part | 15 // must be rethrown by this custom binding. Keep this in sync with the C++ part |
16 // of this API. | 16 // of this API. |
17 var errorInvalidToken = "The token is not valid."; | 17 var errorInvalidToken = 'The token is not valid.'; |
18 | 18 |
19 // The following errors are specified in WebCrypto. | 19 // The following errors are specified in WebCrypto. |
20 // TODO(pneubeck): These should be DOMExceptions. | 20 // TODO(pneubeck): These should be DOMExceptions. |
21 function CreateNotSupportedError() { | 21 function CreateNotSupportedError() { |
22 return new Error('The algorithm is not supported'); | 22 return new Error('The algorithm is not supported'); |
23 } | 23 } |
24 | 24 |
25 function CreateInvalidAccessError() { | 25 function CreateInvalidAccessError() { |
26 return new Error('The requested operation is not valid for the provided key'); | 26 return new Error('The requested operation is not valid for the provided key'); |
27 } | 27 } |
(...skipping 20 matching lines...) Expand all Loading... |
48 } | 48 } |
49 return false; | 49 return false; |
50 } | 50 } |
51 | 51 |
52 /** | 52 /** |
53 * Implementation of WebCrypto.SubtleCrypto used in platformKeys and | 53 * Implementation of WebCrypto.SubtleCrypto used in platformKeys and |
54 * enterprise.platformKeys. | 54 * enterprise.platformKeys. |
55 * @param {string} tokenId The id of the backing Token. | 55 * @param {string} tokenId The id of the backing Token. |
56 * @constructor | 56 * @constructor |
57 */ | 57 */ |
58 var SubtleCryptoImpl = function(tokenId) { | 58 function SubtleCryptoImpl(tokenId) { |
59 this.tokenId = tokenId; | 59 this.tokenId = tokenId; |
60 }; | 60 } |
| 61 $Object.setPrototypeOf(SubtleCryptoImpl.prototype, null); |
61 | 62 |
62 SubtleCryptoImpl.prototype.sign = function(algorithm, key, dataView) { | 63 SubtleCryptoImpl.prototype.sign = function(algorithm, key, dataView) { |
63 var subtleCrypto = this; | 64 var subtleCrypto = this; |
64 return new Promise(function(resolve, reject) { | 65 return new Promise(function(resolve, reject) { |
65 if (key.type != 'private' || key.usages.indexOf(KeyUsage.sign) == -1) | 66 if (key.type != 'private' || key.usages.indexOf(KeyUsage.sign) == -1) |
66 throw CreateInvalidAccessError(); | 67 throw CreateInvalidAccessError(); |
67 | 68 |
68 var normalizedAlgorithmParameters = | 69 var normalizedAlgorithmParameters = |
69 normalizeAlgorithm(algorithm, 'Sign'); | 70 normalizeAlgorithm(algorithm, 'Sign'); |
70 if (!normalizedAlgorithmParameters) { | 71 if (!normalizedAlgorithmParameters) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 utils.expose(SubtleCrypto, SubtleCryptoImpl, { | 117 utils.expose(SubtleCrypto, SubtleCryptoImpl, { |
117 functions: [ | 118 functions: [ |
118 'sign', | 119 'sign', |
119 'exportKey', | 120 'exportKey', |
120 ], | 121 ], |
121 }); | 122 }); |
122 | 123 |
123 // Required for subclassing. | 124 // Required for subclassing. |
124 exports.$set('SubtleCryptoImpl', SubtleCryptoImpl); | 125 exports.$set('SubtleCryptoImpl', SubtleCryptoImpl); |
125 exports.$set('SubtleCrypto', SubtleCrypto); | 126 exports.$set('SubtleCrypto', SubtleCrypto); |
OLD | NEW |