

import { Hasher } from "../../../crypto/hashes/Hasher.mjs";
import { TypedArrayEncoder } from "../../../utils/TypedArrayEncoder.mjs";
import "../../../utils/index.mjs";
import "../../kms/index.mjs";
import { publicJwkToSpki } from "../../../crypto/webcrypto/utils/keyAlgorithmConversion.mjs";
import "../../../crypto/webcrypto/utils/index.mjs";
import { AuthorityKeyIdentifierExtension, BasicConstraintsExtension, CRLDistributionPointsExtension, ExtendedKeyUsageExtension, IssuerAlternativeNameExtension, KeyUsagesExtension, SubjectAlternativeNameExtension, SubjectKeyIdentifierExtension } from "@peculiar/x509";

//#region src/modules/x509/utils/extensions.ts
const createSubjectKeyIdentifierExtension = (options, additionalOptions) => {
	if (!options || !options.include) return;
	const spki = publicJwkToSpki(additionalOptions.publicJwk);
	const hash = Hasher.hash(new Uint8Array(spki.subjectPublicKey), "SHA-1");
	return new SubjectKeyIdentifierExtension(TypedArrayEncoder.toHex(hash));
};
const createKeyUsagesExtension = (options) => {
	if (!options) return;
	return new KeyUsagesExtension(options.usages.reduce((prev, curr) => prev | curr, 0), options.markAsCritical);
};
const createExtendedKeyUsagesExtension = (options) => {
	if (!options) return;
	return new ExtendedKeyUsageExtension(options.usages, options.markAsCritical);
};
const createAuthorityKeyIdentifierExtension = (options, additionalOptions) => {
	if (!options) return;
	const spki = publicJwkToSpki(additionalOptions.publicJwk);
	const hash = Hasher.hash(new Uint8Array(spki.subjectPublicKey), "SHA-1");
	return new AuthorityKeyIdentifierExtension(TypedArrayEncoder.toHex(hash), options.markAsCritical);
};
const createIssuerAlternativeNameExtension = (options) => {
	if (!options) return;
	return new IssuerAlternativeNameExtension(options.name, options.markAsCritical);
};
const createSubjectAlternativeNameExtension = (options) => {
	if (!options) return;
	return new SubjectAlternativeNameExtension(options.name, options.markAsCritical);
};
const createBasicConstraintsExtension = (options) => {
	if (!options) return;
	return new BasicConstraintsExtension(options.ca, options.pathLenConstraint, options.markAsCritical);
};
const createCrlDistributionPointsExtension = (options) => {
	if (!options) return;
	return new CRLDistributionPointsExtension(options.urls, options.markAsCritical);
};

//#endregion
export { createAuthorityKeyIdentifierExtension, createBasicConstraintsExtension, createCrlDistributionPointsExtension, createExtendedKeyUsagesExtension, createIssuerAlternativeNameExtension, createKeyUsagesExtension, createSubjectAlternativeNameExtension, createSubjectKeyIdentifierExtension };
//# sourceMappingURL=extensions.mjs.map