58 |
|
|
59 |
/** Check that the given data bytes match this id. |
/** Check that the given data bytes match this id. |
60 |
*/ |
*/ |
61 |
public void check(byte[] data) throws IOException { |
public void check(byte[] data) throws WrongIdException { |
62 |
throw new UnsupportedOperationException("XXX!"); |
MessageDigest my_digest = makeMessageDigest(); |
63 |
|
|
64 |
|
if(bytes[0] == 0x00) { |
65 |
|
int l = bytes.length - 20; |
66 |
|
my_digest.update((byte)((l >>> 24) & 0xff)); |
67 |
|
my_digest.update((byte)((l >>> 16) & 0xff)); |
68 |
|
my_digest.update((byte)((l >>> 8) & 0xff)); |
69 |
|
my_digest.update((byte)(l & 0xff)); |
70 |
|
my_digest.update(bytes, 0, l); |
71 |
|
} |
72 |
|
|
73 |
|
my_digest.update(data); |
74 |
|
|
75 |
|
byte[] dig = my_digest.digest(); |
76 |
|
for(int i=0; i<20; i++) |
77 |
|
if(dig[i] != bytes[bytes.length-20+i]) |
78 |
|
throw new WrongIdException("Hash doesn't match"); |
79 |
} |
} |
80 |
|
|
81 |
/** Get an InputStream that checks whether the data read from |
/** Get an InputStream that checks whether the data read from |
94 |
final MessageDigest my_digest = makeMessageDigest(); |
final MessageDigest my_digest = makeMessageDigest(); |
95 |
|
|
96 |
if(bytes[0] == 0x00) { |
if(bytes[0] == 0x00) { |
97 |
my_digest.update(bytes, 1, bytes.length-21); |
int l = bytes.length - 20; |
98 |
|
my_digest.update((byte)((l >>> 24) & 0xff)); |
99 |
|
my_digest.update((byte)((l >>> 16) & 0xff)); |
100 |
|
my_digest.update((byte)((l >>> 8) & 0xff)); |
101 |
|
my_digest.update((byte)(l & 0xff)); |
102 |
|
my_digest.update(bytes, 0, l); |
103 |
} |
} |
104 |
|
|
105 |
InputStream dis = new DigestInputStream(in, my_digest) { |
InputStream dis = new DigestInputStream(in, my_digest) { |