diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 10d5d2c0d2..797a39b774 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -3009,9 +3009,6 @@ class Sign : public ObjectWrap { unsigned int md_len; Local outString; - md_len = 8192; // Maximum key size is 8192 bits - md_value = new unsigned char[md_len]; - ASSERT_IS_BUFFER(args[0]); ssize_t len = Buffer::Length(args[0]); @@ -3019,6 +3016,9 @@ class Sign : public ObjectWrap { ssize_t written = DecodeWrite(buf, len, args[0], BUFFER); assert(written == len); + md_len = 8192; // Maximum key size is 8192 bits + md_value = new unsigned char[md_len]; + int r = sign->SignFinal(&md_value, &md_len, buf, len); if (r == 0) { md_value = NULL;