55var BigInteger = require ( '../libs/jsbn' ) ;
66var crypt = require ( 'crypto' ) ;
77var constants = require ( 'constants' ) ;
8+ var _ = require ( 'lodash' ) ;
89var SIGN_INFO_HEAD = {
910 md2 : new Buffer ( '3020300c06082a864886f70d020205000410' , 'hex' ) ,
1011 md5 : new Buffer ( '3020300c06082a864886f70d020505000410' , 'hex' ) ,
@@ -23,6 +24,11 @@ var SIGN_ALG_TO_HASH_ALIASES = {
2324
2425var DEFAULT_HASH_FUNCTION = 'sha256' ;
2526
27+ if ( typeof constants . RSA_NO_PADDING == "undefined" ) {
28+ //patch for node v0.10.x, constants do not defined
29+ constants . RSA_NO_PADDING = 3 ;
30+ }
31+
2632module . exports = {
2733 isEncryption : true ,
2834 isSignature : true
@@ -35,7 +41,7 @@ module.exports.makeScheme = function (key, options) {
3541 }
3642
3743 Scheme . prototype . maxMessageLength = function ( ) {
38- if ( this . options . encryptionSchemeOptions && this . options . encryptionSchemeOptions . padding == constants . RSA_NO_PADDING ) {
44+ if ( ! _ . isEmpty ( this . options . encryptionSchemeOptions ) && this . options . encryptionSchemeOptions . padding == constants . RSA_NO_PADDING ) {
3945 return this . key . encryptedDataLength ;
4046 }
4147 return this . key . encryptedDataLength - 11 ;
@@ -53,8 +59,7 @@ module.exports.makeScheme = function (key, options) {
5359 if ( buffer . length > this . key . maxMessageLength ) {
5460 throw new Error ( "Message too long for RSA (n=" + this . key . encryptedDataLength + ", l=" + buffer . length + ")" ) ;
5561 }
56-
57- if ( this . options . encryptionSchemeOptions && this . options . encryptionSchemeOptions . padding == constants . RSA_NO_PADDING ) {
62+ if ( ! _ . isEmpty ( this . options . encryptionSchemeOptions ) && this . options . encryptionSchemeOptions . padding == constants . RSA_NO_PADDING ) {
5863 //RSA_NO_PADDING treated like JAVA left pad with zero character
5964 filled = new Buffer ( this . key . maxMessageLength - buffer . length ) ;
6065 filled . fill ( 0 ) ;
@@ -97,7 +102,7 @@ module.exports.makeScheme = function (key, options) {
97102 options = options || { } ;
98103 var i = 0 ;
99104
100- if ( this . options . encryptionSchemeOptions && this . options . encryptionSchemeOptions . padding == constants . RSA_NO_PADDING ) {
105+ if ( ! _ . isEmpty ( this . options . encryptionSchemeOptions ) && this . options . encryptionSchemeOptions . padding == constants . RSA_NO_PADDING ) {
101106 //RSA_NO_PADDING treated like JAVA left pad with zero character
102107 var unPad ;
103108 if ( typeof buffer . lastIndexOf == "function" ) { //patch for old node version
0 commit comments