Stuart McCulloch | 3fdcd85 | 2011-10-17 10:31:43 +0000 | [diff] [blame] | 1 | package aQute.libg.cryptography; |
| 2 | |
| 3 | import aQute.lib.hex.*; |
| 4 | |
| 5 | public 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 | } |