Subject: | garbage appended to digest |
According to the Digest::SHA256 documentation, digest() should return a 32-, 48-, or 64-byte binary string. However, the returned string is always 64 bytes long. The extra bytes appear to be garbage from an uninitialized piece of memory. This is an annoyance. I've attached a simple patch to fix it.
--- sha256.xs.orig 2002-09-22 23:20:01.000000000 -0700
+++ sha256.xs 2002-09-22 23:20:42.000000000 -0700
@@ -106,18 +106,19 @@
case 256:
sha_final(&context->u.sha_info);
sha_unpackdigest(d_str, &context->u.sha_info);
+ ST(0) = sv_2mortal(newSVpv(d_str, 32));
break;
case 384:
sha_final512(&context->u.sha_info512);
sha_unpackdigest384(d_str, &context->u.sha_info512);
+ ST(0) = sv_2mortal(newSVpv(d_str, 48));
break;
default:
sha_final512(&context->u.sha_info512);
sha_unpackdigest512(d_str, &context->u.sha_info512);
+ ST(0) = sv_2mortal(newSVpv(d_str, 64));
break;
}
-
- ST(0) = sv_2mortal(newSVpv(d_str, 64));
}
int