"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var OperationalBase_exports = {};
__export(OperationalBase_exports, {
  OperationalBase: () => OperationalBase
});
module.exports = __toCommonJS(OperationalBase_exports);
var import_general = require("#general");
var import_Certificate = require("./Certificate.js");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
const logger = import_general.Logger.get("OperationalBaseCertificate");
class OperationalBase extends import_Certificate.Certificate {
  constructor(cert) {
    super(cert);
    this.validateFields();
  }
  /**
   * Verifies general requirements a Matter certificate fields must fulfill.
   * Rules for this are listed in @see {@link MatterSpecification.v12.Core} §6.5.x
   */
  generalVerify() {
    const cert = this.cert;
    if (cert.serialNumber.byteLength > 20)
      throw new import_general.CertificateError(
        `Serial number must not be longer then 20 octets. Current serial number has ${cert.serialNumber.byteLength} octets.`
      );
    if (cert.signatureAlgorithm !== 1) {
      throw new import_general.CertificateError(`Unsupported signature algorithm: ${cert.signatureAlgorithm}`);
    }
    if (cert.publicKeyAlgorithm !== 1) {
      throw new import_general.CertificateError(`Unsupported public key algorithm: ${cert.publicKeyAlgorithm}`);
    }
    if (cert.ellipticCurveIdentifier !== 1) {
      throw new import_general.CertificateError(`Unsupported elliptic curve identifier: ${cert.ellipticCurveIdentifier}`);
    }
    if (Object.keys(cert.subject).length > 5) {
      throw new import_general.CertificateError(`Certificate subject must not contain more than 5 RDNs.`);
    }
    if (Object.keys(cert.issuer).length > 5) {
      throw new import_general.CertificateError(`Certificate issuer must not contain more than 5 RDNs.`);
    }
    if (cert.notBefore * 1e3 > import_general.Time.nowMs) {
      logger.warn(`Certificate notBefore date is in the future: ${cert.notBefore * 1e3} vs ${import_general.Time.nowMs}`);
    }
  }
}
//# sourceMappingURL=OperationalBase.js.map
