| 1 |
package element |
| 2 |
|
| 3 |
import ( |
| 4 |
"bytes" |
| 5 |
"fmt" |
| 6 |
|
| 7 |
"github.com/mitch000001/go-hbci/internal" |
| 8 |
) |
| 9 |
|
| 10 |
const defaultPinTan = "\x00\x00\x00\x00\x00\x00\x00\x00" |
| 11 |
|
| 12 |
// NewCustomSignature returns a new CustomSignatureDataElement for the pin and |
| 13 |
// tan |
| 14 |
func NewCustomSignature(pin, tan string) *CustomSignatureDataElement { |
| 15 |
p := &PinTanDataElement{ |
| 16 |
PIN: NewAlphaNumeric(pin, 99), |
| 17 |
} |
| 18 |
if tan != "" { |
| 19 |
p.TAN = NewAlphaNumeric(tan, 99) |
| 20 |
} |
| 21 |
p.DataElement = NewDataElementGroup(pinTanDEG, 2, p) |
| 22 |
cust := &CustomSignatureDataElement{ |
| 23 |
PinTanDataElement: p, |
| 24 |
} |
| 25 |
return cust |
| 26 |
} |
| 27 |
|
| 28 |
// CustomSignatureDataElement represents a custom signature |
| 29 |
type CustomSignatureDataElement struct { |
| 30 |
*PinTanDataElement |
| 31 |
} |
| 32 |
|
| 33 |
// NewPinTan returns a new PinTanDataElement for pin and tan |
| 34 |
func NewPinTan(pin, tan string) *PinTanDataElement { |
| 35 |
p := &PinTanDataElement{ |
| 36 |
PIN: NewAlphaNumeric(pin, 6), |
| 37 |
} |
| 38 |
if tan != "" { |
| 39 |
p.TAN = NewAlphaNumeric(tan, 35) |
| 40 |
} |
| 41 |
p.DataElement = NewDataElementGroup(pinTanDEG, 2, p) |
| 42 |
return p |
| 43 |
} |
| 44 |
|
| 45 |
// PinTanDataElement represents a DataElement which contains the PIN and the |
| 46 |
// TAN for a transaction |
| 47 |
type PinTanDataElement struct { |
| 48 |
DataElement |
| 49 |
PIN *AlphaNumericDataElement |
| 50 |
TAN *AlphaNumericDataElement |
| 51 |
} |
| 52 |
|
| 53 |
// GroupDataElements returns the grouped DataElements |
| 54 |
func (p *PinTanDataElement) GroupDataElements() []DataElement { |
| 55 |
return []DataElement{ |
| 56 |
p.PIN, |
| 57 |
p.TAN, |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
type PinTanSpecificParamDataElement struct { |
| 62 |
DataElement |
| 63 |
PinMinLength *NumberDataElement `yaml:"PinMinLength"` |
| 64 |
PinMaxLength *NumberDataElement `yaml:"PinMaxLength"` |
| 65 |
TanMaxLength *NumberDataElement `yaml:"TanMaxLength"` |
| 66 |
UserIDText *AlphaNumericDataElement `yaml:"UserIDText"` |
| 67 |
CustomerIDText *AlphaNumericDataElement `yaml:"CustomerIDText"` |
| 68 |
JobSpecificPinTanInformation *PinTanBusinessTransactionParameters `yaml:"JobSpecificPinTanInformation"` |
| 69 |
} |
| 70 |
|
| 71 |
// Elements returns the grouped DataElements |
| 72 |
func (p *PinTanSpecificParamDataElement) Elements() []DataElement { |
| 73 |
return []DataElement{ |
| 74 |
p.PinMinLength, |
| 75 |
p.PinMaxLength, |
| 76 |
p.TanMaxLength, |
| 77 |
p.UserIDText, |
| 78 |
p.CustomerIDText, |
| 79 |
p.JobSpecificPinTanInformation, |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
// UnmarshalHBCI unmarshals value |
| 84 |
func (t *PinTanSpecificParamDataElement) UnmarshalHBCI(value []byte) error { |
| 85 |
elements, err := ExtractElements(value) |
| 86 |
if err != nil { |
| 87 |
return err |
| 88 |
} |
| 89 |
iter := internal.NewIterator(elements) |
| 90 |
var PinMinLength NumberDataElement |
| 91 |
if err := PinMinLength.UnmarshalHBCI(iter.Next()); err != nil { |
| 92 |
return fmt.Errorf("error unmarshaling PinMinLength: %v", err) |
| 93 |
} |
| 94 |
t.PinMinLength = &PinMinLength |
| 95 |
var PinMaxLength NumberDataElement |
| 96 |
if err := PinMaxLength.UnmarshalHBCI(iter.Next()); err != nil { |
| 97 |
return fmt.Errorf("error unmarshaling PinMaxLength: %v", err) |
| 98 |
} |
| 99 |
t.PinMaxLength = &PinMaxLength |
| 100 |
var TanMaxLength NumberDataElement |
| 101 |
if err := TanMaxLength.UnmarshalHBCI(iter.Next()); err != nil { |
| 102 |
return fmt.Errorf("error unmarshaling TanMaxLength: %v", err) |
| 103 |
} |
| 104 |
t.TanMaxLength = &TanMaxLength |
| 105 |
var UserIDText AlphaNumericDataElement |
| 106 |
if err := UserIDText.UnmarshalHBCI(iter.Next()); err != nil { |
| 107 |
return fmt.Errorf("error unmarshaling UserIDText: %v", err) |
| 108 |
} |
| 109 |
t.UserIDText = &UserIDText |
| 110 |
var CustomerIDText AlphaNumericDataElement |
| 111 |
if err := CustomerIDText.UnmarshalHBCI(iter.Next()); err != nil { |
| 112 |
return fmt.Errorf("error unmarshaling CustomerIDText: %v", err) |
| 113 |
} |
| 114 |
t.CustomerIDText = &CustomerIDText |
| 115 |
var JobSpecificPinTanInformation PinTanBusinessTransactionParameters |
| 116 |
if err := JobSpecificPinTanInformation.UnmarshalHBCI(bytes.Join(iter.Remainder(), []byte(":"))); err != nil { |
| 117 |
return fmt.Errorf("error unmarshaling JobSpecificPinTanInformation: %v", err) |
| 118 |
} |
| 119 |
t.JobSpecificPinTanInformation = &JobSpecificPinTanInformation |
| 120 |
t.DataElement = NewGroupDataElementGroup(pinTanSpecificParamDataElementDEG, 2, t) |
| 121 |
return nil |
| 122 |
} |