/[gzz]/gzz/lava/gzz/storm/BlockId.java
ViewVC logotype

Diff of /gzz/lava/gzz/storm/BlockId.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4 by benja, Sat Nov 16 05:03:40 2002 UTC revision 1.5 by benja, Sat Nov 16 05:59:46 2002 UTC
# Line 58  public final class BlockId { Line 58  public final class BlockId {
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
# Line 78  public final class BlockId { Line 94  public final class BlockId {
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) {

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26