| 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 var internalAPI = require('enterprise.platformKeys.internalAPI'); | 6 var internalAPI = require('enterprise.platformKeys.internalAPI'); |
| 7 var intersect = require('platformKeys.utils').intersect; | 7 var intersect = require('platformKeys.utils').intersect; |
| 8 var subtleCryptoModule = require('platformKeys.SubtleCrypto'); | 8 var subtleCryptoModule = require('platformKeys.SubtleCrypto'); |
| 9 var SubtleCryptoImpl = subtleCryptoModule.SubtleCryptoImpl; | 9 var SubtleCryptoImpl = subtleCryptoModule.SubtleCryptoImpl; |
| 10 var KeyPair = require('enterprise.platformKeys.KeyPair').KeyPair; | 10 var KeyPair = require('enterprise.platformKeys.KeyPair').KeyPair; |
| 11 var KeyUsage = require('platformKeys.Key').KeyUsage; | 11 var KeyUsage = require('platformKeys.Key').KeyUsage; |
| 12 | 12 |
| 13 var normalizeAlgorithm = | 13 var normalizeAlgorithm = |
| 14 requireNative('platform_keys_natives').NormalizeAlgorithm; | 14 requireNative('platform_keys_natives').NormalizeAlgorithm; |
| 15 | 15 |
| 16 // This error is thrown by the internal and public API's token functions and | 16 // This error is thrown by the internal and public API's token functions and |
| 17 // must be rethrown by this custom binding. Keep this in sync with the C++ part | 17 // must be rethrown by this custom binding. Keep this in sync with the C++ part |
| 18 // of this API. | 18 // of this API. |
| 19 var errorInvalidToken = "The token is not valid."; | 19 var errorInvalidToken = 'The token is not valid.'; |
| 20 | 20 |
| 21 // The following errors are specified in WebCrypto. | 21 // The following errors are specified in WebCrypto. |
| 22 // TODO(pneubeck): These should be DOMExceptions. | 22 // TODO(pneubeck): These should be DOMExceptions. |
| 23 function CreateNotSupportedError() { | 23 function CreateNotSupportedError() { |
| 24 return new Error('The algorithm is not supported'); | 24 return new Error('The algorithm is not supported'); |
| 25 } | 25 } |
| 26 | 26 |
| 27 function CreateInvalidAccessError() { | 27 function CreateInvalidAccessError() { |
| 28 return new Error('The requested operation is not valid for the provided key'); | 28 return new Error('The requested operation is not valid for the provided key'); |
| 29 } | 29 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 } | 66 } |
| 67 if (array[array.length - 1 - i] !== expectedDigit) | 67 if (array[array.length - 1 - i] !== expectedDigit) |
| 68 return false; | 68 return false; |
| 69 } | 69 } |
| 70 return true; | 70 return true; |
| 71 } | 71 } |
| 72 | 72 |
| 73 /** | 73 /** |
| 74 * Implementation of WebCrypto.SubtleCrypto used in enterprise.platformKeys. | 74 * Implementation of WebCrypto.SubtleCrypto used in enterprise.platformKeys. |
| 75 * Derived from platformKeys.SubtleCrypto. | 75 * Derived from platformKeys.SubtleCrypto. |
| 76 * |
| 76 * @param {string} tokenId The id of the backing Token. | 77 * @param {string} tokenId The id of the backing Token. |
| 77 * @constructor | 78 * @constructor |
| 78 */ | 79 */ |
| 79 var EnterpriseSubtleCryptoImpl = function(tokenId) { | 80 function EnterpriseSubtleCryptoImpl(tokenId) { |
| 80 SubtleCryptoImpl.call(this, tokenId); | 81 $Function.call(SubtleCryptoImpl, this, tokenId); |
| 81 }; | 82 } |
| 83 $Object.setPrototypeOf(EnterpriseSubtleCryptoImpl, null); |
| 82 | 84 |
| 83 EnterpriseSubtleCryptoImpl.prototype = | 85 EnterpriseSubtleCryptoImpl.prototype = |
| 84 Object.create(SubtleCryptoImpl.prototype); | 86 Object.create(SubtleCryptoImpl.prototype); |
| 85 | 87 |
| 86 EnterpriseSubtleCryptoImpl.prototype.generateKey = | 88 EnterpriseSubtleCryptoImpl.prototype.generateKey = |
| 87 function(algorithm, extractable, keyUsages) { | 89 function(algorithm, extractable, keyUsages) { |
| 88 var subtleCrypto = this; | 90 var subtleCrypto = this; |
| 89 return new Promise(function(resolve, reject) { | 91 return new Promise(function(resolve, reject) { |
| 90 // TODO(pneubeck): Apply the algorithm normalization of the WebCrypto | 92 // TODO(pneubeck): Apply the algorithm normalization of the WebCrypto |
| 91 // implementation. | 93 // implementation. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 } | 139 } |
| 138 utils.expose(SubtleCrypto, EnterpriseSubtleCryptoImpl, { | 140 utils.expose(SubtleCrypto, EnterpriseSubtleCryptoImpl, { |
| 139 superclass: subtleCryptoModule.SubtleCrypto, | 141 superclass: subtleCryptoModule.SubtleCrypto, |
| 140 functions: [ | 142 functions: [ |
| 141 'generateKey', | 143 'generateKey', |
| 142 // 'sign', 'exportKey' are exposed by the base class | 144 // 'sign', 'exportKey' are exposed by the base class |
| 143 ], | 145 ], |
| 144 }); | 146 }); |
| 145 | 147 |
| 146 exports.$set('SubtleCrypto', SubtleCrypto); | 148 exports.$set('SubtleCrypto', SubtleCrypto); |
| OLD | NEW |