public class ClientCHKBlock extends java.lang.Object implements ClientKeyBlock
Constructor and Description |
---|
ClientCHKBlock(byte[] data,
byte[] header,
ClientCHK key2,
boolean verify)
Construct from data retrieved, and a key.
|
ClientCHKBlock(CHKBlock block,
ClientCHK key2)
Construct from a CHKBlock and a key.
|
Modifier and Type | Method and Description |
---|---|
Bucket |
decode(BucketFactory bf,
int maxLength,
boolean dontCompress)
Decode the CHK and recover the original data
|
Bucket |
decodeNew(BucketFactory bf,
int maxLength,
boolean dontCompress)
Decode the CHK and recover the original data
|
Bucket |
decodeNewNoJCA(BucketFactory bf,
int maxLength,
boolean dontCompress)
Decode using Freenet's built in crypto.
|
Bucket |
decodeOld(BucketFactory bf,
int maxLength,
boolean dontCompress)
Decode the CHK and recover the original data
|
static ClientCHKBlock |
encode(Bucket sourceData,
boolean asMetadata,
boolean dontCompress,
short alreadyCompressedCodec,
long sourceLength,
java.lang.String compressorDescriptor,
byte[] cryptoKey,
byte cryptoAlgorithm)
Encode a Bucket of data to a CHKBlock.
|
static ClientCHKBlock |
encode(byte[] sourceData,
boolean asMetadata,
boolean dontCompress,
short alreadyCompressedCodec,
int sourceLength,
java.lang.String compressorDescriptor)
Encode a block of data to a CHKBlock.
|
static ClientCHKBlock |
encodeNew(byte[] data,
int dataLength,
java.security.MessageDigest md256,
byte[] encKey,
boolean asMetadata,
short compressionAlgorithm,
byte cryptoAlgorithm,
int blockHashAlgorithm)
Format:
[0-1]: Block hash algorithm
[2-34]: HMAC (with cryptokey) of data + length bytes.
|
static ClientCHKBlock |
encodeNewNoJCA(byte[] data,
int dataLength,
java.security.MessageDigest md256,
byte[] encKey,
boolean asMetadata,
short compressionAlgorithm,
byte cryptoAlgorithm,
int blockHashAlgorithm)
Encode using Freenet's built in crypto.
|
static ClientCHKBlock |
encodeSplitfileBlock(byte[] data,
byte[] cryptoKey,
byte cryptoAlgorithm)
Encode a splitfile block.
|
boolean |
equals(java.lang.Object o)
This is why ClientKeyBlock isn't instanceof KeyBlock: Two ClientKeyBlock's with the same content
but different keys are not equals(), therefore a ClientKeyBlock and its KeyBlock have to be !equals
too.
|
CHKBlock |
getBlock() |
ClientCHK |
getClientKey() |
Key |
getKey() |
int |
hashCode()
Please be consistent with equals()
|
static ClientCHKBlock |
innerEncode(byte[] data,
int dataLength,
java.security.MessageDigest md256,
byte[] encKey,
boolean asMetadata,
short compressionAlgorithm,
byte cryptoAlgorithm) |
boolean |
isMetadata()
Does the block contain metadata? If not, it contains real data.
|
byte[] |
memoryDecode()
Decode into RAM, if short.
|
java.lang.String |
toString() |
public ClientCHKBlock(byte[] data, byte[] header, ClientCHK key2, boolean verify) throws CHKVerifyException
key2
- The client key.header
- The header.data
- The data.CHKVerifyException
public ClientCHKBlock(CHKBlock block, ClientCHK key2) throws CHKVerifyException
CHKVerifyException
public java.lang.String toString()
toString
in class java.lang.Object
public byte[] memoryDecode() throws CHKDecodeException
memoryDecode
in interface ClientKeyBlock
CHKDecodeException
public Bucket decode(BucketFactory bf, int maxLength, boolean dontCompress) throws CHKDecodeException, java.io.IOException
decode
in interface ClientKeyBlock
bf
- The BucketFactory to use to create the Bucket to return the data in.maxLength
- The maximum size of the returned data in bytes.java.io.IOException
- If there is a bucket error.CHKDecodeException
public Bucket decodeOld(BucketFactory bf, int maxLength, boolean dontCompress) throws CHKDecodeException, java.io.IOException
java.io.IOException
- If there is a bucket error.CHKDecodeException
public Bucket decodeNew(BucketFactory bf, int maxLength, boolean dontCompress) throws CHKDecodeException, java.io.IOException
java.io.IOException
- If there is a bucket error.CHKDecodeException
public Bucket decodeNewNoJCA(BucketFactory bf, int maxLength, boolean dontCompress) throws CHKDecodeException, java.io.IOException
java.io.IOException
- If there is a bucket error.CHKDecodeException
public static ClientCHKBlock encodeSplitfileBlock(byte[] data, byte[] cryptoKey, byte cryptoAlgorithm) throws CHKEncodeException
data
- The data to encode. Must be exactly DATA_LENGTH bytes.cryptoKey
- The encryption key. Can be null in which case this is equivalent to a normal block
encode.CHKEncodeException
public static ClientCHKBlock encode(Bucket sourceData, boolean asMetadata, boolean dontCompress, short alreadyCompressedCodec, long sourceLength, java.lang.String compressorDescriptor, byte[] cryptoKey, byte cryptoAlgorithm) throws CHKEncodeException, java.io.IOException
sourceData
- The bucket of data to encode. Can be arbitrarily large.asMetadata
- Is this a metadata key?dontCompress
- If set, don't even try to compress.alreadyCompressedCodec
- If !dontCompress, and this is >=0, then the
data is already compressed, and this is the algorithm.compressorDescriptor
- cryptoAlgorithm
- cryptoKey
- CHKEncodeException
java.io.IOException
- If there is an error reading from the Bucket.InvalidCompressionCodecException
public static ClientCHKBlock encodeNew(byte[] data, int dataLength, java.security.MessageDigest md256, byte[] encKey, boolean asMetadata, short compressionAlgorithm, byte cryptoAlgorithm, int blockHashAlgorithm) throws CHKEncodeException
data
- Data should already have been padded.dataLength
- Length of original data. Between 0 and 32768.md256
- Convenient reuse of hash object.encKey
- Encryption key for the data, part of the URI.asMetadata
- Whether the final CHK is metadata or not.compressionAlgorithm
- The compression algorithm used.cryptoAlgorithm
- The encryption algorithm used.CHKEncodeException
public static ClientCHKBlock encodeNewNoJCA(byte[] data, int dataLength, java.security.MessageDigest md256, byte[] encKey, boolean asMetadata, short compressionAlgorithm, byte cryptoAlgorithm, int blockHashAlgorithm) throws CHKEncodeException
data
- Data should already have been padded.dataLength
- Length of original data. Between 0 and 32768.md256
- Convenient reuse of hash object.encKey
- Encryption key for the data, part of the URI.asMetadata
- Whether the final CHK is metadata or not.compressionAlgorithm
- The compression algorithm used.cryptoAlgorithm
- The encryption algorithm used.CHKVerifyException
CHKEncodeException
public static ClientCHKBlock innerEncode(byte[] data, int dataLength, java.security.MessageDigest md256, byte[] encKey, boolean asMetadata, short compressionAlgorithm, byte cryptoAlgorithm)
public static ClientCHKBlock encode(byte[] sourceData, boolean asMetadata, boolean dontCompress, short alreadyCompressedCodec, int sourceLength, java.lang.String compressorDescriptor) throws CHKEncodeException, InvalidCompressionCodecException
sourceData
- The data to encode.asMetadata
- Is this a metadata key?dontCompress
- If set, don't even try to compress.alreadyCompressedCodec
- If !dontCompress, and this is >=0, then the
data is already compressed, and this is the algorithm.compressorDescriptor
- Should be null, or list of compressors to try.InvalidCompressionCodecException
CHKEncodeException
public ClientCHK getClientKey()
getClientKey
in interface ClientKeyBlock
public boolean isMetadata()
ClientKeyBlock
isMetadata
in interface ClientKeyBlock
public int hashCode()
ClientKeyBlock
hashCode
in interface ClientKeyBlock
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object o)
ClientKeyBlock
equals
in interface ClientKeyBlock
equals
in class java.lang.Object
public CHKBlock getBlock()
getBlock
in interface ClientKeyBlock
public Key getKey()
getKey
in interface ClientKeyBlock