Merge pull request #9 from gdbelvin/getpseudorandom

Suppport for GetPseudoRandom
This commit is contained in:
Hendrik Hofstadt 2021-03-17 14:23:36 +01:00 committed by GitHub
commit fb117c8072
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 1 deletions

3
.gitignore vendored
View File

@ -1,2 +1,3 @@
.idea
*.iml
*.iml
*.swp

View File

@ -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.

View File

@ -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
}

View File

@ -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:
@ -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 := ""