🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

sri

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sri - npm Package Compare versions

Comparing version
1.0.0
to
1.1.0
+13
-14
index.js

@@ -1,21 +0,20 @@

const path = require('path');
const exec = require('child_process').exec;
const crypto = require('crypto');
function getSRIHash(filePath) {
const algorithm = 'sha384';
return new Promise(function(resolve, reject) {
function getSRIString(data) {
return getIntegrity(algorithm, getSRIHash(data));
}
exec(getCommand(filePath), function(err, stdout, stderr) {
if (err) { reject(err); }
else { resolve(stdout); }
});
});
function getIntegrity(algorithm, hash) {
return `${algorithm}-${hash}`;
}
function getCommand(filePath) {
return `cat ${path.join(__dirname, filePath)} | openssl dgst -sha384 -binary | openssl enc -base64 -A`
function getSRIHash(data) {
return crypto
.createHash(algorithm)
.update(data, 'utf8')
.digest('base64');
}
module.exports = getSRIHash;
module.exports = { getSRIString };
{
"name": "sri",
"version": "1.0.0",
"version": "1.1.0",
"description": "Subresource Integrity hash generator",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -16,7 +16,5 @@ # sri

```javascript
const getSRIHash = require('sri');
const sri = require('sri');
getSRIHash('file.js')
.then((hash) => console.log(hash))
.catch((error) => console.error(error));
const sriString = sri.getSRIString('file.js'); // sha384-J5Dqvq3...
```

@@ -1,14 +0,16 @@

const getSRIHash = require('../index');
const sri = require('../index');
const fs = require('fs');
const path = require('path');
const expected = 'bFHdtDIrMJABoPy41E4hepGKnrLYuQ60YjPufbnrIQFU0da1u62PDdnK+aVeB3gr';
const expected = 'sha384-J5Dqvq3qATcLhtSkdquOAC/pjNfj8c+oSP55YxlmhCRpAmMfdBuTMJZodkLMhw2r';
getSRIHash('./index.js')
.then(function(hash) {
fs.readFile(path.join(__dirname, '../index.js'), 'utf8', function(err, data) {
if (hash !== expected) {
throw Error(`Wrong hash: ${hash}`);
} else {
console.log(`Passed: ${hash}`);
}
})
.catch(function(err) { console.log(err); });
const sriString = sri.getSRIString(data);
if (sriString !== expected) {
throw Error(`Wrong hash: ${sriString}`);
} else {
console.log(`Passed: ${sriString}`);
}
});