Simpllify interface for transport
This commit is contained in:
parent
1cf029df8c
commit
3e09cbd059
@ -4,7 +4,7 @@
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Version>1.0.4</Version>
|
||||
<Version>1.0.5</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
|
||||
@ -13,16 +13,15 @@ public class PCSCAPDUTransport : IAPDUTransport
|
||||
CardReader = cardReader;
|
||||
}
|
||||
|
||||
public Task<NtagResponse> SendAPDU(NTagCommand apdu)
|
||||
public Task<NtagResponse> SendAPDU(byte[] apdu)
|
||||
{
|
||||
return Task.Factory.StartNew(() =>
|
||||
{
|
||||
var bytes = apdu.ToBytes();
|
||||
var resp = ArrayPool<byte>.Shared.Rent(512);
|
||||
try
|
||||
{
|
||||
int received = resp.Length;
|
||||
var sc = CardReader.Transmit(bytes, resp, ref received);
|
||||
var sc = CardReader.Transmit(apdu, resp, ref received);
|
||||
if (sc != SCardError.Success)
|
||||
sc.Throw();
|
||||
var sw1sw2 = (ushort)(resp[received - 2] << 8 | resp[received - 1]);
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<LangVersion>10.0</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<Version>1.0.4</Version>
|
||||
<Version>1.0.5</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
|
||||
@ -4,5 +4,5 @@ namespace BTCPayServer.NTag424;
|
||||
|
||||
public interface IAPDUTransport
|
||||
{
|
||||
Task<NtagResponse> SendAPDU(NTagCommand apdu);
|
||||
Task<NtagResponse> SendAPDU(byte[] apdu);
|
||||
}
|
||||
|
||||
@ -226,7 +226,7 @@ public class Ntag424
|
||||
if (CurrentSession is not null)
|
||||
CurrentSession.Counter++;
|
||||
|
||||
var resp = await Transport.SendAPDU(command);
|
||||
var resp = await Transport.SendAPDU(command.ToBytes());
|
||||
command.ThrowIfUnexpected(resp);
|
||||
if (commandMode is not CommMode.Plain && CurrentSession is not null)
|
||||
{
|
||||
|
||||
@ -76,24 +76,6 @@ public record NTagCommand(string Name, byte CLA, byte INS, byte? P1, byte? P2, b
|
||||
list.Add(P2.Value);
|
||||
if (Data != null)
|
||||
{
|
||||
if (Lc.HasValue)
|
||||
{
|
||||
var realLc = Lc.Value;
|
||||
if (CommMode is NTag424.CommMode.Full)
|
||||
{
|
||||
var encDataSize = realLc - CommandHeaderSize;
|
||||
realLc = (byte)CommandHeaderSize;
|
||||
realLc += (byte)(16 - (encDataSize % 16)); // Padding
|
||||
realLc += 8; // Add mac
|
||||
}
|
||||
if (CommMode is NTag424.CommMode.MAC)
|
||||
{
|
||||
realLc += 8; // Add mac
|
||||
}
|
||||
|
||||
if (realLc != Data.Length)
|
||||
throw new InvalidOperationException("Invalid Data length");
|
||||
}
|
||||
list.Add((byte)(Data.Length));
|
||||
list.AddRange(Data);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user