deno_std icon indicating copy to clipboard operation
deno_std copied to clipboard

node/crypto: add `X509Certificate` class from node.js crypto

Open v1rtl opened this issue 4 years ago • 1 comments

Node.js docs reference

https://nodejs.org/api/crypto.html#crypto_class_x509certificate

Implementation interface

import { Buffer } from "../buffer.ts";
import { ERR_INVALID_ARG_TYPE } from "../_errors.ts";
import { isArrayBufferView } from "../_util/_util_types.ts";

export class X509Certificate {
  constructor(buffer: string | Buffer | DataView) {
    if (typeof buffer === "string") buffer = Buffer.from(buffer);
    if (!isArrayBufferView(buffer)) {
      throw new ERR_INVALID_ARG_TYPE("buffer", [
        "string",
        "Buffer",
        "TypedArray",
        "DataView",
      ], buffer);
    }
  }

  get subject(): string {}

  get subjectAltName() {}

  get issuer(): string {}

  get issuerCertificate() {}

  get infoAccess() {}

  get validFrom(): string {}

  get validTo(): string {}

  get fingerprint(): string {}

  get fingerprint256(): string {}

  get keyUsage() {}

  get serialNumber(): string {}

  get raw() {}

  get publicKey() {}

  toString(): string {}

  // There's no standardized JSON encoding for X509 certs so we
  // fallback to providing the PEM encoding as a string.
  toJSON() {
    return this.toString();
  }

  get ca(): boolean {}

  checkHost(name, options) {}

  checkEmail(email, options) {}

  checkIP(ip, options) {}

  checkIssued(otherCert) {}

  checkPrivateKey(pkey) {}

  verify(pkey) {}
}

v1rtl avatar Oct 01 '21 10:10 v1rtl

Hi.

This issue seems closely related to a similar request made in https://github.com/denoland/deno_std/issues/981. So we may want to merge them in a unique thread.

Also, as Deno std lib is closely modeled from Go std lib inspiration, https://pkg.go.dev/encoding/pem may also be worth implementing as dealing with PEM is often related to handling X509 certificates.

Delapouite avatar Jul 28 '22 09:07 Delapouite