"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 asn_exports = {};
__export(asn_exports, {
  FabricId_Matter: () => FabricId_Matter,
  FirmwareSigningId_Matter: () => FirmwareSigningId_Matter,
  IcacId_Matter: () => IcacId_Matter,
  MATTER_OID_TO_FIELD_MAP: () => MATTER_OID_TO_FIELD_MAP,
  NocCat_Matter: () => NocCat_Matter,
  NodeId_Matter: () => NodeId_Matter,
  ProductId_Matter: () => ProductId_Matter,
  RcacId_Matter: () => RcacId_Matter,
  VendorId_Matter: () => VendorId_Matter,
  VvsId_Matter: () => VvsId_Matter,
  jsToMatterDate: () => jsToMatterDate,
  matterToJsDate: () => matterToJsDate
});
module.exports = __toCommonJS(asn_exports);
var import_general = require("@matter/general");
var import_types = require("@matter/types");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
const YEAR_S = 365 * 24 * 60 * 60;
function matterToJsDate(date) {
  return date === 0 ? import_general.X520.NON_WELL_DEFINED_DATE : new Date((date + import_types.MATTER_EPOCH_OFFSET_S) * 1e3);
}
function jsToMatterDate(date, addYears = 0) {
  return date.getTime() === import_general.X520.NON_WELL_DEFINED_DATE.getTime() ? 0 : Math.floor(date.getTime() / 1e3) - import_types.MATTER_EPOCH_OFFSET_S + addYears * YEAR_S;
}
function intTo16Chars(value) {
  const byteArray = new Uint8Array(8);
  const dataView = import_general.Bytes.dataViewOf(byteArray);
  dataView.setBigUint64(0, typeof value === "bigint" ? value : BigInt(value));
  return import_general.Bytes.toHex(byteArray).toUpperCase();
}
function uInt16To8Chars(value) {
  const byteArray = new Uint8Array(4);
  const dataView = import_general.Bytes.dataViewOf(byteArray);
  dataView.setUint32(0, value);
  return import_general.Bytes.toHex(byteArray).toUpperCase();
}
function uInt16To4Chars(value) {
  const byteArray = new Uint8Array(2);
  const dataView = import_general.Bytes.dataViewOf(byteArray);
  dataView.setUint16(0, value);
  return import_general.Bytes.toHex(byteArray).toUpperCase();
}
const MATTER_OID_TO_FIELD_MAP = {};
const GenericMatterObject = (oidBase, id, fieldName, valueConverter) => {
  const oidHex = `${oidBase}${import_general.hex.byte(id)}`;
  if (MATTER_OID_TO_FIELD_MAP[oidHex] !== void 0 && MATTER_OID_TO_FIELD_MAP[oidHex] !== fieldName) {
    throw new import_general.InternalError(
      `ASN.1 Matter OID mapping for ${oidHex} already exists with a different field name: "${MATTER_OID_TO_FIELD_MAP[oidHex]}" vs "${fieldName}"`
    );
  }
  MATTER_OID_TO_FIELD_MAP[oidHex] = fieldName;
  return (value) => [
    (0, import_general.DerObject)(oidHex, {
      value: (valueConverter ?? intTo16Chars)(value)
    })
  ];
};
const GenericMatterOpCertObject = (id, fieldName, valueConverter) => GenericMatterObject("2b0601040182a27c01", id, fieldName, valueConverter);
const GenericMatterAttCertObject = (id, fieldName, valueConverter) => GenericMatterObject("2b0601040182a27c02", id, fieldName, valueConverter);
const NodeId_Matter = GenericMatterOpCertObject(1, "nodeId");
const FirmwareSigningId_Matter = GenericMatterOpCertObject(2, "firmwareSigningId");
const IcacId_Matter = GenericMatterOpCertObject(3, "icacId");
const RcacId_Matter = GenericMatterOpCertObject(4, "rcacId");
const FabricId_Matter = GenericMatterOpCertObject(5, "fabricId");
const NocCat_Matter = GenericMatterOpCertObject(6, "caseAuthenticatedTag", uInt16To8Chars);
const VvsId_Matter = GenericMatterOpCertObject(7, "vvsId");
const VendorId_Matter = GenericMatterAttCertObject(1, "vendorId", uInt16To4Chars);
const ProductId_Matter = GenericMatterAttCertObject(2, "productId", uInt16To4Chars);
//# sourceMappingURL=asn.js.map
