Commit 6f084e63 authored by Steven Allen's avatar Steven Allen

validate ipv6 zone

parent 1f9df061
package multiaddr
import (
"bytes"
"encoding/base32"
"encoding/binary"
"fmt"
......@@ -47,7 +48,7 @@ func (t twrp) ValidateBytes(b []byte) error {
var TranscoderIP4 = NewTranscoderFromFunctions(ip4StB, ipBtS, nil)
var TranscoderIP6 = NewTranscoderFromFunctions(ip6StB, ipBtS, nil)
var TranscoderIP6Zone = NewTranscoderFromFunctions(ip6zoneStB, ip6zoneBtS, nil)
var TranscoderIP6Zone = NewTranscoderFromFunctions(ip6zoneStB, ip6zoneBtS, ip6zoneVal)
func ip4StB(s string) ([]byte, error) {
i := net.ParseIP(s).To4()
......@@ -71,6 +72,14 @@ func ip6zoneBtS(b []byte) (string, error) {
return string(b), nil
}
func ip6zoneVal(b []byte) error {
// Not supported as this would break multiaddrs.
if bytes.IndexByte(b, '/') >= 0 {
return fmt.Errorf("IPv6 zone ID contains '/': %s", string(b))
}
return nil
}
func ip6StB(s string) ([]byte, error) {
i := net.ParseIP(s).To16()
if i == nil {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment