@@ -15,8 +15,6 @@ var utils = require('./utils');
1515var schemes = require ( './schemes/schemes.js' ) ;
1616var formats = require ( './formats/formats.js' ) ;
1717
18- var PUBLIC_RSA_OID = '1.2.840.113549.1.1.1' ;
19-
2018module . exports = ( function ( ) {
2119 var SUPPORTED_HASH_ALGORITHMS = {
2220 node : [ 'md4' , 'md5' , 'ripemd160' , 'sha' , 'sha1' , 'sha224' , 'sha256' , 'sha384' , 'sha512' ] ,
@@ -68,6 +66,7 @@ module.exports = (function () {
6866 } else if ( _ . isObject ( key ) ) {
6967 this . generateKeyPair ( key . b , key . e ) ;
7068 }
69+
7170 this . setOptions ( options ) ;
7271 }
7372
@@ -110,6 +109,7 @@ module.exports = (function () {
110109 if ( ! schemes . isSignature ( this . $options . signingScheme ) ) {
111110 throw Error ( 'Unsupported signing scheme' ) ;
112111 }
112+
113113 if ( this . $options . signingSchemeOptions . hash &&
114114 _ . indexOf ( SUPPORTED_HASH_ALGORITHMS [ this . $options . environment ] , this . $options . signingSchemeOptions . hash ) == - 1 ) {
115115 throw Error ( 'Unsupported hashing algorithm for ' + this . $options . environment + ' environment' ) ;
@@ -172,9 +172,10 @@ module.exports = (function () {
172172 format = EXPORT_FORMAT_ALIASES [ format ] || format ;
173173 }
174174
175- if ( ! formats . detectAndImport ( this . keyPair , keyData , format ) && format === undefined ) {
175+ if ( ! formats . detectAndImport ( this . keyPair , keyData , format ) && format === undefined ) {
176176 throw Error ( "Key format must be specified" ) ;
177177 }
178+
178179 this . $cache = { } ;
179180 } ;
180181
@@ -189,6 +190,7 @@ module.exports = (function () {
189190 if ( ! this . $cache [ format ] ) {
190191 this . $cache [ format ] = formats . detectAndExport ( this . keyPair , format ) ;
191192 }
193+
192194 return this . $cache [ format ] ;
193195 } ;
194196
@@ -247,9 +249,11 @@ module.exports = (function () {
247249 try {
248250 buffer = _ . isString ( buffer ) ? new Buffer ( buffer , 'base64' ) : buffer ;
249251 var res = this . keyPair . decrypt ( buffer ) ;
252+
250253 if ( res === null ) {
251254 throw Error ( 'Key decrypt method returns null.' ) ;
252255 }
256+
253257 return this . $getDecryptedData ( res , encoding ) ;
254258 } catch ( e ) {
255259 throw Error ( 'Error during decryption (probably incorrect key). Original error: ' + e ) ;
@@ -268,11 +272,13 @@ module.exports = (function () {
268272 if ( ! this . isPrivate ( ) ) {
269273 throw Error ( "It is not private key" ) ;
270274 }
275+
271276 var res = this . keyPair . sign ( this . $getDataForEncrypt ( buffer , source_encoding ) ) ;
272277
273278 if ( encoding && encoding != 'buffer' ) {
274279 res = res . toString ( encoding ) ;
275280 }
281+
276282 return res ;
277283 } ;
278284
0 commit comments