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