Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interpret PIN as decimal string (fixes #6) #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions communication/command/pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package command

import (
"encoding/binary"
"encoding/hex"
"fmt"
"strconv"
)

// InvalidPinError will be returned if the given pin is invalid
Expand All @@ -12,15 +12,15 @@ var InvalidPinError = fmt.Errorf("the given pin is invalid")
type Pin uint16

func NewPin(pin string) (Pin, error) {
if len(pin) != 4 || hex.DecodedLen(len(pin)) != 2 {
if len(pin) != 4 {
return 0, InvalidPinError
}
rawPin, err := hex.DecodeString(pin)
rawPin, err := strconv.ParseUint(pin, 10, 16)
if err != nil {
return 0, InvalidPinError
}

return Pin(binary.BigEndian.Uint16(rawPin)), nil
return Pin(rawPin), nil
}

func (p Pin) AsByte() []byte {
Expand Down