public override CommandApdu AsApdu() { var apdu = CommandApdu.Case2S(ApduClass.GlobalPlatform, ApduInstruction.Delete, this.P1, this.P2, 0x00); var data = new List <byte>(); switch (this.scope) { case DeleteCommandScope.CardContent: data.AddTLV(TLV.Build((byte)Tag.ExecutableLoadFileOrApplicationAID, this.application)); if (this.token.Any()) { data.AddTLV(TLV.Build((byte)Tag.DeleteToken, this.token)); } break; case DeleteCommandScope.Key: if (this.keyIdentifier == 0 && this.keyVersionNumber == 0) { throw new InvalidOperationException("A key identifier or key version number must be specified."); } if (this.keyIdentifier > 0) { data.AddTLV(TLV.Build((byte)Tag.KeyIdentifier, this.keyIdentifier)); } if (this.keyVersionNumber > 0) { data.AddTLV(TLV.Build((byte)Tag.KeyVersionNumber, this.keyVersionNumber)); } break; } apdu.CommandData = data.ToArray(); return(apdu); }