@ -2265,10 +2265,13 @@ class Cipher : public ObjectWrap {
unsigned char * out = 0 ;
int out_len = 0 , r ;
if ( args [ 0 ] - > IsString ( ) ) {
Local < String > string = args [ 0 ] . As < String > ( ) ;
enum encoding encoding = ParseEncoding ( args [ 1 ] , BINARY ) ;
size_t buflen = StringBytes : : StorageSize ( args [ 0 ] , encoding ) ;
if ( ! StringBytes : : IsValidString ( string , encoding ) )
return ThrowTypeError ( " Bad input string " ) ;
size_t buflen = StringBytes : : StorageSize ( string , encoding ) ;
char * buf = new char [ buflen ] ;
size_t written = StringBytes : : Write ( buf , buflen , args [ 0 ] , encoding ) ;
size_t written = StringBytes : : Write ( buf , buflen , string , encoding ) ;
r = cipher - > CipherUpdate ( buf , written , & out , & out_len ) ;
delete [ ] buf ;
} else {
@ -2574,10 +2577,13 @@ class Decipher : public ObjectWrap {
unsigned char * out = 0 ;
int out_len = 0 , r ;
if ( args [ 0 ] - > IsString ( ) ) {
Local < String > string = args [ 0 ] . As < String > ( ) ;
enum encoding encoding = ParseEncoding ( args [ 1 ] , BINARY ) ;
size_t buflen = StringBytes : : StorageSize ( args [ 0 ] , encoding ) ;
if ( ! StringBytes : : IsValidString ( string , encoding ) )
return ThrowTypeError ( " Bad input string " ) ;
size_t buflen = StringBytes : : StorageSize ( string , encoding ) ;
char * buf = new char [ buflen ] ;
size_t written = StringBytes : : Write ( buf , buflen , args [ 0 ] , encoding ) ;
size_t written = StringBytes : : Write ( buf , buflen , string , encoding ) ;
r = cipher - > DecipherUpdate ( buf , written , & out , & out_len ) ;
delete [ ] buf ;
} else {
@ -2763,10 +2769,13 @@ class Hmac : public ObjectWrap {
// Only copy the data if we have to, because it's a string
int r ;
if ( args [ 0 ] - > IsString ( ) ) {
Local < String > string = args [ 0 ] . As < String > ( ) ;
enum encoding encoding = ParseEncoding ( args [ 1 ] , BINARY ) ;
size_t buflen = StringBytes : : StorageSize ( args [ 0 ] , encoding ) ;
if ( ! StringBytes : : IsValidString ( string , encoding ) )
return ThrowTypeError ( " Bad input string " ) ;
size_t buflen = StringBytes : : StorageSize ( string , encoding ) ;
char * buf = new char [ buflen ] ;
size_t written = StringBytes : : Write ( buf , buflen , args [ 0 ] , encoding ) ;
size_t written = StringBytes : : Write ( buf , buflen , string , encoding ) ;
r = hmac - > HmacUpdate ( buf , written ) ;
delete [ ] buf ;
} else {
@ -2892,10 +2901,13 @@ class Hash : public ObjectWrap {
// Only copy the data if we have to, because it's a string
int r ;
if ( args [ 0 ] - > IsString ( ) ) {
Local < String > string = args [ 0 ] . As < String > ( ) ;
enum encoding encoding = ParseEncoding ( args [ 1 ] , BINARY ) ;
size_t buflen = StringBytes : : StorageSize ( args [ 0 ] , encoding ) ;
if ( ! StringBytes : : IsValidString ( string , encoding ) )
return ThrowTypeError ( " Bad input string " ) ;
size_t buflen = StringBytes : : StorageSize ( string , encoding ) ;
char * buf = new char [ buflen ] ;
size_t written = StringBytes : : Write ( buf , buflen , args [ 0 ] , encoding ) ;
size_t written = StringBytes : : Write ( buf , buflen , string , encoding ) ;
r = hash - > HashUpdate ( buf , written ) ;
delete [ ] buf ;
} else {
@ -3055,10 +3067,13 @@ class Sign : public ObjectWrap {
// Only copy the data if we have to, because it's a string
int r ;
if ( args [ 0 ] - > IsString ( ) ) {
Local < String > string = args [ 0 ] . As < String > ( ) ;
enum encoding encoding = ParseEncoding ( args [ 1 ] , BINARY ) ;
size_t buflen = StringBytes : : StorageSize ( args [ 0 ] , encoding ) ;
if ( ! StringBytes : : IsValidString ( string , encoding ) )
return ThrowTypeError ( " Bad input string " ) ;
size_t buflen = StringBytes : : StorageSize ( string , encoding ) ;
char * buf = new char [ buflen ] ;
size_t written = StringBytes : : Write ( buf , buflen , args [ 0 ] , encoding ) ;
size_t written = StringBytes : : Write ( buf , buflen , string , encoding ) ;
r = sign - > SignUpdate ( buf , written ) ;
delete [ ] buf ;
} else {
@ -3280,10 +3295,13 @@ class Verify : public ObjectWrap {
// Only copy the data if we have to, because it's a string
int r ;
if ( args [ 0 ] - > IsString ( ) ) {
Local < String > string = args [ 0 ] . As < String > ( ) ;
enum encoding encoding = ParseEncoding ( args [ 1 ] , BINARY ) ;
size_t buflen = StringBytes : : StorageSize ( args [ 0 ] , encoding ) ;
if ( ! StringBytes : : IsValidString ( string , encoding ) )
return ThrowTypeError ( " Bad input string " ) ;
size_t buflen = StringBytes : : StorageSize ( string , encoding ) ;
char * buf = new char [ buflen ] ;
size_t written = StringBytes : : Write ( buf , buflen , args [ 0 ] , encoding ) ;
size_t written = StringBytes : : Write ( buf , buflen , string , encoding ) ;
r = verify - > VerifyUpdate ( buf , written ) ;
delete [ ] buf ;
} else {