Allow output shorter than getDigestSize().

This commit is contained in:
akwizgran
2016-01-01 14:28:38 +00:00
parent 7c1ee9ce87
commit 7e115fed6d

View File

@@ -26,8 +26,9 @@ class DigestWrapper implements MessageDigest {
@Override @Override
public int digest(byte[] buf, int offset, int len) { public int digest(byte[] buf, int offset, int len) {
if (len != digest.getDigestSize()) throw new IllegalArgumentException(); byte[] hash = digest();
digest.doFinal(buf, offset); len = Math.min(len, hash.length);
System.arraycopy(hash, 0, buf, offset, len);
return len; return len;
} }