| 1 |
package element |
| 2 |
|
| 3 |
import "fmt" |
| 4 |
|
| 5 |
// NewPinTanSecurityProfile returns a new SecurityProfile for the provided |
| 6 |
// securityMehtod |
| 7 |
func NewPinTanSecurityProfile(securityMethod int) *SecurityProfileDataElement { |
| 8 |
s := &SecurityProfileDataElement{ |
| 9 |
SecurityMethod: NewAlphaNumeric("PIN", 3), |
| 10 |
SecurityMethodVersion: NewNumber(securityMethod, 3), |
| 11 |
} |
| 12 |
s.DataElement = NewDataElementGroup(securityProfileDEG, 2, s) |
| 13 |
return s |
| 14 |
} |
| 15 |
|
| 16 |
// SecurityProfileDataElement defines a security method for the dialog flow |
| 17 |
type SecurityProfileDataElement struct { |
| 18 |
DataElement |
| 19 |
SecurityMethod *AlphaNumericDataElement |
| 20 |
SecurityMethodVersion *NumberDataElement |
| 21 |
} |
| 22 |
|
| 23 |
// UnmarshalHBCI unmarshals value into the DataElement |
| 24 |
func (s *SecurityProfileDataElement) UnmarshalHBCI(value []byte) error { |
| 25 |
s = &SecurityProfileDataElement{} |
| 26 |
elements, err := ExtractElements(value) |
| 27 |
if err != nil { |
| 28 |
return err |
| 29 |
} |
| 30 |
if len(elements) < 2 { |
| 31 |
return fmt.Errorf("Malformed marshaled value") |
| 32 |
} |
| 33 |
s.DataElement = NewDataElementGroup(securityProfileDEG, 5, s) |
| 34 |
s.SecurityMethod = &AlphaNumericDataElement{} |
| 35 |
err = s.SecurityMethod.UnmarshalHBCI(elements[0]) |
| 36 |
if err != nil { |
| 37 |
return err |
| 38 |
} |
| 39 |
s.SecurityMethodVersion = &NumberDataElement{} |
| 40 |
err = s.SecurityMethodVersion.UnmarshalHBCI(elements[1]) |
| 41 |
return err |
| 42 |
} |
| 43 |
|
| 44 |
// GroupDataElements returns the grouped DataElements |
| 45 |
func (s *SecurityProfileDataElement) GroupDataElements() []DataElement { |
| 46 |
return []DataElement{ |
| 47 |
s.SecurityMethod, |
| 48 |
s.SecurityMethodVersion, |
| 49 |
} |
| 50 |
} |