-
Notifications
You must be signed in to change notification settings - Fork 20
/
main.go
85 lines (65 loc) · 1.33 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
import (
"fmt"
"github.com/ebfe/scard"
"github.com/greenboxal/emv-kernel/emv"
)
var hints = []emv.ApplicationHint{
emv.ApplicationHint{
Name: []byte{0xA0, 0x00, 0x00, 0x00, 0x04, 0x10, 0x10},
Partial: false,
},
emv.ApplicationHint{
Name: []byte{0xA0, 0x00, 0x00, 0x00, 0x03, 0x10, 0x10},
Partial: false,
},
emv.ApplicationHint{
Name: []byte{0xA0, 0x00, 0x00, 0x00, 0x25, 0x01},
Partial: true,
},
emv.ApplicationHint{
Name: []byte{0xA0, 0x00},
Partial: true,
},
}
func getCard() (*scard.Card, error) {
ctx, err := scard.EstablishContext()
if err != nil {
return nil, err
}
readers, err := ctx.ListReaders()
if err != nil {
return nil, err
}
fmt.Printf("Available readers:\n")
for i, r := range readers {
fmt.Printf("\t%d: %s\n", i, r)
}
selected := -1
if len(readers) == 1 {
selected = 0
}
if selected == -1 {
return nil, err
}
return ctx.Connect(readers[selected], scard.ShareExclusive, scard.ProtocolAny)
}
func main() {
rawCard, err := getCard()
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
card := emv.NewCard(rawCard)
processor := NewTransactionProcessor(card)
err = processor.Initialize()
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
err = processor.Process()
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
}