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

Return payload even if NOK is set in the frame header. #11

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
Return payload even if NOK is set in the frame header.
This is to let the application decide what to do, if the NOK bit is set
in the header, which tkeyclient cannot know.
  • Loading branch information
dehanj committed Jun 28, 2024
commit f1f3a26efa0a77b72ac47db8fef91bb448a8588f
15 changes: 9 additions & 6 deletions proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ const ErrResponseStatusNotOK = constError("response status not OK")

// ReadFrame reads a response in the framing protocol. The header byte
// is first parsed. If the header has response status Not OK,
// ErrResponseStatusNotOK is returned. Header command length and
// ErrResponseStatusNotOK is returned, along with the payload. Header command length and
// endpoint are then checked against the expectedResp parameter,
// header ID is checked against expectedID. The response code (first
// byte after header) is also checked against the code in
Expand Down Expand Up @@ -239,14 +239,17 @@ func (tk TillitisKey) ReadFrame(expectedResp Cmd, expectedID int) ([]byte, Frami

if hdr.ResponseNotOK {
err = ErrResponseStatusNotOK
// We still need to read out the data/payload, note that
// ReadFull() overrides any timeout set using SetReadTimeout()
rest := make([]byte, hdr.CmdLen.Bytelen())
if _, readErr := io.ReadFull(tk.conn, rest); readErr != nil {
// Read out the payload and return anyway, to let the
// application decide what to do. Note that ReadFull()
// overrides any timeout set using SetReadTimeout()
rx := make([]byte, 1+hdr.CmdLen.Bytelen())
if _, readErr := io.ReadFull(tk.conn, rx[1:]); readErr != nil {
// NOTE: go 1.20 has errors.Join()
err = fmt.Errorf("%w; ReadFull: %w", ErrResponseStatusNotOK, readErr)
return nil, hdr, err
}
return nil, hdr, err
rx[0] = rxHdr[0]
return rx, hdr, err
}

if hdr.CmdLen != expectedResp.CmdLen() {
Expand Down
Loading