How to use the ssri.parse function in ssri

To help you get started, we’ve selected a few ssri examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github npm / cacache / lib / content / read.js View on Github external
const tryFn = () => {
    const sri = ssri.parse(integrity)
    // If `integrity` has multiple entries, pick the first digest
    // with available local data.
    const algo = sri.pickAlgorithm()
    const digests = sri[algo]

    if (digests.length <= 1) {
      const cpath = contentPath(cache, digests[0])
      return fn(cpath, digests[0])
    } else {
      // Can't use race here because a generic error can happen before a ENOENT error, and can happen before a valid result
      return Promise
        .all(digests.map((meta) => {
          return withContentSri(cache, meta, fn)
            .catch((err) => {
              if (err.code === 'ENOENT') {
                return Object.assign(
github davidhealey / waistline / node_modules / npm / lib / install / diff-trees.js View on Github external
function pkgIntegrity (pkg) {
  try {
    // dist is provided by the registry
    var sri = (pkg.dist && pkg.dist.integrity) ||
              // _integrity is provided by pacote
              pkg._integrity ||
              // _shasum is legacy
              (pkg._shasum && ssri.fromHex(pkg._shasum, 'sha1').toString())
    if (!sri) return
    var integrity = ssri.parse(sri)
    if (Object.keys(integrity).length === 0) return
    return integrity
  } catch (ex) {
    return
  }
}
github npm / cacache / lib / content / read.js View on Github external
function withContentSriSync (cache, integrity, fn) {
  const sri = ssri.parse(integrity)
  // If `integrity` has multiple entries, pick the first digest
  // with available local data.
  const algo = sri.pickAlgorithm()
  const digests = sri[algo]
  if (digests.length <= 1) {
    const cpath = contentPath(cache, digests[0])
    return fn(cpath, digests[0])
  } else {
    let lastErr = null
    for (const meta of digests) {
      try {
        return withContentSriSync(cache, meta, fn)
      } catch (err) {
        lastErr = err
      }
    }
github yarnpkg / yarn / __tests__ / lockfile.js View on Github external
test('Lockfile.getLockfile handles integrity field', () => {
  const integrity = ssri.parse('sha1-foo sha512-bar');
  const patterns = {
    foobar: {
      name: 'foobar',
      version: '0.0.0',
      uid: '0.0.0',
      dependencies: {},
      optionalDependencies: {},
      _reference: {
        permissions: {},
      },
      _remote: {
        resolved: 'http://example.com/foobar',
        registry: 'npm',
        integrity,
      },
    },
github JamieMason / shrinkpack / src / lib / get-integrity.ts View on Github external
export const getIntegrity = async (path: string): Promise => {
  try {
    const data = await readFile(path);
    return fromData(data.toString());
  } catch (err) {
    bug(`failed to get hash integrity of ${path} from zkat/ssri`, err);
    return parse('');
  }
};
github electrode-io / fyn / lib / fyn-central.js View on Github external
_analyze(integrity) {
    const sri = ssri.parse(integrity, { single: true });

    const algorithm = sri.algorithm;
    const hex = sri.hexDigest();

    const segLen = 2;
    const contentPath = Path.join(
      ...[this._centralDir, algorithm].concat(
        hex.substr(0, segLen),
        hex.substr(segLen, segLen),
        hex.substr(segLen * 2)
      )
    );

    return { algorithm, contentPath, hex };
  }
github orchoban / react.cordova / node_modules / npm / lib / install / inflate-shrinkwrap.js View on Github external
function childIsEquivalent (sw, requested, child) {
  if (!child) return false
  if (child.fromShrinkwrap) return true
  if (
    sw.integrity &&
    child.package._integrity &&
    ssri.parse(sw.integrity).match(child.package._integrity)
  ) return true
  if (child.isLink && requested.type === 'directory') return path.relative(child.realpath, requested.fetchSpec) === ''

  if (sw.resolved) return child.package._resolved === sw.resolved
  if (!isRegistry(requested) && sw.from) return child.package._from === sw.from
  if (!isRegistry(requested) && child.package._resolved) return sw.version === child.package._resolved
  return child.package.version === sw.version
}

ssri

Standard Subresource Integrity library -- parses, serializes, generates, and verifies integrity metadata according to the SRI spec.

ISC
Latest version published 1 month ago

Package Health Score

92 / 100
Full package analysis