var _=require("../utils")._;function formatParse(e){e=e.split("-");for(var r="private",t={type:"default"},o=1;o<e.length;o++)if(e[o])switch(e[o]){case"public":case"private":r=e[o];break;case"pem":case"der":t.type=e[o]}return{scheme:e[0],keyType:r,keyOpt:t}}module.exports={pkcs1:require("./pkcs1"),pkcs8:require("./pkcs8"),components:require("./components"),isPrivateExport:function(e){return module.exports[e]&&"function"==typeof module.exports[e].privateExport},isPrivateImport:function(e){return module.exports[e]&&"function"==typeof module.exports[e].privateImport},isPublicExport:function(e){return module.exports[e]&&"function"==typeof module.exports[e].publicExport},isPublicImport:function(e){return module.exports[e]&&"function"==typeof module.exports[e].publicImport},detectAndImport:function(e,r,t){if(void 0===t){for(var o in module.exports)if("function"==typeof module.exports[o].autoImport&&module.exports[o].autoImport(e,r))return!0}else if(t){var p=formatParse(t);if(!module.exports[p.scheme])throw Error("Unsupported key format");"private"===p.keyType?module.exports[p.scheme].privateImport(e,r,p.keyOpt):module.exports[p.scheme].publicImport(e,r,p.keyOpt)}return!1},detectAndExport:function(e,r){if(r){var t=formatParse(r);if(module.exports[t.scheme]){if("private"===t.keyType){if(!e.isPrivate())throw Error("This is not private key");return module.exports[t.scheme].privateExport(e,t.keyOpt)}if(!e.isPublic())throw Error("This is not public key");return module.exports[t.scheme].publicExport(e,t.keyOpt)}throw Error("Unsupported key format")}}};