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 if (algorithm.publicExponent) { | |
35 algorithm.publicExponent = new Uint8Array(algorithm.publicExponent); | |
Ryan Sleevi
2015/02/03 01:44:50
BUG? The point of WebCrypto is to ensure the impor
pneubeck (no reviews)
2015/02/03 20:15:00
added a comment explaining that this only fixes th
| |
36 } | |
37 | |
38 for (var key in importParams) { | |
39 algorithm[key] = importParams[key]; | |
40 } | |
41 | |
42 return algorithm; | |
43 } | |
44 | |
45 function getPublicKey(cert, importParams, callback) { | |
46 internalAPI.getPublicKey(cert, function(publicKey, algorithm) { | |
47 var combinedAlgorithm = combineAlgorithms(algorithm, importParams); | |
48 callback(publicKey, combinedAlgorithm); | |
49 }); | |
50 } | |
51 | |
52 exports.getPublicKey = getPublicKey; | |
OLD | NEW |