Skip to content

Commit

Permalink
Merge pull request #9 from gdbelvin/getpseudorandom
Browse files Browse the repository at this point in the history
Suppport for GetPseudoRandom
  • Loading branch information
hendrikhofstadt authored Mar 17, 2021
2 parents 3727364 + 48c7fef commit fb117c8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea
*.iml
*.iml
*.swp
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Currently the following commands are implemented:
* Echo
* ChangeAuthenticationKey
* Authentication & Session related commands
* GetPseudoRandom

Implementing new commands is really easy. Please consult `commands/constructors.go` and `commands/response.go` for reference.

Expand Down
12 changes: 12 additions & 0 deletions commands/constructors.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,15 @@ func CreateChangeAuthenticationKeyCommand(objID uint16, newPassword string) (*Co

return command, nil
}

func CreateGetPseudoRandomCommand(numBytes uint16) *CommandMessage {
command := &CommandMessage{
CommandType: CommandTypeGetPseudoRandom,
}

payload := bytes.NewBuffer([]byte{})
binary.Write(payload, binary.BigEndian, numBytes)
command.Data = payload.Bytes()

return command
}
6 changes: 6 additions & 0 deletions commands/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ func ParseResponse(data []byte) (Response, error) {
return parseDeriveEcdhResponse(payload)
case CommandTypeChangeAuthenticationKey:
return parseChangeAuthenticationKeyResponse(payload)
case CommandTypeGetPseudoRandom:
return parseGetPseudoRandomResponse(payload), nil
case ErrorResponseCode:
return nil, parseErrorResponse(payload)
default:
Expand Down Expand Up @@ -282,6 +284,10 @@ func parseChangeAuthenticationKeyResponse(payload []byte) (Response, error) {
return &ChangeAuthenticationKeyResponse{ObjectID: objectID}, nil
}

func parseGetPseudoRandomResponse(payload []byte) Response {
return payload
}

// Error formats a card error message into a human readable format
func (e *Error) Error() string {
message := ""
Expand Down

0 comments on commit fb117c8

Please sign in to comment.