gzz.mediaserver
Class IDSpace

java.lang.Object
  |
  +--gzz.mediaserver.IDSpace
All Implemented Interfaces:
java.io.Serializable

public class IDSpace
extends java.lang.Object
implements java.io.Serializable

A space of globally unique IDs. Now with support for two ID schemes: '00' and '01'. Only '01' is generated; '00' can be verified, but is never generated.

'00' IDs contain some additional information, '01' IDs contain only an SHA-1 hash. Note that the data that produces the hash in the '00' IDs contains the part of the ID that is not part of the hash-- i.e., part of the ID is prepended to the actual data before hashing. '01' hashes do not do this. At first glance, this seems to be consistent, since there does not seem to be anything else in the '01' IDs except the hash-- but there is something else: the '01' ID format byte.

Yet, hashing that byte too would make the model harder to understand, and it's not like there would be much point in it. So there's a minor inconsistency between '00' and '01' IDs which you sometimes may have to worry about.

See Also:
Serialized Form

Field Summary
static IDSpace instance
           
 
Constructor Summary
IDSpace()
           
 
Method Summary
 boolean checkData(Mediaserver.Id idid, byte[] data)
          Check that the hash code in the id is correct.
 java.io.InputStream checkInputStream(Mediaserver.Id idid, java.io.InputStream is)
          Return an ID-checking InputStream.
 Mediaserver.Id createID(byte[] data)
          Create a fresh ID for the given block of data.
 void put00Data(java.security.MessageDigest d, byte[] id, byte[] data)
          Put the data in an old-style ('00') id and data arrays into the signature object, preparing to sign the combination.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

instance

public static final IDSpace instance
Constructor Detail

IDSpace

public IDSpace()
Method Detail

put00Data

public void put00Data(java.security.MessageDigest d,
                      byte[] id,
                      byte[] data)
Put the data in an old-style ('00') id and data arrays into the signature object, preparing to sign the combination.

The old format is: 4 bytes = integer length of the id, the id and the data.


createID

public Mediaserver.Id createID(byte[] data)
Create a fresh ID for the given block of data. The ID contains a cryptographic hash of the data to avoid spoofing. (Actually, the current ID format is just an SHA-1 hash with a '01' byte prepended.)

Parameters:
data - The block of data that the new ID will refer to

checkData

public boolean checkData(Mediaserver.Id idid,
                         byte[] data)
Check that the hash code in the id is correct. Note that this function does not detect spoofing by new ids and data blocks, but only the changing of the data block behind a known id.


checkInputStream

public java.io.InputStream checkInputStream(Mediaserver.Id idid,
                                            java.io.InputStream is)
Return an ID-checking InputStream. When closed, the returned InputStream must throw an exception if the ID is not correct.