"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 Cipher_exports = {};
__export(Cipher_exports, {
  AesCipher: () => AesCipher
});
module.exports = __toCommonJS(Cipher_exports);
var import_Bytes = require("#util/Bytes.js");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
const NONCE_LENGTH = 13;
class AesCipher {
  #crypto;
  #key;
  constructor(crypto, key) {
    this.#crypto = crypto;
    this.#key = key;
  }
  encrypt(data) {
    const nonce = this.#crypto.randomBytes(NONCE_LENGTH);
    const ciphertext = this.#crypto.encrypt(this.#key, data, nonce);
    const result = new Uint8Array(NONCE_LENGTH + ciphertext.byteLength);
    result.set(import_Bytes.Bytes.of(nonce), 0);
    result.set(import_Bytes.Bytes.of(ciphertext), NONCE_LENGTH);
    return result;
  }
  decrypt(data) {
    const bytes = import_Bytes.Bytes.of(data);
    const nonce = bytes.subarray(0, NONCE_LENGTH);
    const ciphertext = bytes.subarray(NONCE_LENGTH);
    return import_Bytes.Bytes.of(this.#crypto.decrypt(this.#key, ciphertext, nonce));
  }
}
//# sourceMappingURL=Cipher.js.map
