

import { X509Error } from "../X509Error.mjs";

//#region src/modules/x509/utils/nameConversion.ts
const convertName = (name) => {
	if (typeof name === "string") return name;
	let nameBuilder = "";
	if (name.commonName) nameBuilder = nameBuilder.concat(`CN=${name.commonName}, `);
	if (name.countryName) nameBuilder = nameBuilder.concat(`C=${name.countryName}, `);
	if (name.organizationalUnit) nameBuilder = nameBuilder.concat(`OU=${name.organizationalUnit}, `);
	if (name.stateOrProvinceName) nameBuilder = nameBuilder.concat(`S=${name.stateOrProvinceName}, `);
	if (nameBuilder.length === 0) throw new X509Error("Provided name object has no entries. Could not generate an issuer/subject name");
	return nameBuilder.slice(0, nameBuilder.length - 2);
};

//#endregion
export { convertName };
//# sourceMappingURL=nameConversion.mjs.map