6a696e03e7
* migrate to golang.zx2c4.com/wireguard/wgctrl This commit introduces the usage of wgctrl. It avoids the usage of exec calls of the wg command and parsing the output of `wg show`. Signed-off-by: leonnicolas <leonloechner@gmx.de> * vendor wgctrl Signed-off-by: leonnicolas <leonloechner@gmx.de> * apply suggestions from code review Remove wireguard.Enpoint struct and use net.UDPAddr for the resolved endpoint and addr string (dnsanme:port) if a DN was supplied. Signed-off-by: leonnicolas <leonloechner@gmx.de> * pkg/*: use wireguard.Enpoint This commit introduces the wireguard.Enpoint struct. It encapsulates a DN name with port and a net.UPDAddr. The fields are private and only accessible over exported Methods to avoid accidental modification. Also iptables.GetProtocol is improved to avoid ipv4 rules being applied by `ip6tables`. Signed-off-by: leonnicolas <leonloechner@gmx.de> * pkg/wireguard/conf_test.go: add tests for Endpoint Signed-off-by: leonnicolas <leonloechner@gmx.de> * cmd/kg/main.go: validate port range Signed-off-by: leonnicolas <leonloechner@gmx.de> * add suggestions from review Signed-off-by: leonnicolas <leonloechner@gmx.de> * pkg/mesh/mesh.go: use Equal func Implement an Equal func for Enpoint and use it instead of comparing strings. Signed-off-by: leonnicolas <leonloechner@gmx.de> * cmd/kgctl/main.go: check port range Signed-off-by: leonnicolas <leonloechner@gmx.de> * vendor Signed-off-by: leonnicolas <leonloechner@gmx.de>
54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
// Copyright 2021 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package http2
|
|
|
|
import "strings"
|
|
|
|
// The HTTP protocols are defined in terms of ASCII, not Unicode. This file
|
|
// contains helper functions which may use Unicode-aware functions which would
|
|
// otherwise be unsafe and could introduce vulnerabilities if used improperly.
|
|
|
|
// asciiEqualFold is strings.EqualFold, ASCII only. It reports whether s and t
|
|
// are equal, ASCII-case-insensitively.
|
|
func asciiEqualFold(s, t string) bool {
|
|
if len(s) != len(t) {
|
|
return false
|
|
}
|
|
for i := 0; i < len(s); i++ {
|
|
if lower(s[i]) != lower(t[i]) {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
// lower returns the ASCII lowercase version of b.
|
|
func lower(b byte) byte {
|
|
if 'A' <= b && b <= 'Z' {
|
|
return b + ('a' - 'A')
|
|
}
|
|
return b
|
|
}
|
|
|
|
// isASCIIPrint returns whether s is ASCII and printable according to
|
|
// https://tools.ietf.org/html/rfc20#section-4.2.
|
|
func isASCIIPrint(s string) bool {
|
|
for i := 0; i < len(s); i++ {
|
|
if s[i] < ' ' || s[i] > '~' {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
// asciiToLower returns the lowercase version of s if s is ASCII and printable,
|
|
// and whether or not it was.
|
|
func asciiToLower(s string) (lower string, ok bool) {
|
|
if !isASCIIPrint(s) {
|
|
return "", false
|
|
}
|
|
return strings.ToLower(s), true
|
|
}
|