Skip to content

Commit 06ba362

Browse files
committed
remove the custom BytesReader in favor of io.ByteReader
io.Reader is not needed anymore there.
1 parent 2c902a5 commit 06ba362

File tree

7 files changed

+18
-17
lines changed

7 files changed

+18
-17
lines changed

constant.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package varsig
33
import (
44
"encoding/binary"
55
"fmt"
6+
"io"
67
)
78

89
// Prefix is the value for the varsig's varuint prefix byte.
@@ -49,7 +50,7 @@ const (
4950

5051
// DecodeHashAlgorithm reads and validates the expected hash algorithm
5152
// (for varsig types include a variable hash algorithm.)
52-
func DecodeHashAlgorithm(r BytesReader) (Hash, error) {
53+
func DecodeHashAlgorithm(r io.ByteReader) (Hash, error) {
5354
u, err := binary.ReadUvarint(r)
5455
if err != nil {
5556
return HashUnspecified, fmt.Errorf("%w: %w", ErrUnknownHash, err)
@@ -114,7 +115,7 @@ const (
114115

115116
// DecodePayloadEncoding reads and validates the expected canonical payload
116117
// encoding of the data to be signed.
117-
func DecodePayloadEncoding(r BytesReader) (PayloadEncoding, error) {
118+
func DecodePayloadEncoding(r io.ByteReader) (PayloadEncoding, error) {
118119
seg1, err := binary.ReadUvarint(r)
119120
if err != nil {
120121
return PayloadEncodingUnspecified, fmt.Errorf("%w: %w", ErrUnsupportedPayloadEncoding, err)

ecdsa.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package varsig
33
import (
44
"encoding/binary"
55
"fmt"
6+
"io"
67
)
78

89
// AlgorithmECDSA is the value specifying an ECDSA signature.
@@ -21,7 +22,7 @@ const (
2122
CurveP521 = ECDSACurve(0x1202)
2223
)
2324

24-
func decodeECDSACurve(r BytesReader) (ECDSACurve, error) {
25+
func decodeECDSACurve(r io.ByteReader) (ECDSACurve, error) {
2526
u, err := binary.ReadUvarint(r)
2627
if err != nil {
2728
return 0, err
@@ -81,7 +82,7 @@ func (v ECDSAVarsig) Encode() []byte {
8182
return buf
8283
}
8384

84-
func decodeECDSA(r BytesReader) (Varsig, error) {
85+
func decodeECDSA(r io.ByteReader) (Varsig, error) {
8586
curve, err := decodeECDSACurve(r)
8687
if err != nil {
8788
return nil, err

eddsa.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package varsig
33
import (
44
"encoding/binary"
55
"fmt"
6+
"io"
67
)
78

89
// AlgorithmEdDSA is the value specifying an EdDSA signature.
@@ -19,7 +20,7 @@ const (
1920
CurveEd448 = EdDSACurve(0x1203)
2021
)
2122

22-
func decodeEdDSACurve(r BytesReader) (EdDSACurve, error) {
23+
func decodeEdDSACurve(r io.ByteReader) (EdDSACurve, error) {
2324
u, err := binary.ReadUvarint(r)
2425
if err != nil {
2526
return 0, err
@@ -79,7 +80,7 @@ func (v EdDSAVarsig) Encode() []byte {
7980
return buf
8081
}
8182

82-
func decodeEdDSA(r BytesReader) (Varsig, error) {
83+
func decodeEdDSA(r io.ByteReader) (Varsig, error) {
8384
curve, err := decodeEdDSACurve(r)
8485
if err != nil {
8586
return nil, err

registry.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"encoding/binary"
66
"fmt"
7+
"io"
78
)
89

910
// Version represents which version of the varsig specification was used
@@ -18,7 +19,7 @@ const (
1819

1920
// DecodeFunc is a function that parses the varsig representing a specific
2021
// signing algorithm.
21-
type DecodeFunc func(BytesReader) (Varsig, error)
22+
type DecodeFunc func(io.ByteReader) (Varsig, error)
2223

2324
// Registry contains a mapping between known signing algorithms and
2425
// functions that can parse varsigs for that signing algorithm.
@@ -53,7 +54,7 @@ func (rs Registry) Decode(data []byte) (Varsig, error) {
5354

5455
// DecodeStream converts data read from the provided io.Reader into one
5556
// of the registered Varsig types.
56-
func (rs Registry) DecodeStream(r BytesReader) (Varsig, error) {
57+
func (rs Registry) DecodeStream(r io.ByteReader) (Varsig, error) {
5758
pre, err := binary.ReadUvarint(r)
5859
if err != nil {
5960
return nil, fmt.Errorf("%w: %w", ErrBadPrefix, err)
@@ -80,7 +81,7 @@ func (rs Registry) DecodeStream(r BytesReader) (Varsig, error) {
8081
return decodeFunc(r)
8182
}
8283

83-
func (rs Registry) decodeVersAndAlgo(r BytesReader) (Version, Algorithm, error) {
84+
func (rs Registry) decodeVersAndAlgo(r io.ByteReader) (Version, Algorithm, error) {
8485
vers, err := binary.ReadUvarint(r)
8586
if err != nil {
8687
return Version(vers), 0, err

registry_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package varsig_test
33
import (
44
"bytes"
55
"encoding/hex"
6+
"io"
67
"testing"
78

89
"github.com/stretchr/testify/assert"
@@ -41,7 +42,7 @@ func testRegistry(t *testing.T) varsig.Registry {
4142
}
4243

4344
func testDecodeFunc(algo varsig.Algorithm) varsig.DecodeFunc {
44-
return func(r varsig.BytesReader) (varsig.Varsig, error) {
45+
return func(r io.ByteReader) (varsig.Varsig, error) {
4546
return &testVarsig{algo: algo}, nil
4647
}
4748
}

rsa.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package varsig
22

33
import (
44
"encoding/binary"
5+
"io"
56
)
67

78
// AlgorithmRSA is the value specifying an RSA signature.
@@ -53,7 +54,7 @@ func (v RSAVarsig) KeyLength() uint64 {
5354
return v.keyLen
5455
}
5556

56-
func decodeRSA(r BytesReader) (Varsig, error) {
57+
func decodeRSA(r io.ByteReader) (Varsig, error) {
5758
hashAlg, err := DecodeHashAlgorithm(r)
5859
if err != nil {
5960
return nil, err

varsig.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func Decode(data []byte) (Varsig, error) {
5050

5151
// DecodeStream converts data read from the provided io.Reader into one
5252
// of the Varsig types provided by the DefaultRegistry.
53-
func DecodeStream(r BytesReader) (Varsig, error) {
53+
func DecodeStream(r io.ByteReader) (Varsig, error) {
5454
return DefaultRegistry().DecodeStream(r)
5555
}
5656

@@ -88,8 +88,3 @@ func (v varsig) encode() []byte {
8888

8989
return buf
9090
}
91-
92-
type BytesReader interface {
93-
io.ByteReader
94-
io.Reader
95-
}

0 commit comments

Comments
 (0)