webcrypto-liner
Advanced tools
Comparing version
{ | ||
"name": "webcrypto-liner", | ||
"version": "0.1.17", | ||
"version": "0.1.18", | ||
"description": "A WebCrypto pollyfill that \"smooths out\" the rough-edges in existing User Agent implementations.", | ||
@@ -24,7 +24,8 @@ "main": "build/index.js", | ||
"elliptic": "*", | ||
"webcrypto-core": "^0.1.12" | ||
"webcrypto-core": "^0.1.13" | ||
}, | ||
"devDependencies": { | ||
"ts-loader": "^0.9.5", | ||
"typescript": "*" | ||
"typescript": "*", | ||
"webpack": "^1.14" | ||
}, | ||
@@ -31,0 +32,0 @@ "author": "PeculiarVentures", |
# webcrypto-liner | ||
[](https://raw.githubusercontent.com/PeculiarVentures/webcrypto-liner/master/LICENSE) | ||
[](https://badge.fury.io/js/webcrypto-liner) | ||
[](https://travis-ci.org/PeculiarVentures/webcrypto-liner) | ||
@@ -5,0 +6,0 @@ [](https://nodei.co/npm/webcrypto-liner/) |
@@ -116,3 +116,8 @@ import { AlgorithmError, AlgorithmNames, Base64Url, BaseCrypto, PrepareData } from "webcrypto-core"; | ||
} | ||
return verify(signature, data, key.key); | ||
try { | ||
return verify(signature, data, key.key); | ||
} catch (err) { | ||
console.warn(`Verify error: ${err.message}`); | ||
return false; | ||
} | ||
} | ||
@@ -133,3 +138,8 @@ case AlgorithmNames.RsaPSS.toLowerCase(): | ||
} | ||
return verify(signature, data, key.key, rsaAlg.saltLength); | ||
try { | ||
return verify(signature, data, key.key, rsaAlg.saltLength); | ||
} catch (err) { | ||
console.warn(`Verify error: ${err.message}`); | ||
return false; | ||
} | ||
default: | ||
@@ -239,3 +249,3 @@ throw new LinerError(LinerError.UNSUPPORTED_ALGORITHM, algorithm.name); | ||
const hash = (alg as any).hash as Algorithm; | ||
const hashSize = /(\d+)/.exec(hash.name) ![1]; | ||
const hashSize = /(\d+)/.exec(hash.name)![1]; | ||
switch (alg.name!.toUpperCase()) { | ||
@@ -242,0 +252,0 @@ case AlgorithmNames.RsaOAEP.toUpperCase(): |
@@ -32,3 +32,9 @@ // Core | ||
return crypto.subtle.exportKey("jwk", key) | ||
.then((jwk: any) => subtle.importKey("jwk", jwk, key.algorithm as Algorithm, true, key.usages)); | ||
.then((jwk: any) => { | ||
let alg = GetHashAlgorithm(key); | ||
if (alg) { | ||
alg = assign(alg, key.algorithm); | ||
} | ||
return subtle.importKey("jwk", jwk, alg as any, true, key.usages); | ||
}); | ||
} | ||
@@ -197,3 +203,3 @@ } else { | ||
return PrepareKey(key, Class) | ||
.then((preparedKey) => Class.verify(alg, key, signatureBytes, dataBytes)); | ||
.then((preparedKey) => Class.verify(alg, preparedKey, signatureBytes, dataBytes)); | ||
}); | ||
@@ -559,3 +565,3 @@ } | ||
// fix hash alg for rsa key | ||
function GetHashAlgorithm(key: CryptoKey) { | ||
function GetHashAlgorithm(key: CryptoKey): Algorithm | null { | ||
let alg: Algorithm | null = null; | ||
@@ -562,0 +568,0 @@ keys.some((item) => { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
301920
0.4%3908
0.44%124
0.81%3
50%Updated