Skip to content

Commit

Permalink
Documented Transcoder functions, and fixed ip6zone string validation
Browse files Browse the repository at this point in the history
Documented Transcoder functions, and fixed ip6zone string validation
  • Loading branch information
Aratz M. Lasa committed Dec 9, 2019
1 parent 64e3415 commit b00b4ac
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions transcoders.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ import (
)

type Transcoder interface {
// Validates and encodes to bytes a multiaddr that's in the string representation.
StringToBytes(string) ([]byte, error)
// Validates and decodes to a string a multiaddr that's in the bytes representation.
BytesToString([]byte) (string, error)
// Validates bytes when parsing a multiaddr that's already in the bytes representation.
ValidateBytes([]byte) error
}

Expand Down Expand Up @@ -63,6 +66,9 @@ func ip6zoneStB(s string) ([]byte, error) {
if len(s) == 0 {
return nil, fmt.Errorf("empty ip6zone")
}
if strings.Contains(s, "/") {
return nil, fmt.Errorf("IPv6 zone ID contains '/': %s", s)
}
return []byte(s), nil
}

Expand Down

0 comments on commit b00b4ac

Please sign in to comment.