New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

jose-node-cjs-runtime

Package Overview
Dependencies
Maintainers
1
Versions
133
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jose-node-cjs-runtime - npm Package Compare versions

Comparing version 4.12.0 to 4.12.1

84

dist/node/cjs/key/import.js

@@ -6,75 +6,5 @@ "use strict";

const asn1_js_1 = require("../runtime/asn1.js");
const asn1_js_2 = require("../runtime/asn1.js");
const jwk_to_key_js_1 = require("../runtime/jwk_to_key.js");
const errors_js_1 = require("../util/errors.js");
const format_pem_js_1 = require("../lib/format_pem.js");
const is_object_js_1 = require("../lib/is_object.js");
function getElement(seq) {
let result = [];
let next = 0;
while (next < seq.length) {
let nextPart = parseElement(seq.subarray(next));
result.push(nextPart);
next += nextPart.byteLength;
}
return result;
}
function parseElement(bytes) {
let position = 0;
let tag = bytes[0] & 0x1f;
position++;
if (tag === 0x1f) {
tag = 0;
while (bytes[position] >= 0x80) {
tag = tag * 128 + bytes[position] - 0x80;
position++;
}
tag = tag * 128 + bytes[position] - 0x80;
position++;
}
let length = 0;
if (bytes[position] < 0x80) {
length = bytes[position];
position++;
}
else if (length === 0x80) {
length = 0;
while (bytes[position + length] !== 0 || bytes[position + length + 1] !== 0) {
if (length > bytes.byteLength) {
throw new TypeError('invalid indefinite form length');
}
length++;
}
const byteLength = position + length + 2;
return {
byteLength,
contents: bytes.subarray(position, position + length),
raw: bytes.subarray(0, byteLength),
};
}
else {
let numberOfDigits = bytes[position] & 0x7f;
position++;
length = 0;
for (let i = 0; i < numberOfDigits; i++) {
length = length * 256 + bytes[position];
position++;
}
}
const byteLength = position + length;
return {
byteLength,
contents: bytes.subarray(position, byteLength),
raw: bytes.subarray(0, byteLength),
};
}
function spkiFromX509(buf) {
const tbsCertificate = getElement(getElement(parseElement(buf).contents)[0].contents);
return (0, base64url_js_1.encodeBase64)(tbsCertificate[tbsCertificate[0].raw[0] === 0xa0 ? 6 : 5].raw);
}
function getSPKI(x509) {
const pem = x509.replace(/(?:-----(?:BEGIN|END) CERTIFICATE-----|\s)/g, '');
const raw = (0, base64url_js_1.decodeBase64)(pem);
return (0, format_pem_js_1.default)(spkiFromX509(raw), 'PUBLIC KEY');
}
async function importSPKI(spki, alg, options) {

@@ -91,10 +21,3 @@ if (typeof spki !== 'string' || spki.indexOf('-----BEGIN PUBLIC KEY-----') !== 0) {

}
let spki;
try {
spki = getSPKI(x509);
}
catch (cause) {
throw new TypeError('failed to parse the X.509 certificate', { cause });
}
return (0, asn1_js_1.fromSPKI)(spki, alg, options);
return (0, asn1_js_1.fromX509)(x509, alg, options);
}

@@ -106,3 +29,3 @@ exports.importX509 = importX509;

}
return (0, asn1_js_2.fromPKCS8)(pkcs8, alg, options);
return (0, asn1_js_1.fromPKCS8)(pkcs8, alg, options);
}

@@ -116,5 +39,2 @@ exports.importPKCS8 = importPKCS8;

