ds.ov2.bignat
Class APDU_BigInteger

java.lang.Object
  extended by ds.ov2.bignat.APDU_BigInteger
All Implemented Interfaces:
APDU_Serializable

public class APDU_BigInteger
extends Object
implements APDU_Serializable

Mutable APDU_Serializable wrapper around BigInteger. This is a host data type with Bignat as corresponding card data type. Its purpose is to wrap BigInteger arguments and results for the OV-chip protocol layer. Wrapping and unwrapping will be done by the stub code, which is generated by the idl compiler. Therefore, high-level host code should not at all come in contect with APDU_BigInteger's. High-level host code can use BigIntegers for its computations and can also pass BigIntegers into the method stubs of the OV-chip protocol layer. The OV-chip protocol layer will send the byte array of the BigInteger to the card, where it is copied into a Bignat, silently performing a data type conversion.

The BigIntegers (which are wrapped here) stay immutable. Mutability of this class is achived by changing a reference to a BigInteger.

For a number of general topics see also the package description.

CPP Preprocessing
no cpp preprocessing needed
Execution Environment:
host
Author:
Hendrik Tews
Version:
$Revision: 1.16 $
Last Commit:
$Date: 2009-06-19 20:37:34 $ by $Author: tews $

Field Summary
private  byte[] buf
          Internal (de-)serialization buffer.
 short max_size
          Maximal size of the wrapped BigInteger.
 BigInteger value
          The wrapped BigInteger instance.
 
Constructor Summary
APDU_BigInteger(short max_size)
          Receiving constructor.
APDU_BigInteger(short max_size, BigInteger value)
          Sending constructor.
 
Method Summary
 short from_byte_array(short len, short this_index, byte[] byte_array, short byte_index)
          Deserialization of the wrapped BigInteger for the OV-chip protocol layer.
 boolean is_compatible_with(Object o)
          This is a host data type, nothing is compatible with it.
 short size()
          Size in bytes necessary to send or receive this BigInteger via the OV-chip protocol layer, see APDU_Serializable.size().
 short to_byte_array(short len, short this_index, byte[] byte_array, short byte_index)
          Serialization of the wrapped BigInteger for the OV-chip protocol layer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

value

public BigInteger value
The wrapped BigInteger instance. The value can be directly changed from the outside, as long as the new value fits into max_size bytes. The size check will be done when to_byte_array is called. Because BigInteger are immutable, this reference changes when deserialization (from_byte_array) completes.

The reference might be null before the first deserialization completes. It must not be null when serialization starts.


buf

private byte[] buf
Internal (de-)serialization buffer. Holds the BigInteger to serialize or partial data during deserialization.


max_size

public final short max_size
Maximal size of the wrapped BigInteger. This maximal size must equal the size of the Bignat that this BigInteger is sent to or received from. That is, (de-)serialization uses always byte arrays of size max_size.

Note that valuetoByteArray() might be one byte longer, because toByteArray occacionally adds a leding zero byte.

Constructor Detail

APDU_BigInteger

public APDU_BigInteger(short max_size,
                       BigInteger value)
Sending constructor. Initializes max_size and value.

Parameters:
max_size -
value -

APDU_BigInteger

public APDU_BigInteger(short max_size)
Receiving constructor. Initializes only max_size. value will stay null until set or deserialization completes.

Parameters:
max_size -
Method Detail

size

public short size()
Size in bytes necessary to send or receive this BigInteger via the OV-chip protocol layer, see APDU_Serializable.size().

Specified by:
size in interface APDU_Serializable
Returns:
max_size

is_compatible_with

public boolean is_compatible_with(Object o)
This is a host data type, nothing is compatible with it. See the compatibility check explanations and also APDU_Serializable.is_compatible_with.

Specified by:
is_compatible_with in interface APDU_Serializable
Parameters:
o - actual argument or result
Returns:
always false

to_byte_array

public short to_byte_array(short len,
                           short this_index,
                           byte[] byte_array,
                           short byte_index)
Serialization of the wrapped BigInteger for the OV-chip protocol layer. See APDU_Serializable.to_byte_array. Prior to serialization value must be non-null.

Specified by:
to_byte_array in interface APDU_Serializable
Parameters:
len - available space in byte_array
this_index - number of bytes that have already been written in preceeding calls
byte_array - data array to serialize the state into
byte_index - index in byte_array
Returns:
the number of bytes actually written, except for the case where serialization finished by writing precisely len bytes, in this case len + 1 is returned.

from_byte_array

public short from_byte_array(short len,
                             short this_index,
                             byte[] byte_array,
                             short byte_index)
Deserialization of the wrapped BigInteger for the OV-chip protocol layer. See APDU_Serializable.from_byte_array. After deserialization is completed a new BigInteger is constructed from the received data and assigned to value.

Specified by:
from_byte_array in interface APDU_Serializable
Parameters:
len - available data in byte_array
this_index - number of bytes that have already been read in preceeding calls
byte_array - data array to deserialize from
byte_index - index in byte_array
Returns:
the number of bytes actually read, except for the case where deserialization finished by reading precisely len bytes, in this case len + 1 is returned.