add -keycard-applet and -cash-applet flags

This commit is contained in:
Andrea Franz 2021-01-08 09:28:51 +01:00
parent 7979faf8de
commit 14a203452b
No known key found for this signature in database
GPG Key ID: 4F0D2F2D9DE7F29D
3 changed files with 21 additions and 16 deletions

View File

@ -1 +1 @@
0.4.0
0.5.0

View File

@ -32,7 +32,7 @@ func NewInstaller(t keycardio.Transmitter) *Installer {
}
// Install installs the applet from the specified capFile.
func (i *Installer) Install(capFile *os.File, overwriteApplet bool, ndefRecordTemplate string) error {
func (i *Installer) Install(capFile *os.File, overwriteApplet bool, installKeycard bool, installCash bool, ndefRecordTemplate string) error {
logger.Info("installation started")
startTime := time.Now()
cmdSet := globalplatform.NewCommandSet(i.c)
@ -71,16 +71,20 @@ func (i *Installer) Install(capFile *os.File, overwriteApplet bool, ndefRecordTe
return err
}
logger.Info("installing Keycard applet")
if err = cmdSet.InstallKeycardApplet(); err != nil {
logger.Error("installing Keycard applet failed", "error", err)
return err
if installKeycard {
logger.Info("installing Keycard applet")
if err = cmdSet.InstallKeycardApplet(); err != nil {
logger.Error("installing Keycard applet failed", "error", err)
return err
}
}
logger.Info("installing Cash applet")
if err = cmdSet.InstallCashApplet(); err != nil {
logger.Error("installing Cash applet failed", "error", err)
return err
if installCash {
logger.Info("installing Cash applet")
if err = cmdSet.InstallCashApplet(); err != nil {
logger.Error("installing Cash applet failed", "error", err)
return err
}
}
if ndefRecordTemplate != "" {

13
main.go
View File

@ -26,10 +26,12 @@ var (
commands map[string]commandFunc
command string
flagCapFile = flag.String("a", "", "applet cap file path")
flagOverwrite = flag.Bool("f", false, "force applet installation if already installed")
flagLogLevel = flag.String("l", "", `Log level, one of: "error", "warn", "info", "debug", and "trace"`)
flagNdefTemplate = flag.String("ndef", "", "Specify a URL to use in the NDEF record. Use the {{.cashAddress}} variable to get the cash address: http://example.com/{{.cashAddress}}.")
flagCapFile = flag.String("a", "", "applet cap file path")
flagKeycardApplet = flag.Bool("keycard-applet", true, "install keycard applet")
flagCashApplet = flag.Bool("cash-applet", true, "install cash applet")
flagOverwrite = flag.Bool("f", false, "force applet installation if already installed")
flagLogLevel = flag.String("l", "", `Log level, one of: "error", "warn", "info", "debug", and "trace"`)
flagNdefTemplate = flag.String("ndef", "", "Specify a URL to use in the NDEF record. Use the {{.cashAddress}} variable to get the cash address: http://example.com/{{.cashAddress}}.")
)
func initLogger() {
@ -236,8 +238,7 @@ func commandInstall(card *scard.Card) error {
defer f.Close()
i := NewInstaller(card)
return i.Install(f, *flagOverwrite, *flagNdefTemplate)
return i.Install(f, *flagOverwrite, *flagKeycardApplet, *flagCashApplet, *flagNdefTemplate)
}
func commandInfo(card *scard.Card) error {