node-webcrypto-ossl
Advanced tools
Comparing version 1.0.31 to 1.0.32
@@ -19,3 +19,11 @@ "use strict"; | ||
function ab2b(ab) { | ||
return new Buffer(ab); | ||
if (Buffer.isBuffer(ab)) { | ||
return ab; | ||
} | ||
else if (ArrayBuffer.isView(ab)) { | ||
return new Buffer(ab.buffer); | ||
} | ||
else { | ||
return new Buffer(ab); | ||
} | ||
} | ||
@@ -22,0 +30,0 @@ var SubtleCrypto = (function (_super) { |
{ | ||
"name": "node-webcrypto-ossl", | ||
"version": "1.0.31", | ||
"version": "1.0.32", | ||
"repository": { | ||
@@ -5,0 +5,0 @@ "type": "git", |
@@ -6,5 +6,5 @@ # node-webcrypto-ossl | ||
[![Coverage Status](https://coveralls.io/repos/github/PeculiarVentures/node-webcrypto-ossl/badge.svg?branch=master)](https://coveralls.io/github/PeculiarVentures/node-webcrypto-ossl?branch=master) | ||
[![NPM version](https://badge.fury.io/js/node-webcrypto-ossl.png)](http://badge.fury.io/js/node-webcrypto-ossl) | ||
[![npm version](https://badge.fury.io/js/node-webcrypto-ossl.svg)](https://badge.fury.io/js/node-webcrypto-ossl) | ||
[![NPM](https://nodei.co/npm-dl/node-webcrypto-ossl.png?months=2&height=2)](https://nodei.co/npm/node-webcrypto-ossl/) | ||
[![NPM](https://nodei.co/npm/node-webcrypto-ossl.png)](https://nodei.co/npm/node-webcrypto-ossl/) | ||
@@ -11,0 +11,0 @@ We wanted to be able to write Javascript that used crypto on both the client and the server but we did not want to rely on Javascript implementations of crypto. The only native cryptography available in browser is [Web Crypto](http://caniuse.com/#search=cryptography), this resulted in us creating a `node-webcrypto-ossl` a native polyfill for WebCrypto based on OpenSSL. |
@@ -7,18 +7,40 @@ "use strict"; | ||
var TEST_MESSAGE = new Buffer("12345678901234561234567890123456"); | ||
context("Sha", function () { | ||
["SHA-1", "SHA-256", "SHA-384", "SHA-512"].forEach(digestAlg => | ||
it(`Valid digest ${digestAlg}`, done => { | ||
webcrypto.subtle.digest({ name: digestAlg }, TEST_MESSAGE) | ||
.then(function (k) { | ||
assert.equal(k.key !== null, true, "Digest is empty"); | ||
return Promise.resolve(); | ||
}) | ||
.then(done, done); | ||
})); | ||
var vector = { | ||
data: new Uint8Array([116, 101, 115, 116]), // "test" | ||
algs: { | ||
"SHA-1": "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3", | ||
"SHA-256": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08", | ||
"SHA-384": "768412320f7b0aa5812fce428dc4706b3cae50e02a64caa16a782249bfe8efc4b7ef1ccb126255d196047dfedf17a0a9", | ||
"SHA-512": "ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff", | ||
} | ||
}; | ||
var dataList = { | ||
ArrayBuffer: vector.data.buffer, | ||
Buffer: new Buffer(vector.data), | ||
Uint8Array: vector.data, | ||
Uint16Array: new Uint16Array(vector.data.buffer), | ||
Uint32Array: new Uint32Array(vector.data.buffer), | ||
}; | ||
["SHA-1", "SHA-256", "SHA-384", "SHA-512"].forEach(digestAlg => { | ||
context(digestAlg, () => { | ||
for (const type in dataList) { | ||
(() => { | ||
const data = dataList[type]; | ||
it(type, done => { | ||
webcrypto.subtle.digest(digestAlg, data) | ||
.then(function (hash) { | ||
assert.equal(Buffer.from(hash).toString("hex").toLowerCase(), vector.algs[digestAlg]); | ||
}) | ||
.then(done, done); | ||
}); | ||
})(); | ||
} | ||
}); | ||
}); | ||
}); | ||
}) | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
357253
3970
105