blob: f70caa0fd49213c371597535d2af1bf826643cbc [file] [log] [blame]
Stuart McCulloch3fdcd852011-10-17 10:31:43 +00001package aQute.libg.cryptography;
2
3import aQute.lib.hex.*;
4
5public abstract class Digest {
6 final byte[] digest;
7
8 protected Digest(byte[] checksum, int width) {
9 this.digest = checksum;
10 if (digest.length != width)
11 throw new IllegalArgumentException("Invalid width for digest: " + digest.length
12 + " expected " + width);
13 }
14
15
16 public byte[] digest() {
17 return digest;
18 }
19
20 @Override public String toString() {
21 return String.format("%s(d=%s)", getAlgorithm(), Hex.toHexString(digest));
22 }
23
24 public abstract String getAlgorithm();
25}