Skip to content

Instantly share code, notes, and snippets.

@wsct
Created February 21, 2021 09:45
Show Gist options
  • Save wsct/6156471e25521244885b0f60d21cb44e to your computer and use it in GitHub Desktop.
Save wsct/6156471e25521244885b0f60d21cb44e to your computer and use it in GitHub Desktop.
/// <summary>
/// Represents a raw command to be sent to the smartcard reader.
/// </summary>
public class RawCommand : ICardCommand
{
private byte[] _rawData;
/// <summary>
/// Accessor to the entire C-APDU in byte array format.
/// </summary>
public byte[] BinaryCommand
{
get => _rawData;
}
/// <summary>
/// Accessor to the entire C-APDU in string format (all bytes are represented in hexa).
/// </summary>
public string StringCommand
{
get => BinaryCommand.ToHexa();
}
/// <summary>
/// Initializes a new instance.
/// </summary>
public RawCommand()
{
_rawData = Array.Empty<byte>();
}
/// <summary>
/// Initializes a new instance for arbitrary C-APDU.
/// </summary>
/// <param name="cAPDU">C-APDU to be assigned as a byte array.</param>
public RawCommand(byte[] cAPDU)
{
Parse(cAPDU);
}
/// <summary>
/// Initializes a new instance for arbitrary C-APDU.
/// </summary>
/// <param name="cAPDU">C-APDU to be assigned as a string container (each byte is coded in hexa).</param>
public RawCommand(string cAPDU)
{
Parse(cAPDU);
}
public override string ToString()
{
return StringCommand;
}
/// <inheritdoc />
public ICardCommand Parse(byte[] cAPDU)
{
_rawData = cAPDU;
return this;
}
/// <inheritdoc />
public ICardCommand Parse(string cAPDU)
{
return Parse(cAPDU.FromHexa());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment