Skip to content

Commit 0e78fd7

Browse files
committed
feat: remove figgy-pudding
1 parent 79ba4ec commit 0e78fd7

File tree

4 files changed

+29
-97
lines changed

4 files changed

+29
-97
lines changed

index.js

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict'
22

33
const crypto = require('crypto')
4-
const figgyPudding = require('figgy-pudding')
54
const MiniPass = require('minipass')
65

76
const SPEC_ALGORITHMS = ['sha256', 'sha384', 'sha512']
@@ -11,17 +10,17 @@ const SRI_REGEX = /^([^-]+)-([^?]+)([?\S*]*)$/
1110
const STRICT_SRI_REGEX = /^([^-]+)-([A-Za-z0-9+/=]{44,88})(\?[\x21-\x7E]*)*$/
1211
const VCHAR_REGEX = /^[\x21-\x7E]+$/
1312

14-
const SsriOpts = figgyPudding({
15-
algorithms: { default: ['sha512'] },
16-
error: { default: false },
17-
integrity: {},
18-
options: { default: [] },
19-
pickAlgorithm: { default: () => getPrioritizedHash },
20-
sep: { default: ' ' },
21-
single: { default: false },
22-
size: {},
23-
strict: { default: false }
24-
})
13+
const defaultOpts = {
14+
algorithms: ['sha512'],
15+
error: false,
16+
options: [],
17+
pickAlgorithm: getPrioritizedHash,
18+
sep: ' ',
19+
single: false,
20+
strict: false
21+
}
22+
23+
const ssriOpts = (opts = {}) => ({ ...defaultOpts, ...opts })
2524

