From 5f23138b4523e9b00d8ea281e2bf98c444539b13 Mon Sep 17 00:00:00 2001 From: Andrea Franz Date: Thu, 14 Mar 2019 14:13:57 +0100 Subject: [PATCH] add delete and load package methods to gp command set --- globalplatform/command_set.go | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/globalplatform/command_set.go b/globalplatform/command_set.go index e7a5d98..e6234bf 100644 --- a/globalplatform/command_set.go +++ b/globalplatform/command_set.go @@ -75,10 +75,9 @@ func (cs *CommandSet) DeleteKeycardInstancesAndPackage() error { identifiers.PackageAID, } - for _, id := range ids { - cmd := NewCommandDelete(id) - resp, err := cs.sc.Send(cmd) - if cs.checkOK(resp, err, SwOK, SwReferencedDataNotFound) != nil { + for _, aid := range ids { + err := cs.Delete(aid) + if err != nil { return err } } @@ -86,12 +85,22 @@ func (cs *CommandSet) DeleteKeycardInstancesAndPackage() error { return nil } +func (cs *CommandSet) Delete(aid []byte) error { + cmd := NewCommandDelete(aid) + resp, err := cs.sc.Send(cmd) + return cs.checkOK(resp, err, SwOK, SwReferencedDataNotFound) +} + func (cs *CommandSet) LoadKeycardPackage(capFile *os.File, callback LoadingCallback) error { + return cs.LoadPackage(capFile, identifiers.PackageAID, callback) +} + +func (cs *CommandSet) LoadPackage(capFile *os.File, pkgAID []byte, callback LoadingCallback) error { if cs.sc == nil { return ErrSecureChannelNotOpen } - preLoad := NewCommandInstallForLoad(identifiers.PackageAID, []byte{}) + preLoad := NewCommandInstallForLoad(pkgAID, []byte{}) resp, err := cs.sc.Send(preLoad) if err = cs.checkOK(resp, err); err != nil { return err @@ -115,7 +124,7 @@ func (cs *CommandSet) LoadKeycardPackage(capFile *os.File, callback LoadingCallb } func (cs *CommandSet) InstallNDEFApplet(ndefRecord []byte) error { - return cs.installForInstall( + return cs.InstallForInstall( identifiers.PackageAID, identifiers.NdefAID, identifiers.NdefInstanceAID, @@ -128,14 +137,14 @@ func (cs *CommandSet) InstallKeycardApplet() error { return err } - return cs.installForInstall( + return cs.InstallForInstall( identifiers.PackageAID, identifiers.KeycardAID, instanceAID, []byte{}) } -func (cs *CommandSet) installForInstall(packageAID, appletAID, instanceAID, params []byte) error { +func (cs *CommandSet) InstallForInstall(packageAID, appletAID, instanceAID, params []byte) error { cmd := NewCommandInstallForInstall(packageAID, appletAID, instanceAID, params) resp, err := cs.sc.Send(cmd) return cs.checkOK(resp, err)