File: decoder.go

package info (click to toggle)
golang-github-go-webauthn-webauthn 0.10.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 704 kB
  • sloc: makefile: 2
file content (23 lines) | stat: -rw-r--r-- 340 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package protocol

import (
	"encoding/json"
	"errors"
	"io"
)

func decodeBody(body io.Reader, v any) (err error) {
	decoder := json.NewDecoder(body)

	if err = decoder.Decode(v); err != nil {
		return err
	}

	_, err = decoder.Token()

	if !errors.Is(err, io.EOF) {
		return errors.New("The body contains trailing data")
	}

	return nil
}