| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 var internalAPI = require('platformKeys.internalAPI'); | |
| 6 | |
| 7 var normalizeAlgorithm = | |
| 8 requireNative('platform_keys_natives').NormalizeAlgorithm; | |
| 9 | |
| 10 function combineAlgorithms(algorithm, importParams) { | |
| 11 if (importParams.name === undefined) { | |
| 12 importParams.name = algorithm.name; | |
| 13 } | |
| 14 | |
| 15 // Verify whether importParams.hash equals | |
| 16 // { name: 'none' } | |
| 17 if (importParams.hash && | |
| 18 importParams.hash.name.toLowerCase() === 'none') { | |
| 19 if (Object.keys(importParams.hash).length != 1 || | |
| 20 Object.keys(importParams).length != 2) { | |
| 21 // 'name' must be the only hash property in this case. | |
| 22 throw new Error('A required parameter was missing or out-of-range'); | |
| 23 } | |
| 24 importParams.hash.name = 'none'; | |
| 25 } else { | |
| 26 // Otherwise apply WebCrypto's algorithm normalization. | |
| 27 importParams = normalizeAlgorithm(importParams, 'ImportKey'); | |
| 28 if (!importParams) { | |
| 29 // throw CreateSyntaxError(); | |
| 30 throw new Error('A required parameter was missing or out-of-range'); | |
| 31 } | |
| 32 } | |
| 33 | |
| 34 // internalAPI.getPublicKey returns publicExponent as ArrayBuffer, but it | |
| 35 // should be a Uint8Array. | |
| 36 if (algorithm.publicExponent) { | |
| 37 algorithm.publicExponent = new Uint8Array(algorithm.publicExponent); | |
| 38 } | |
| 39 | |
| 40 for (var key in importParams) { | |
| 41 algorithm[key] = importParams[key]; | |
| 42 } | |
| 43 | |
| 44 return algorithm; | |
| 45 } | |
| 46 | |
| 47 function getPublicKey(cert, importParams, callback) { | |
| 48 internalAPI.getPublicKey(cert, function(publicKey, algorithm) { | |
| 49 var combinedAlgorithm = combineAlgorithms(algorithm, importParams); | |
| 50 callback(publicKey, combinedAlgorithm); | |
| 51 }); | |
| 52 } | |
| 53 | |
| 54 exports.getPublicKey = getPublicKey; | |
| OLD | NEW |