| 1 |
package segment |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
"sort" |
| 6 |
|
| 7 |
"github.com/mitch000001/go-hbci/element" |
| 8 |
) |
| 9 |
|
| 10 |
type tanProcess4Constructor func(referencingSegmentID string) *TanRequestSegment |
| 11 |
|
| 12 |
var tanProcess4RequestSegmentConstructors = map[int](tanProcess4Constructor){ |
| 13 |
6: NewTanProcess4RequestSegmentV6, |
| 14 |
1: NewTanProcess4RequestSegmentV1, |
| 15 |
} |
| 16 |
|
| 17 |
func TanProcess4RequestBuilder(versions []int) (tanProcess4Constructor, error) { |
| 18 |
sort.Sort(sort.Reverse(sort.IntSlice(versions))) |
| 19 |
for _, version := range versions { |
| 20 |
builder, ok := tanProcess4RequestSegmentConstructors[version] |
| 21 |
if ok { |
| 22 |
return builder, nil |
| 23 |
} |
| 24 |
} |
| 25 |
return nil, fmt.Errorf("unsupported versions %v", versions) |
| 26 |
} |
| 27 |
|
| 28 |
type TanRequestSegment struct { |
| 29 |
tanRequestSegment |
| 30 |
} |
| 31 |
|
| 32 |
type tanRequestSegment interface { |
| 33 |
ClientSegment |
| 34 |
} |
| 35 |
|
| 36 |
func NewTanRequestProcess2(jobReference string, anotherTANFollows bool) *TanRequestSegmentV1 { |
| 37 |
t := &TanRequestSegmentV1{ |
| 38 |
TANProcess: element.NewAlphaNumeric("2", 1), |
| 39 |
JobReference: element.NewAlphaNumeric(jobReference, 35), |
| 40 |
AnotherTanFollows: element.NewBoolean(anotherTANFollows), |
| 41 |
} |
| 42 |
t.ClientSegment = NewBasicSegment(1, t) |
| 43 |
return t |
| 44 |
} |
| 45 |
|
| 46 |
func NewTanProcess4RequestSegmentV1(referencingSegmentID string) *TanRequestSegment { |
| 47 |
t := &TanRequestSegmentV1{ |
| 48 |
TANProcess: element.NewAlphaNumeric("4", 1), |
| 49 |
} |
| 50 |
t.ClientSegment = NewBasicSegment(1, t) |
| 51 |
|
| 52 |
segment := &TanRequestSegment{ |
| 53 |
tanRequestSegment: t, |
| 54 |
} |
| 55 |
return segment |
| 56 |
} |
| 57 |
|
| 58 |
type TanRequestSegmentV1 struct { |
| 59 |
ClientSegment |
| 60 |
TANProcess *element.AlphaNumericDataElement |
| 61 |
JobHash *element.BinaryDataElement |
| 62 |
JobReference *element.AlphaNumericDataElement |
| 63 |
TanListNumber *element.AlphaNumericDataElement |
| 64 |
AnotherTanFollows *element.BooleanDataElement |
| 65 |
TANInformation *element.AlphaNumericDataElement |
| 66 |
} |
| 67 |
|
| 68 |
func (t *TanRequestSegmentV1) Version() int { return 1 } |
| 69 |
func (t *TanRequestSegmentV1) ID() string { return "HKTAN" } |
| 70 |
func (t *TanRequestSegmentV1) referencedId() string { return "" } |
| 71 |
func (t *TanRequestSegmentV1) sender() string { return senderUser } |
| 72 |
|
| 73 |
func (t *TanRequestSegmentV1) elements() []element.DataElement { |
| 74 |
return []element.DataElement{ |
| 75 |
t.TANProcess, |
| 76 |
t.JobHash, |
| 77 |
t.JobReference, |
| 78 |
t.TanListNumber, |
| 79 |
t.AnotherTanFollows, |
| 80 |
t.TANInformation, |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
func NewTanProcess4RequestSegmentV6(referencingSegmentID string) *TanRequestSegment { |
| 85 |
t := &TanRequestSegmentV6{ |
| 86 |
TANProcess: element.NewAlphaNumeric("4", 1), |
| 87 |
ReferencingSegmentID: element.NewAlphaNumeric(referencingSegmentID, 6), |
| 88 |
} |
| 89 |
t.ClientSegment = NewBasicSegment(1, t) |
| 90 |
|
| 91 |
segment := &TanRequestSegment{ |
| 92 |
tanRequestSegment: t, |
| 93 |
} |
| 94 |
return segment |
| 95 |
} |
| 96 |
|
| 97 |
type TanRequestSegmentV6 struct { |
| 98 |
ClientSegment |
| 99 |
TANProcess *element.AlphaNumericDataElement |
| 100 |
ReferencingSegmentID *element.AlphaNumericDataElement |
| 101 |
JobHash *element.BinaryDataElement |
| 102 |
JobReference *element.AlphaNumericDataElement |
| 103 |
TanListNumber *element.AlphaNumericDataElement |
| 104 |
AnotherTanFollows *element.BooleanDataElement |
| 105 |
TANInformation *element.AlphaNumericDataElement |
| 106 |
} |
| 107 |
|
| 108 |
func (t *TanRequestSegmentV6) Version() int { return 6 } |
| 109 |
func (t *TanRequestSegmentV6) ID() string { return "HKTAN" } |
| 110 |
func (t *TanRequestSegmentV6) referencedId() string { return "" } |
| 111 |
func (t *TanRequestSegmentV6) sender() string { return senderUser } |
| 112 |
|
| 113 |
func (t *TanRequestSegmentV6) elements() []element.DataElement { |
| 114 |
return []element.DataElement{ |
| 115 |
t.TANProcess, |
| 116 |
t.ReferencingSegmentID, |
| 117 |
t.JobHash, |
| 118 |
t.JobReference, |
| 119 |
t.TanListNumber, |
| 120 |
t.AnotherTanFollows, |
| 121 |
t.TANInformation, |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
type TanResponse interface { |
| 126 |
BankSegment |
| 127 |
} |
| 128 |
|
| 129 |
//go:generate go run ../cmd/unmarshaler/unmarshaler_generator.go -segment TanResponseSegment -segment_interface TanResponse -segment_versions="TanResponseSegmentV6:6:Segment" |
| 130 |
|
| 131 |
type TanResponseSegment struct { |
| 132 |
TanResponse |
| 133 |
} |
| 134 |
|
| 135 |
type TanResponseSegmentV6 struct { |
| 136 |
Segment |
| 137 |
TANProcess *element.AlphaNumericDataElement |
| 138 |
JobHash *element.BinaryDataElement |
| 139 |
JobReference *element.AlphaNumericDataElement |
| 140 |
Challenge *element.AlphaNumericDataElement |
| 141 |
ChallengeHHD_UC *element.BinaryDataElement |
| 142 |
TANMediumDescription *element.AlphaNumericDataElement |
| 143 |
ChallengeExpiryDate *element.TanChallengeExpiryDate |
| 144 |
} |
| 145 |
|
| 146 |
func (t *TanResponseSegmentV6) Version() int { return 6 } |
| 147 |
func (t *TanResponseSegmentV6) ID() string { return "HITAN" } |
| 148 |
func (t *TanResponseSegmentV6) referencedId() string { return "" } |
| 149 |
func (t *TanResponseSegmentV6) sender() string { return senderBank } |
| 150 |
|
| 151 |
func (t *TanResponseSegmentV6) elements() []element.DataElement { |
| 152 |
return []element.DataElement{ |
| 153 |
t.TANProcess, |
| 154 |
t.JobHash, |
| 155 |
t.JobReference, |
| 156 |
} |
| 157 |
} |