ds.ov2.util
Class Response_apdu

java.lang.Object
  extended by ds.ov2.util.Response_apdu

public class Response_apdu
extends Object

Utility functions around Response APDU's. Takes the status words defined for the OV-chip project (in Response_status) into account.

CPP Preprocessing
no cpp preprocessing needed
Execution Environment:
host
Author:
Hendrik Tews
Version:
$Revision: 1.18 $
Last Commit:
$Date: 2009-05-19 14:59:53 $ by $Author: tews $

Nested Class Summary
 class Response_apdu.Card_response_error
          Exception of response APDU's that indicate an error.
 
Field Summary
private  String name
          A readable representation of the respose status.
private  ResponseAPDU response_apdu
          The raw response APDU.
private  short response_argument
          The response status argument.
private  short response_code
          The pure response status.
 
Constructor Summary
Response_apdu(ResponseAPDU r)
          Constructs a new response APDU from a raw response APDU r.
 
Method Summary
 boolean error()
          Check whether the respose status indicates an error.
 short get_argument()
          Argument of the respose status.
 short get_code()
          Return the pure response status.
 byte[] get_data()
          The data of the response APDU.
 int get_length()
          Length of the data in the response APDU.
 String get_name()
          Return a readable name of the response status.
 short get_status()
          Return the response status as obtained from the card.
 boolean OK()
          Check whether the response status is OK.
 void print(PrintWriter out, boolean with_message)
          Print this response APDU in human readable form to out.
 void throw_if_not_ok(int check_expected_length)
          Check whether the response status is OK and the contained data has the expected length.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

response_apdu

private ResponseAPDU response_apdu
The raw response APDU.


response_code

private short response_code
The pure response status. For status words that carry an argument as for instance ISO7816.SW_BYTES_REMAINING_00 the argument is stripped off.


response_argument

private short response_argument
The response status argument. -1 for status words that do not carry an argument.


name

private String name
A readable representation of the respose status. Lazily computed in get_name().

Constructor Detail

Response_apdu

public Response_apdu(ResponseAPDU r)
Constructs a new response APDU from a raw response APDU r.

Parameters:
r - the raw response APDU
Method Detail

OK

public boolean OK()
Check whether the response status is OK. This is the case if it equals ISO7816.SW_NO_ERROR or 0x9000. Negation of error().

Returns:
true if the response status is ISO7816.SW_NO_ERROR;

error

public boolean error()
Check whether the respose status indicates an error. This is the case if the status is different from ISO7816.SW_NO_ERROR and 0x9000. Negation of OK().

Returns:
true if the response status is different from ISO7816.SW_NO_ERROR

get_code

public short get_code()
Return the pure response status. For status words that carry an argument, as for instance ISO7816.SW_BYTES_REMAINING_00, the argument is stripped off.

Returns:
the response status without potential arguments,

get_status

public short get_status()
Return the response status as obtained from the card.

Returns:
original response status

get_argument

public short get_argument()
Argument of the respose status.

Returns:
the argument of the response status or -1 if the status did not contain an argument.

get_length

public int get_length()
Length of the data in the response APDU.

Returns:
length in bytes

get_data

public byte[] get_data()
The data of the response APDU.

Returns:
the data of this response APDU

get_name

public String get_name()
Return a readable name of the response status. Knows about all response status code in Java Card 2.2.1 and the OV-chip specific ones from Response_status.

Returns:
name of the response status

print

public void print(PrintWriter out,
                  boolean with_message)
Print this response APDU in human readable form to out. Print the data in the body if with_message is true, otherwise the data is supressed.

Parameters:
out - channel to print to, pass null to disable printing
with_message - print payload data if true

throw_if_not_ok

public void throw_if_not_ok(int check_expected_length)
                     throws Response_apdu.Card_response_error
Check whether the response status is OK and the contained data has the expected length. Return normally if the check passes and through an Response_apdu.Card_response_error if the check fails. This method combines precisely all the tests that are needed after the OV-chip protocol layer received a response APDU.

If the status is ok, but the length of the data is wrong, then the status of this response APDU is set to Response_status.OV_WRONG_RESPONSE_LENGTH and an Response_apdu.Card_response_error is thrown.

Parameters:
check_expected_length - the expected length of the data in the response APDU; the special value -1 indicates that 255 and 256 data bytes are ok.
Throws:
Response_apdu.Card_response_error - in case the status is not ok or the length of the response data does not match