var crypto=require("crypto"),constants=require("constants"),schemes=require("../schemes/schemes.js");module.exports=function(e,n){var t=require("./js.js")(e,n),c=schemes.pkcs1.makeScheme(e,n);return{encrypt:function(e,r){if(r)return t.encrypt(e,r);var p=constants.RSA_PKCS1_OAEP_PADDING;"pkcs1"===n.encryptionScheme&&(p=constants.RSA_PKCS1_PADDING),n.encryptionSchemeOptions&&n.encryptionSchemeOptions.padding&&(p=n.encryptionSchemeOptions.padding);var s=e;return p===constants.RSA_NO_PADDING&&(s=c.pkcs0pad(e)),crypto.publicEncrypt({key:n.rsaUtils.exportKey("public"),padding:p},s)},decrypt:function(e,r){if(r)return t.decrypt(e,r);var p=constants.RSA_PKCS1_OAEP_PADDING;"pkcs1"===n.encryptionScheme&&(p=constants.RSA_PKCS1_PADDING),n.encryptionSchemeOptions&&n.encryptionSchemeOptions.padding&&(p=n.encryptionSchemeOptions.padding);var s=crypto.privateDecrypt({key:n.rsaUtils.exportKey("private"),padding:p},e);return p===constants.RSA_NO_PADDING?c.pkcs0unpad(s):s}}};