Ejemplo n.º 1
0
 public async Task<ApduResponse> QueryApduAsync(ApduRequest request,
     CancellationToken cancellationToken = default(CancellationToken))
 {
     var requestBytes = ApduCodec.EncodeRequest(request);
     var responseBytes = await QueryAsync(requestBytes, cancellationToken);
     return ApduCodec.DecodeResponse(responseBytes);
 }
Ejemplo n.º 2
0
        public static ArraySegment<byte> EncodeRequest(ApduRequest request)
        {
            if (request.Data.Count > maxDataSize)
            {
                throw new ArgumentOutOfRangeException(nameof(request), "The data length is too big");
            }

            var buffer = new byte[7 + request.Data.Count];
            using (var stream = new MemoryStream(buffer))
            {
                stream.WriteByte(0);
                stream.WriteByte(request.CommandCode);
                stream.WriteByte(request.Parameter1);
                stream.WriteByte(request.Parameter2);
                Write3ByteIntBigEndian(stream, (uint)request.Data.Count);
                stream.Write(request.Data.Array, request.Data.Offset, request.Data.Count);
            }

            return buffer.Segment();
        }
Ejemplo n.º 3
0
        public static ArraySegment <byte> EncodeRequest(ApduRequest request)
        {
            if (request.Data.Count > maxDataSize)
            {
                throw new ArgumentOutOfRangeException(nameof(request), "The data length is too big");
            }

            var buffer = new byte[7 + request.Data.Count];

            using (var stream = new MemoryStream(buffer))
            {
                stream.WriteByte(0);
                stream.WriteByte(request.CommandCode);
                stream.WriteByte(request.Parameter1);
                stream.WriteByte(request.Parameter2);
                Write3ByteIntBigEndian(stream, (uint)request.Data.Count);
                stream.Write(request.Data.Array, request.Data.Offset, request.Data.Count);
            }

            return(buffer.Segment());
        }