-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunwrapKey.js
executable file
·51 lines (42 loc) · 1.69 KB
/
unwrapKey.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
var algorithms = require('./algorithms');
var functions = require('./functions');
var aes = require('./DJCL/src/aes').aes;
var encoding = require('./DJCL/src/encoding').encoding;
var hashing = require('./DJCL/src/hashing').hashing;
var rsa = require('./DJCL/src/rsa').rsa;
var Q = require('q');
exports.unwrapKey = function(format, wrappedKey, unwrappingKey, unwrapAlgorithm, unwrappedKeyAlgorithm, extractable, keyUsages){
var unwrapKeypromise = new Q.Promise(function(resolve,reject){
var algorithm = unwrapAlgorithm;
if (!algorithm.hasOwnProperty("name")){
reject ("Name of algorithm is not provided");
}
var algo = algorithm.name;
//Checking if the algo name in present in the suggested algorithms
if (algorithms.unwrapKeyalgos.indexOf(algo)==-1 && decryptalgos.indexOf(algo)==-1){
//Not correct. Check how to reject a DOMException
reject("The algorithm is not supported");
}
if (!unwrappedKeyAlgorithm.hasOwnProperty("name")){
reject ("Name of the unwrap key algorithm is not provided");
}
if (alogrithms.importKeyalgos.indexOf(unwrappedKeyAlgorithm.name)==-1){
reject("NotSupportedError");
}
if (!unwrappingKey.hasOwnProperty("usages")){
reject ("usages attribute of unwrappingKey is not provided");
}
else if (unwrappingKey.usages.indexOf("unwrapKey")==-1){
reject ("InvalidAccessError");
}
//Checking if the format is one of the recognized key format values
if (!functions.checkRecognizedKeyFormatValues(format)){
reject ("SyntaxError");
}
if (!functions.checkRecognizedKeyUsageValues(keyUsages)){
reject("SyntaxError");
}
//TODO : How to unwrap the key
});
return unwrapKeypromise;
};