const require_rolldown_runtime = require('../../../../_virtual/rolldown_runtime.cjs');
const require_utils$1 = require('../utils.cjs');
const require_pkcs1$1 = require('./pkcs1.cjs');
const require_pkcs8$1 = require('./pkcs8.cjs');
const require_components$1 = require('./components.cjs');
const require_openssh$1 = require('./openssh.cjs');

//#region ../../node_modules/node-rsa/src/formats/formats.js
var require_formats = /* @__PURE__ */ require_rolldown_runtime.__commonJS({ "../../node_modules/node-rsa/src/formats/formats.js": ((exports, module) => {
	require_utils$1.default._;
	function formatParse(format) {
		format = format.split("-");
		var keyType = "private";
		var keyOpt = { type: "default" };
		for (var i = 1; i < format.length; i++) if (format[i]) switch (format[i]) {
			case "public":
				keyType = format[i];
				break;
			case "private":
				keyType = format[i];
				break;
			case "pem":
				keyOpt.type = format[i];
				break;
			case "der":
				keyOpt.type = format[i];
				break;
		}
		return {
			scheme: format[0],
			keyType,
			keyOpt
		};
	}
	module.exports = {
		pkcs1: require_pkcs1$1.default,
		pkcs8: require_pkcs8$1.default,
		components: require_components$1.default,
		openssh: require_openssh$1.default,
		isPrivateExport: function(format) {
			return module.exports[format] && typeof module.exports[format].privateExport === "function";
		},
		isPrivateImport: function(format) {
			return module.exports[format] && typeof module.exports[format].privateImport === "function";
		},
		isPublicExport: function(format) {
			return module.exports[format] && typeof module.exports[format].publicExport === "function";
		},
		isPublicImport: function(format) {
			return module.exports[format] && typeof module.exports[format].publicImport === "function";
		},
		detectAndImport: function(key, data, format) {
			if (format === void 0) {
				for (var scheme in module.exports) if (typeof module.exports[scheme].autoImport === "function" && module.exports[scheme].autoImport(key, data)) return true;
			} else if (format) {
				var fmt = formatParse(format);
				if (module.exports[fmt.scheme]) if (fmt.keyType === "private") module.exports[fmt.scheme].privateImport(key, data, fmt.keyOpt);
				else module.exports[fmt.scheme].publicImport(key, data, fmt.keyOpt);
				else throw Error("Unsupported key format");
			}
			return false;
		},
		detectAndExport: function(key, format) {
			if (format) {
				var fmt = formatParse(format);
				if (module.exports[fmt.scheme]) if (fmt.keyType === "private") {
					if (!key.isPrivate()) throw Error("This is not private key");
					return module.exports[fmt.scheme].privateExport(key, fmt.keyOpt);
				} else {
					if (!key.isPublic()) throw Error("This is not public key");
					return module.exports[fmt.scheme].publicExport(key, fmt.keyOpt);
				}
				else throw Error("Unsupported key format");
			}
		}
	};
}) });

//#endregion
Object.defineProperty(exports, 'default', {
  enumerable: true,
  get: function () {
    return require_formats();
  }
});
//# sourceMappingURL=formats.cjs.map