2625
const getOptString = options => !options || !options.length ? ''
2726
: `?${options.join('?')}`
@@ -101,7 +100,7 @@ class IntegrityStream extends MiniPass {
101100
class Hash {
102101
get isHash () { return true }
103102
constructor (hash, opts) {
104-
opts = SsriOpts(opts)
103+
opts = ssriOpts(opts)
105104
const strict = !!opts.strict
106105
this.source = hash.trim()
107106

@@ -138,7 +137,7 @@ class Hash {
138137
}
139138

140139
toString (opts) {
141-
opts = SsriOpts(opts)
140+
opts = ssriOpts(opts)
142141
if (opts.strict) {
143142
// Strict mode enforces the standard as close to the foot of the
144143
// letter as it can.
@@ -173,7 +172,7 @@ class Integrity {
173172
}
174173

175174
toString (opts) {
176-
opts = SsriOpts(opts)
175+
opts = ssriOpts(opts)
177176
let sep = opts.sep || ' '
178177
if (opts.strict) {
179178
// Entries must be separated by whitespace, according to spec.
@@ -187,7 +186,7 @@ class Integrity {
187186
}
188187

189188
concat (integrity, opts) {
190-
opts = SsriOpts(opts)
189+
opts = ssriOpts(opts)
191190
const other = typeof integrity === 'string'
192191
? integrity
193192
: stringify(integrity, opts)
@@ -201,7 +200,7 @@ class Integrity {
201200
// add additional hashes to an integrity value, but prevent
202201
// *changing* an existing integrity hash.
203202
merge (integrity, opts) {
204-
opts = SsriOpts(opts)
203+
opts = ssriOpts(opts)
205204
const other = parse(integrity, opts)
206205
for (const algo in other) {
207206
if (this[algo]) {
@@ -217,7 +216,7 @@ class Integrity {
217216
}
218217

219218
match (integrity, opts) {
220-
opts = SsriOpts(opts)
219+
opts = ssriOpts(opts)
221220
const other = parse(integrity, opts)
222221
const algo = other.pickAlgorithm(opts)
223222
return (
@@ -232,7 +231,7 @@ class Integrity {
232231
}
233232

234233
pickAlgorithm (opts) {
235-
opts = SsriOpts(opts)
234+
opts = ssriOpts(opts)
236235
const pickAlgorithm = opts.pickAlgorithm
237236
const keys = Object.keys(this)
238237
if (!keys.length) {
@@ -248,7 +247,7 @@ class Integrity {
248247

249248
module.exports.parse = parse
250249
function parse (sri, opts) {
251-
opts = SsriOpts(opts)
250+
opts = ssriOpts(opts)
252251
if (typeof sri === 'string') {
253252
return _parse(sri, opts)
254253
} else if (sri.algorithm && sri.digest) {
@@ -279,7 +278,7 @@ function _parse (integrity, opts) {
279278

280279
module.exports.stringify = stringify
281280
function stringify (obj, opts) {
282-
opts = SsriOpts(opts)
281+
opts = ssriOpts(opts)
283282
if (obj.algorithm && obj.digest) {
284283
return Hash.prototype.toString.call(obj, opts)
285284
} else if (typeof obj === 'string') {
@@ -291,7 +290,7 @@ function stringify (obj, opts) {
291290

292291
module.exports.fromHex = fromHex
293292
function fromHex (hexDigest, algorithm, opts) {
294-
opts = SsriOpts(opts)
293+
opts = ssriOpts(opts)
295294
const optString = getOptString(opts.options)
296295
return parse(
297296
`${algorithm}-${
@@ -302,7 +301,7 @@ function fromHex (hexDigest, algorithm, opts) {
302301

303302
module.exports.fromData = fromData
304303
function fromData (data, opts) {
305-
opts = SsriOpts(opts)
304+
opts = ssriOpts(opts)
306305
const algorithms = opts.algorithms
307306
const optString = getOptString(opts.options)
308307
return algorithms.reduce((acc, algo) => {
@@ -325,7 +324,7 @@ function fromData (data, opts) {
325324

326325
module.exports.fromStream = fromStream
327326
function fromStream (stream, opts) {
328-
opts = SsriOpts(opts)
327+
opts = ssriOpts(opts)
329328
const istream = integrityStream(opts)
330329
return new Promise((resolve, reject) => {
331330
stream.pipe(istream)
@@ -340,7 +339,7 @@ function fromStream (stream, opts) {
340339

341340
module.exports.checkData = checkData
342341
function checkData (data, sri, opts) {
343-
opts = SsriOpts(opts)
342+
opts = ssriOpts(opts)
344343
sri = parse(sri, opts)
345344
if (!Object.keys(sri).length) {
346345
if (opts.error) {
@@ -379,10 +378,9 @@ function checkData (data, sri, opts) {
379378

380379
module.exports.checkStream = checkStream
381380
function checkStream (stream, sri, opts) {
382-
opts = SsriOpts(opts)
383-
const checker = integrityStream(opts.concat({
384-
integrity: sri
385-
}))
381+
opts = ssriOpts(opts)
382+
opts.integrity = sri
383+
const checker = integrityStream(opts)
386384
return new Promise((resolve, reject) => {
387385
stream.pipe(checker)
388386
stream.on('error', reject)
@@ -396,12 +394,12 @@ function checkStream (stream, sri, opts) {
396394

397395
module.exports.integrityStream = integrityStream
398396
function integrityStream (opts) {
399-
return new IntegrityStream(SsriOpts(opts))
397+
return new IntegrityStream(ssriOpts(opts))
400398
}
401399

402400
module.exports.create = createIntegrity
403401
function createIntegrity (opts) {
404-
opts = SsriOpts(opts)
402+
opts = ssriOpts(opts)
405403
const algorithms = opts.algorithms
406404
const optString = getOptString(opts.options)
407405

package-lock.json

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
},
3838
"license": "ISC",
3939
"dependencies": {
40-
"figgy-pudding": "^3.5.1",
4140
"minipass": "^3.1.1"
4241
},
4342
"devDependencies": {

test/mutable-opts-resilience.js

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)