FileDocCategorySizeDatePackage
ConnectionState.javaAPI DocAndroid 1.5 API5754Wed May 06 22:41:06 BST 2009org.apache.harmony.xnet.provider.jsse

ConnectionState

public abstract class ConnectionState extends Object
This abstract class is a base for Record Protocol operating environmet of different SSL protocol versions.

Fields Summary
protected Cipher
encCipher
The cipher used for encode operations
protected Cipher
decCipher
The cipher used for decode operations
protected boolean
is_block_cipher
The cipher type
protected int
hash_size
The size of MAC used under this connection state
protected final byte[]
write_seq_num
Write sequence number which is incremented after each encrypt call
protected final byte[]
read_seq_num
Read sequence number which is incremented after each decrypt call
protected Logger.Stream
logger
Constructors Summary
Methods Summary
protected byte[]decrypt(byte type, byte[] fragment)
Retrieves the fragment of the Plaintext structure of the specified type from the provided data.

param
type - the ContentType of the data to be decrypted.
param
fragment - the byte array containing the data to be encrypted under the current connection state.

        return decrypt(type, fragment, 0, fragment.length);
    
protected abstract byte[]decrypt(byte type, byte[] fragment, int offset, int len)
Retrieves the fragment of the Plaintext structure of the specified type from the provided data.

param
type - the ContentType of the data to be decrypted.
param
fragment - the byte array containing the data to be encrypted under the current connection state.
param
offset - the offset from which the data begins with.
param
len - the length of the data.

protected byte[]encrypt(byte type, byte[] fragment)
Creates the GenericStreamCipher or GenericBlockCipher data structure for specified data of specified type.

param
type - the ContentType of the provided data
param
fragment - the byte array containing the data to be encrypted under the current connection state.

        return encrypt(type, fragment, 0, fragment.length);
    
protected abstract byte[]encrypt(byte type, byte[] fragment, int offset, int len)
Creates the GenericStreamCipher or GenericBlockCipher data structure for specified data of specified type.

param
type - the ContentType of the provided data
param
fragment - the byte array containing the data to be encrypted under the current connection state.
param
offset - the offset from which the data begins with.
param
len - the length of the data.

protected intgetContentSize(int generic_cipher_size)
Returns the minimal upper bound of the content size enclosed into the Generic[Stream|Generic]Cipher structure of specified size. For stream ciphers the returned value will be exact value.

        //it does not take the padding of block ciphered structures
        //into account (so returned value can be greater than actual)
        return decCipher.getOutputSize(generic_cipher_size)-hash_size;
    
protected intgetFragmentSize(int content_size)
Returns the size of the Generic[Stream|Generic]Cipher structure corresponding to the content data of specified size.

        return encCipher.getOutputSize(content_size+hash_size);
    
protected intgetMinFragmentSize()
Returns the minimal possible size of the Generic[Stream|Generic]Cipher structure under this connection state.


                      
       
        // block ciphers return value with padding included
        return encCipher.getOutputSize(1+hash_size); // 1 byte for data
    
protected static voidincSequenceNumber(byte[] seq_num)
Increments the sequence number.

        int octet = 7;
        while (octet >= 0) {
            seq_num[octet] ++;
            if (seq_num[octet] == 0) {
                // characteristic overflow, so
                // carrying a number in adding
                octet --;
            } else {
                return;
            }
        }
    
protected voidshutdown()
Shutdownes the protocol. It will be impossiblke to use the instance after the calling of this method.

        encCipher = null;
        decCipher = null;
        for (int i=0; i<write_seq_num.length; i++) {
            write_seq_num[i] = 0;
            read_seq_num[i] = 0;
        }