add DeleteObject and DeleteObjectAndRelatedObject to gp cmdSet

This commit is contained in:
Andrea Franz 2019-11-19 10:18:37 +01:00
parent 9d48af884d
commit 96c3596fca
No known key found for this signature in database
GPG Key ID: 4F0D2F2D9DE7F29D
2 changed files with 16 additions and 24 deletions

View File

@ -57,29 +57,19 @@ func (cs *CommandSet) DeleteKeycardInstancesAndPackage() error {
return ErrSecureChannelNotOpen
}
instanceAID, err := identifiers.KeycardInstanceAID(identifiers.KeycardDefaultInstanceIndex)
if err != nil {
return err
}
ids := [][]byte{
identifiers.NdefInstanceAID,
instanceAID,
identifiers.PackageAID,
}
for _, aid := range ids {
err := cs.Delete(aid)
if err != nil {
return err
}
}
return nil
return cs.DeleteObjectAndRelatedObject(identifiers.PackageAID)
}
func (cs *CommandSet) Delete(aid []byte) error {
cmd := NewCommandDelete(aid)
func (cs *CommandSet) DeleteObject(aid []byte) error {
return cs.Delete(aid, P2DeleteObject)
}
func (cs *CommandSet) DeleteObjectAndRelatedObject(aid []byte) error {
return cs.Delete(aid, P2DeleteObjectAndRelatedObject)
}
func (cs *CommandSet) Delete(aid []byte, p2 uint8) error {
cmd := NewCommandDelete(aid, p2)
resp, err := cs.sc.Send(cmd)
return cs.checkOK(resp, err, SwOK, SwReferencedDataNotFound)
}

View File

@ -31,7 +31,9 @@ const (
P1GetStatusExecLoadFiles = 0x20
P1GetStatusExecLoadFilesAndModules = 0x10
P2GetStatusTLVData = 0x02
P2GetStatusTLVData = 0x02
P2DeleteObject = 0x00
P2DeleteObjectAndRelatedObject = 0x80
Sw1ResponseDataIncomplete = 0x61
@ -108,7 +110,7 @@ func NewCommandGetResponse(length uint8) *apdu.Command {
}
// NewCommandDelete returns a Delete command as defined in the globalplatform specifications.
func NewCommandDelete(aid []byte) *apdu.Command {
func NewCommandDelete(aid []byte, p2 uint8) *apdu.Command {
data := []byte{tagDeleteAID, byte(len(aid))}
data = append(data, aid...)
@ -116,7 +118,7 @@ func NewCommandDelete(aid []byte) *apdu.Command {
ClaGp,
InsDelete,
0,
0,
p2,
data,
)
}