/// <summary>Initializes a new instance of the <see cref="ResponseApdu" /> class.</summary> /// <param name="response">The response as byte array that shall be parsed.</param> /// <param name="length">The size of the response.</param> /// <param name="isoCase">The ISO case that was used when sending the <see cref="CommandApdu" />.</param> /// <param name="protocol">The communication protocol.</param> /// <param name="copy">If <see langword="true" /> the bytes of the supplied response will be copied.</param> /// <exception cref="ArgumentOutOfRangeException">If <paramref name="length" /> is greater than the <paramref name="response" /> size.</exception> public ResponseApdu(byte[] response, int length, IsoCase isoCase, SCardProtocol protocol, bool copy) { if (length < 0 || (response == null && length > 0) || (response != null && response.Length < length)) { throw new ArgumentOutOfRangeException(nameof(length)); } if (copy) { if (response != null) { FullApdu = new byte[length]; Array.Copy(response, FullApdu, length); } } else { FullApdu = response; } Length = length; Case = isoCase; Protocol = protocol; }
public ResponseApdu(byte[] response, int length, IsoCase isoCase, SCardProtocol proto, bool copy) { if (length < 0 || (response == null && length > 0) || (response.Length < length)) { throw new ArgumentOutOfRangeException("length"); } if (copy) { if (response != null) { this.response = new byte[length]; Array.Copy(response, this.response, length); } } else { this.response = response; } this.length = length; this.isocase = isoCase; this.proto = proto; }
public ResponseApdu(byte[] response, IsoCase isoCase, SCardProtocol proto) { this.response = response; if (response != null) length = response.Length; this.isocase = isoCase; this.proto = proto; }
/// <summary>Initializes a new instance of the <see cref="ResponseApdu" /> class.</summary> /// <param name="response">The response as byte array that shall be parsed.</param> /// <param name="isoCase">The ISO case that was used when sending the <see cref="CommandApdu" />.</param> /// <param name="protocol">The communication protocol.</param> public ResponseApdu(byte[] response, IsoCase isoCase, SCardProtocol protocol) { _response = response; if (response != null) { _length = response.Length; } Case = isoCase; Protocol = protocol; }
public ResponseApdu(byte[] response, IsoCase isoCase, SCardProtocol proto) { this.response = response; if (response != null) { length = response.Length; } this.isocase = isoCase; this.proto = proto; }
public ResponseApdu(byte[] response, int length, IsoCase isoCase, SCardProtocol proto) { if (length < 0 || (response == null && length > 0) || (response.Length < length)) throw new ArgumentOutOfRangeException("length"); this.response = response; this.length = length; this.isocase = isoCase; this.proto = proto; }
/// <summary>Initializes a new instance of the <see cref="ResponseApdu" /> class.</summary> /// <param name="response">The response as byte array that shall be parsed.</param> /// <param name="length">The size of the response.</param> /// <param name="isoCase">The ISO case that was used when sending the <see cref="CommandApdu" />.</param> /// <param name="protocol">The communication protocol.</param> /// <exception cref="ArgumentOutOfRangeException">If <paramref name="length" /> is greater than the <paramref name="response" /> size.</exception> public ResponseApdu(byte[] response, int length, IsoCase isoCase, SCardProtocol protocol) { if (length < 0 || (response == null && length > 0) || (response != null && response.Length < length)) { throw new ArgumentOutOfRangeException("length"); } _response = response; _length = length; Case = isoCase; Protocol = protocol; }
/// <summary>Initializes a new instance of the <see cref="ResponseApdu" /> class.</summary> /// <param name="response">The response as byte array that shall be parsed.</param> /// <param name="isoCase">The ISO case that was used when sending the <see cref="CommandApdu" />.</param> /// <param name="protocol">The communication protocol.</param> public ResponseApdu(byte[] response, IsoCase isoCase, SCardProtocol protocol) { FullApdu = response; if (response != null) { Length = response.Length; } Case = isoCase; Protocol = protocol; }
public ResponseApdu(byte[] response, int length, IsoCase isoCase, SCardProtocol proto) { if (length < 0 || (response == null && length > 0) || (response.Length < length)) { throw new ArgumentOutOfRangeException("length"); } this.response = response; this.length = length; this.isocase = isoCase; this.proto = proto; }
/// <summary>Initializes a new instance of the <see cref="ResponseApdu" /> class.</summary> /// <param name="response">The response as byte array that shall be parsed.</param> /// <param name="length">The size of the response.</param> /// <param name="isoCase">The ISO case that was used when sending the <see cref="CommandApdu" />.</param> /// <param name="protocol">The communication protocol.</param> /// <exception cref="ArgumentOutOfRangeException">If <paramref name="length" /> is greater than the <paramref name="response" /> size.</exception> public ResponseApdu(byte[] response, int length, IsoCase isoCase, SCardProtocol protocol) { if (length < 0 || (response == null && length > 0) || (response != null && response.Length < length)) { throw new ArgumentOutOfRangeException(nameof(length)); } FullApdu = response; Length = length; Case = isoCase; Protocol = protocol; }
/// <summary>Initializes a new instance of the <see cref="ResponseApdu" /> class.</summary> /// <param name="response">The response as byte array that shall be parsed.</param> /// <param name="isoCase">The ISO case that was used when sending the <see cref="CommandApdu" />.</param> /// <param name="protocol">The communication protocol.</param> /// <param name="copy">If <see langword="true" /> the bytes of the supplied response will be copied.</param> public ResponseApdu(byte[] response, IsoCase isoCase, SCardProtocol protocol, bool copy) { Case = isoCase; Protocol = protocol; if (response == null) { return; } if (copy) { Length = response.Length; FullApdu = new byte[Length]; Array.Copy(response, FullApdu, Length); } else { FullApdu = response; Length = response.Length; } }
/// <summary>Initializes a new instance of the <see cref="ResponseApdu" /> class.</summary> /// <param name="response">The response as byte array that shall be parsed.</param> /// <param name="isoCase">The ISO case that was used when sending the <see cref="CommandApdu" />.</param> /// <param name="protocol">The communication protocol.</param> /// <param name="copy">If <see langword="true" /> the bytes of the supplied response will be copied.</param> public ResponseApdu(byte[] response, IsoCase isoCase, SCardProtocol protocol, bool copy) { Case = isoCase; Protocol = protocol; if (response == null) { return; } if (copy) { _length = response.Length; _response = new byte[_length]; Array.Copy(response, _response, _length); } else { _response = response; _length = response.Length; } }
private ResponseApdu _SimpleTransmit(byte[] cmdApdu, int cmdApduLength, IsoCase isoCase, SCardProtocol proto, SCardPCI recvPci, ref byte[] recvBuf, ref int recvBufLength) { SCardError sc = SCardError.UnknownError; bool cmdSent = false; do { // send Command APDU to the card sc = reader.Transmit( SCardPCI.GetPci(reader.ActiveProtocol), cmdApdu, cmdApduLength, recvPci, recvBuf, ref recvBufLength); // Do we need to resend the command APDU? if (sc == SCardError.InsufficientBuffer && recvBuf.Length < recvBufLength) { // The response buffer was too small. recvBuf = new byte[recvBufLength]; // Shall we wait until we re-send we APDU? if (_retransmitWaitTime > 0) { Thread.Sleep(_retransmitWaitTime); } } else { cmdSent = true; } } while (cmdSent == false); if (sc == SCardError.Success) { ResponseApdu respApdu = new ResponseApdu(recvBuf, recvBufLength, isoCase, proto); return(respApdu); } // An error occurred, throw exception.. ThrowExceptionOnSCardError(sc); return(null); }
/// <summary>Initializes a new instance of the <see cref="ResponseApdu" /> class.</summary> /// <param name="response">The response as byte array that shall be parsed.</param> /// <param name="length">The size of the response.</param> /// <param name="isoCase">The ISO case that was used when sending the <see cref="CommandApdu" />.</param> /// <param name="protocol">The communication protocol.</param> /// <param name="copy">If <see langword="true" /> the bytes of the supplied response will be copied.</param> /// <exception cref="ArgumentOutOfRangeException">If <paramref name="length" /> is greater than the <paramref name="response" /> size.</exception> public ResponseApdu(byte[] response, int length, IsoCase isoCase, SCardProtocol protocol, bool copy) { if (length < 0 || (response == null && length > 0) || (response != null && response.Length < length)) { throw new ArgumentOutOfRangeException("length"); } if (copy) { if (response != null) { _response = new byte[length]; Array.Copy(response, _response, length); } } else { _response = response; } _length = length; Case = isoCase; Protocol = protocol; }
public ResponseApdu(byte[] response, IsoCase isoCase, SCardProtocol proto, bool copy) { this.isocase = isoCase; this.proto = proto; if (response == null) return; if (copy) { length = response.Length; this.response = new byte[length]; Array.Copy(response, this.response, length); } else { this.response = response; length = response.Length; } }
public ResponseApdu(byte[] response, IsoCase isoCase, SCardProtocol proto, bool copy) { this.isocase = isoCase; this.proto = proto; if (response == null) { return; } if (copy) { length = response.Length; this.response = new byte[length]; Array.Copy(response, this.response, length); } else { this.response = response; length = response.Length; } }
private static byte[] sendRequest(SCardReader rfidReader, SCardError sc, SCardPCI receivePci, IntPtr sendPci, CommandApdu apdu, ResponseApdu responseApdu, IsoCase isoCase) { sc = rfidReader.BeginTransaction(); if (sc != SCardError.Success) { return(null); } receivePci = new SCardPCI(); sendPci = SCardPCI.GetPci(rfidReader.ActiveProtocol); var receiveBuffer = new byte[256]; var command = apdu.ToArray(); sc = rfidReader.Transmit( sendPci, command, receivePci, ref receiveBuffer); if (sc != SCardError.Success) { return(null); } responseApdu = new ResponseApdu(receiveBuffer, isoCase, rfidReader.ActiveProtocol); if (!responseApdu.HasData) { return(null); } return((byte[])responseApdu.GetData()); }
/// <summary>Initializes a new instance of the <see cref="CommandApdu" /> class.</summary> /// <param name="isoCase">The ISO case to use.</param> /// <param name="protocol">The protocol.</param> public CommandApdu(IsoCase isoCase, SCardProtocol protocol) { Case = isoCase; Protocol = protocol; }
public ResponseApdu(byte[] response, int length, IsoCase isoCase, SCardProtocol proto, bool copy) { if (length < 0 || (response == null && length > 0) || (response.Length < length)) throw new ArgumentOutOfRangeException("length"); if (copy) { if (response != null) { this.response = new byte[length]; Array.Copy(response, this.response, length); } } else { this.response = response; } this.length = length; this.isocase = isoCase; this.proto = proto; }
public CommandApdu ConstructCommandApdu(IsoCase isoCase) { return new CommandApdu(isoCase, ActiveProtocol); }
private ResponseApdu SimpleTransmit(byte[] commandApdu, int commandApduLength, IsoCase isoCase, SCardProtocol protocol, SCardPCI receivePci, ref byte[] receiveBuffer, ref int receiveBufferLength) { SCardError sc; var cmdSent = false; do { // send Command APDU to the card sc = _reader.Transmit( SCardPCI.GetPci(_reader.ActiveProtocol), commandApdu, commandApduLength, receivePci, receiveBuffer, ref receiveBufferLength); // Do we need to resend the command APDU? if (sc == SCardError.InsufficientBuffer && receiveBuffer.Length < receiveBufferLength) { // The response buffer was too small. receiveBuffer = new byte[receiveBufferLength]; // Shall we wait until we re-send we APDU? if (RetransmitWaitTime > 0) { Thread.Sleep(RetransmitWaitTime); } } else { cmdSent = true; } } while (cmdSent == false); if (sc == SCardError.Success) { return new ResponseApdu(receiveBuffer, receiveBufferLength, isoCase, protocol); } // An error occurred, throw exception.. sc.Throw(); return null; }
public CommandApdu(IsoCase isocase, SCardProtocol protocol) { this.isocase = isocase; this.proto = protocol; }
/// <summary>Constructs a command APDU using the active protocol of the reader.</summary> /// <param name="isoCase">The ISO case that shall be used for this command.</param> /// <returns>An empty command APDU.</returns> public virtual CommandApdu ConstructCommandApdu(IsoCase isoCase) { return(new CommandApdu(isoCase, ActiveProtocol)); }
private ResponseApdu _SimpleTransmit(byte[] cmdApdu, int cmdApduLength, IsoCase isoCase, SCardProtocol proto, SCardPCI recvPci, ref byte[] recvBuf, ref int recvBufLength) { SCardError sc = SCardError.UnknownError; bool cmdSent = false; do { // send Command APDU to the card sc = reader.Transmit( SCardPCI.GetPci(reader.ActiveProtocol), cmdApdu, cmdApduLength, recvPci, recvBuf, ref recvBufLength); // Do we need to resend the command APDU? if (sc == SCardError.InsufficientBuffer && recvBuf.Length < recvBufLength) { // The response buffer was too small. recvBuf = new byte[recvBufLength]; // Shall we wait until we re-send we APDU? if (_retransmitWaitTime > 0) Thread.Sleep(_retransmitWaitTime); } else cmdSent = true; } while (cmdSent == false); if (sc == SCardError.Success) { ResponseApdu respApdu = new ResponseApdu(recvBuf, recvBufLength, isoCase, proto); return respApdu; } // An error occurred, throw exception.. ThrowExceptionOnSCardError(sc); return null; }
public CommandApdu InitApdu(bool hasData) { IsoCase commandCase = hasData ? IsoCase.Case4Short : IsoCase.Case2Short; return(new CommandApdu(commandCase, Reader.ActiveProtocol)); }
private ResponseApdu SimpleTransmit(byte[] commandApdu, int commandApduLength, IsoCase isoCase, SCardProtocol protocol, SCardPCI receivePci, byte[] receiveBuffer, int receiveBufferLength) { SCardError sc; do { // send Command APDU to the card sc = Reader.Transmit( SCardPCI.GetPci(Reader.ActiveProtocol), commandApdu, commandApduLength, receivePci, receiveBuffer, ref receiveBufferLength); // Do we need to resend the command APDU? if (sc.HasInsufficientBuffer() && receiveBuffer.Length < receiveBufferLength) { // The response buffer was too small. receiveBuffer = new byte[receiveBufferLength]; // Shall we wait until we re-send we APDU? if (RetransmitWaitTime > 0) { Thread.Sleep(RetransmitWaitTime); } } else { break; } } while (true); if (sc != SCardError.Success) { sc.Throw(); } return(new ResponseApdu(receiveBuffer, receiveBufferLength, isoCase, protocol)); }