using System; using System.Text; namespace GemCard { /// /// This class represents the APDU response sent by the card /// public class APDUResponse { /// /// Status bytes length /// public const int SW_LENGTH = 2; /// /// Response data. Contains the data sent by the card minus the 2 status bytes (SW1, SW2) /// null if no data were sent by the card /// public byte[] Data; public byte SW1; public byte SW2; /// /// Status get property /// public ushort Status { get { return (ushort)(((short)SW1 << 8) + (short)SW2); } } /// /// Constructor from the byte data sent back by the card /// /// Buffer of data from the card public APDUResponse(byte[] baData) { if (baData.Length > SW_LENGTH) { Data = new byte[baData.Length - SW_LENGTH]; for (int nI = 0; nI < baData.Length - SW_LENGTH; nI++) { this.Data[nI] = baData[nI]; } } this.SW1 = baData[baData.Length - 2]; this.SW2 = baData[baData.Length - 1]; } /// /// Overrides the ToString method to format to a string the APDUResponse object /// /// public override string ToString() { if (Data != null) { StringBuilder sData = new StringBuilder(Data.Length * 2); for (int nI = 0; nI < Data.Length; nI++) { sData.AppendFormat("{0:X02}", Data[nI]); } return sData.ToString(); } else { return string.Empty; } } } }