alg || (alg = jwk.alg);
if (typeof alg !== 'string' || !alg) {
throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
}
switch (jwk.kty) {

@@ -121,0 +41,0 @@ case 'oct':

8

dist/node/cjs/runtime/asn1.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.fromSPKI = exports.fromPKCS8 = exports.toPKCS8 = exports.toSPKI = void 0;
exports.fromX509 = exports.fromSPKI = exports.fromPKCS8 = exports.toPKCS8 = exports.toSPKI = void 0;
const crypto_1 = require("crypto");

@@ -49,1 +49,7 @@ const buffer_1 = require("buffer");

exports.fromSPKI = fromSPKI;
const fromX509 = (pem) => (0, crypto_1.createPublicKey)({
key: pem,
type: 'spki',
format: 'pem',
});
exports.fromX509 = fromX509;

@@ -20,3 +20,3 @@ import type { KeyLike } from '../types';

/**
* (Web Cryptography API specific) The value to use as
* (Only effective in Web Crypto API runtimes) The value to use as
* [SubtleCrypto.generateKey()](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/generateKey)

@@ -31,3 +31,3 @@ * `extractable` argument. Default is false.

*
* Note: Under Web Cryptography API runtime the `privateKey` is generated with `extractable` set to
* Note: Under Web Crypto API runtime the `privateKey` is generated with `extractable` set to
* `false` by default.

@@ -34,0 +34,0 @@ *

import type { KeyLike } from '../types';
export interface GenerateSecretOptions {
/**
* (Web Cryptography API specific) The value to use as
* (Only effective in Web Crypto API runtimes) The value to use as
* [SubtleCrypto.generateKey()](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/generateKey)

@@ -13,4 +13,4 @@ * `extractable` argument. Default is false.

*
* Note: Under Web Cryptography API runtime the secret key is generated with `extractable` set to
* `false` by default.
* Note: Under Web Crypto API runtime the secret key is generated with `extractable` set to `false`
* by default.
*

@@ -17,0 +17,0 @@ * @example Usage

import type { JWK, KeyLike } from '../types';
export interface PEMImportOptions {
/**
* (Web Cryptography API specific) The value to use as
* (Only effective in Web Crypto API runtimes) The value to use as
* [SubtleCrypto.importKey()](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey)

@@ -27,3 +27,4 @@ * `extractable` argument. Default is false.

* @param pem PEM-encoded SPKI string
* @param alg JSON Web Algorithm identifier to be used with the imported key.
* @param alg (Only effective in Web Crypto API runtimes) JSON Web Algorithm identifier to be used
* with the imported key, its presence is only enforced in Web Crypto API runtimes.
*/

@@ -55,3 +56,4 @@ export declare function importSPKI(spki: string, alg: string, options?: PEMImportOptions): Promise<KeyLike>;

* @param pem X.509 certificate string
* @param alg JSON Web Algorithm identifier to be used with the imported key.
* @param alg (Only effective in Web Crypto API runtimes) JSON Web Algorithm identifier to be used
* with the imported key, its presence is only enforced in Web Crypto API runtimes.
*/

@@ -77,3 +79,4 @@ export declare function importX509(x509: string, alg: string, options?: PEMImportOptions): Promise<KeyLike>;

* @param pem PEM-encoded PKCS#8 string
* @param alg JSON Web Algorithm identifier to be used with the imported key.
* @param alg (Only effective in Web Crypto API runtimes) JSON Web Algorithm identifier to be used
* with the imported key, its presence is only enforced in Web Crypto API runtimes.
*/

@@ -113,4 +116,5 @@ export declare function importPKCS8(pkcs8: string, alg: string, options?: PEMImportOptions): Promise<KeyLike>;

* @param jwk JSON Web Key.
* @param alg JSON Web Algorithm identifier to be used with the imported key. Default is the "alg"
* property on the JWK.
* @param alg (Only effective in Web Crypto API runtimes) JSON Web Algorithm identifier to be used
* with the imported key. Default is the "alg" property on the JWK, its presence is only enforced
* in Web Crypto API runtimes.
* @param octAsKeyObject Forces a symmetric key to be imported to a KeyObject or CryptoKey. Default

@@ -117,0 +121,0 @@ * is true unless JWK "ext" (Extractable) is true.

@@ -39,3 +39,3 @@ /**

*
* @example Import a X.509 Certificate
* @example Import SPKI from an X.509 Certificate
*

@@ -42,0 +42,0 @@ * ```js

{
"name": "jose-node-cjs-runtime",
"version": "4.12.0",
"version": "4.12.1",
"homepage": "https://github.com/panva/jose",

@@ -5,0 +5,0 @@ "repository": "panva/jose",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc