-
Notifications
You must be signed in to change notification settings - Fork 11
/
tan.go
157 lines (133 loc) · 4.56 KB
/
tan.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package segment
import (
"fmt"
"sort"
"github.com/mitch000001/go-hbci/element"
)
type tanProcess4Constructor func(referencingSegmentID string) *TanRequestSegment
var tanProcess4RequestSegmentConstructors = map[int](tanProcess4Constructor){
6: NewTanProcess4RequestSegmentV6,
1: NewTanProcess4RequestSegmentV1,
}
func TanProcess4RequestBuilder(versions []int) (tanProcess4Constructor, error) {
sort.Sort(sort.Reverse(sort.IntSlice(versions)))
for _, version := range versions {
builder, ok := tanProcess4RequestSegmentConstructors[version]
if ok {
return builder, nil
}
}
return nil, fmt.Errorf("unsupported versions %v", versions)
}
type TanRequestSegment struct {
tanRequestSegment
}
type tanRequestSegment interface {
ClientSegment
}
func NewTanRequestProcess2(jobReference string, anotherTANFollows bool) *TanRequestSegmentV1 {
t := &TanRequestSegmentV1{
TANProcess: element.NewAlphaNumeric("2", 1),
JobReference: element.NewAlphaNumeric(jobReference, 35),
AnotherTanFollows: element.NewBoolean(anotherTANFollows),
}
t.ClientSegment = NewBasicSegment(1, t)
return t
}
func NewTanProcess4RequestSegmentV1(referencingSegmentID string) *TanRequestSegment {
t := &TanRequestSegmentV1{
TANProcess: element.NewAlphaNumeric("4", 1),
}
t.ClientSegment = NewBasicSegment(1, t)
segment := &TanRequestSegment{
tanRequestSegment: t,
}
return segment
}
type TanRequestSegmentV1 struct {
ClientSegment
TANProcess *element.AlphaNumericDataElement
JobHash *element.BinaryDataElement
JobReference *element.AlphaNumericDataElement
TanListNumber *element.AlphaNumericDataElement
AnotherTanFollows *element.BooleanDataElement
TANInformation *element.AlphaNumericDataElement
}
func (t *TanRequestSegmentV1) Version() int { return 1 }
func (t *TanRequestSegmentV1) ID() string { return "HKTAN" }
func (t *TanRequestSegmentV1) referencedId() string { return "" }
func (t *TanRequestSegmentV1) sender() string { return senderUser }
func (t *TanRequestSegmentV1) elements() []element.DataElement {
return []element.DataElement{
t.TANProcess,
t.JobHash,
t.JobReference,
t.TanListNumber,
t.AnotherTanFollows,
t.TANInformation,
}
}
func NewTanProcess4RequestSegmentV6(referencingSegmentID string) *TanRequestSegment {
t := &TanRequestSegmentV6{
TANProcess: element.NewAlphaNumeric("4", 1),
ReferencingSegmentID: element.NewAlphaNumeric(referencingSegmentID, 6),
}
t.ClientSegment = NewBasicSegment(1, t)
segment := &TanRequestSegment{
tanRequestSegment: t,
}
return segment
}
type TanRequestSegmentV6 struct {
ClientSegment
TANProcess *element.AlphaNumericDataElement
ReferencingSegmentID *element.AlphaNumericDataElement
JobHash *element.BinaryDataElement
JobReference *element.AlphaNumericDataElement
TanListNumber *element.AlphaNumericDataElement
AnotherTanFollows *element.BooleanDataElement
TANInformation *element.AlphaNumericDataElement
}
func (t *TanRequestSegmentV6) Version() int { return 6 }
func (t *TanRequestSegmentV6) ID() string { return "HKTAN" }
func (t *TanRequestSegmentV6) referencedId() string { return "" }
func (t *TanRequestSegmentV6) sender() string { return senderUser }
func (t *TanRequestSegmentV6) elements() []element.DataElement {
return []element.DataElement{
t.TANProcess,
t.ReferencingSegmentID,
t.JobHash,
t.JobReference,
t.TanListNumber,
t.AnotherTanFollows,
t.TANInformation,
}
}
type TanResponse interface {
BankSegment
}
//go:generate go run ../cmd/unmarshaler/unmarshaler_generator.go -segment TanResponseSegment -segment_interface TanResponse -segment_versions="TanResponseSegmentV6:6:Segment"
type TanResponseSegment struct {
TanResponse
}
type TanResponseSegmentV6 struct {
Segment
TANProcess *element.AlphaNumericDataElement
JobHash *element.BinaryDataElement
JobReference *element.AlphaNumericDataElement
Challenge *element.AlphaNumericDataElement
ChallengeHHD_UC *element.BinaryDataElement
TANMediumDescription *element.AlphaNumericDataElement
ChallengeExpiryDate *element.TanChallengeExpiryDate
}
func (t *TanResponseSegmentV6) Version() int { return 6 }
func (t *TanResponseSegmentV6) ID() string { return "HITAN" }
func (t *TanResponseSegmentV6) referencedId() string { return "" }
func (t *TanResponseSegmentV6) sender() string { return senderBank }
func (t *TanResponseSegmentV6) elements() []element.DataElement {
return []element.DataElement{
t.TANProcess,
t.JobHash,
t.JobReference,
}
}