How to use the @peculiar/asn1-schema.AsnParser.parse function in @peculiar/asn1-schema

To help you get started, we’ve selected a few @peculiar/asn1-schema 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 PeculiarVentures / webcrypto / test / asn.ts View on Github external
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);
      });
github PeculiarVentures / webcrypto / src / mechs / ec / crypto.ts View on Github external
} 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'");
    }
  }
github PeculiarVentures / webcrypto-liner / src / mechs / ec / crypto.ts View on Github external
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);
  }
github PeculiarVentures / webcrypto / src / mechs / ec / private_key.ts View on Github external
public getKey() {
    const keyInfo = AsnParser.parse(this.data, asn.PrivateKeyInfo);
    return AsnParser.parse(keyInfo.privateKey, asn.EcPrivateKey);
  }
github PeculiarVentures / webcrypto / src / mechs / rsa / public_key.ts View on Github external
public getKey() {
    const keyInfo = AsnParser.parse(this.data, asn.PublicKeyInfo);
    return AsnParser.parse(keyInfo.publicKey, asn.RsaPublicKey);
  }
github PeculiarVentures / webcrypto / src / mechs / rsa / public_key.ts View on Github external
public getKey() {
    const keyInfo = AsnParser.parse(this.data, asn.PublicKeyInfo);
    return AsnParser.parse(keyInfo.publicKey, asn.RsaPublicKey);
  }
github PeculiarVentures / webcrypto / src / mechs / rsa / crypto.ts View on Github external
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'");
    }
  }
github PeculiarVentures / webcrypto-liner / src / mechs / rsa / crypto.ts View on Github external
private static importPkcs8Key(data: ArrayBuffer) {
    const keyInfo = AsnParser.parse(data, asn.PrivateKeyInfo);
    const privateKey = AsnParser.parse(keyInfo.privateKey, asn.RsaPrivateKey);
    return this.importAsmKey(privateKey);
  }

@peculiar/asn1-schema

Decorators for ASN.1 schemas building

MIT
Latest version published 3 months ago

Package Health Score

70 / 100
Full package analysis