From bfa73afdb945cd6d399a539c764920c7daa9c3ec Mon Sep 17 00:00:00 2001 From: Gary Belvin Date: Mon, 1 Mar 2021 11:46:54 +0000 Subject: [PATCH 1/3] Add vim swap files to .gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 29b636a..78d47ef 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea -*.iml \ No newline at end of file +*.iml +*.swp From 11bd9d2fb6478bbd5a8073d9b8025a1a0d781996 Mon Sep 17 00:00:00 2001 From: Gary Belvin Date: Mon, 1 Mar 2021 11:47:30 +0000 Subject: [PATCH 2/3] Add GetPseudoRandom Command --- commands/constructors.go | 12 ++++++++++++ commands/response.go | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/commands/constructors.go b/commands/constructors.go index caf69d7..0f3c238 100644 --- a/commands/constructors.go +++ b/commands/constructors.go @@ -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 +} diff --git a/commands/response.go b/commands/response.go index bbdf3d4..276f031 100644 --- a/commands/response.go +++ b/commands/response.go @@ -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 := "" From 48c7fef69dd070ca7b6c94ced64a689432b312dc Mon Sep 17 00:00:00 2001 From: Gary Belvin Date: Fri, 5 Mar 2021 12:05:04 +0000 Subject: [PATCH 3/3] Update readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index f69205c..7dea693 100644 --- a/README.md +++ b/README.md @@ -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.