Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it("parse", () => {
const keyInfo = AsnParser.parse(bytes, asn.PrivateKeyInfo);
const key = AsnParser.parse(keyInfo.privateKey, asn.RsaPrivateKey);
const jsonKey = JsonSerializer.toJSON(key);
assert.deepEqual(jsonKey, json);
});
} else {
const asnKey = JsonParser.fromJSON(keyData, { targetSchema: asn.EcPublicKey });
return this.importPublicKey(asnKey, algorithm, extractable, keyUsages);
}
case "raw": {
const asnKey = new asn.EcPublicKey(keyData as ArrayBuffer);
return this.importPublicKey(asnKey, algorithm, extractable, keyUsages);
}
case "spki": {
const keyInfo = AsnParser.parse(new Uint8Array(keyData as ArrayBuffer), asn.PublicKeyInfo);
const asnKey = new asn.EcPublicKey(keyInfo.publicKey);
return this.importPublicKey(asnKey, algorithm, extractable, keyUsages);
}
case "pkcs8": {
const keyInfo = AsnParser.parse(new Uint8Array(keyData as ArrayBuffer), asn.PrivateKeyInfo);
const asnKey = AsnParser.parse(keyInfo.privateKey, asn.EcPrivateKey);
return this.importPrivateKey(asnKey, algorithm, extractable, keyUsages);
}
default:
throw new core.OperationError("format: Must be 'jwk', 'raw', 'pkcs8' or 'spki'");
}
}
private static importPkcs8Key(data: ArrayBuffer, namedCurve: string) {
const keyInfo = AsnParser.parse(data, asn.PrivateKeyInfo);
const privateKey = AsnParser.parse(keyInfo.privateKey, asn.EcPrivateKey);
return this.importEcKey(privateKey, namedCurve);
}
public getKey() {
const keyInfo = AsnParser.parse(this.data, asn.PrivateKeyInfo);
return AsnParser.parse(keyInfo.privateKey, asn.EcPrivateKey);
}
public getKey() {
const keyInfo = AsnParser.parse(this.data, asn.PublicKeyInfo);
return AsnParser.parse(keyInfo.publicKey, asn.RsaPublicKey);
}
public getKey() {
const keyInfo = AsnParser.parse(this.data, asn.PublicKeyInfo);
return AsnParser.parse(keyInfo.publicKey, asn.RsaPublicKey);
}
const jwk = keyData as JsonWebKey;
if (jwk.d) {
const asnKey = JsonParser.fromJSON(keyData, { targetSchema: asn.RsaPrivateKey });
return this.importPrivateKey(asnKey, algorithm, extractable, keyUsages);
} else {
const asnKey = JsonParser.fromJSON(keyData, { targetSchema: asn.RsaPublicKey });
return this.importPublicKey(asnKey, algorithm, extractable, keyUsages);
}
case "spki": {
const keyInfo = AsnParser.parse(new Uint8Array(keyData as ArrayBuffer), asn.PublicKeyInfo);
const asnKey = AsnParser.parse(keyInfo.publicKey, asn.RsaPublicKey);
return this.importPublicKey(asnKey, algorithm, extractable, keyUsages);
}
case "pkcs8": {
const keyInfo = AsnParser.parse(new Uint8Array(keyData as ArrayBuffer), asn.PrivateKeyInfo);
const asnKey = AsnParser.parse(keyInfo.privateKey, asn.RsaPrivateKey);
return this.importPrivateKey(asnKey, algorithm, extractable, keyUsages);
}
default:
throw new core.OperationError("format: Must be 'jwk', 'pkcs8' or 'spki'");
}
}
private static importPkcs8Key(data: ArrayBuffer) {
const keyInfo = AsnParser.parse(data, asn.PrivateKeyInfo);
const privateKey = AsnParser.parse(keyInfo.privateKey, asn.RsaPrivateKey);
return this.importAsmKey(privateKey);
}