package main import ( "encoding/base64" "net" ) // ValidateIP returns true if the input is a valid IPv4 or IPv6 address. func ValidateIP(ip string) bool { if ip == "" { return false } return net.ParseIP(ip) != nil } // ValidateCIDR returns true if the input is a valid CIDR notation (e.g., 10.0.0.0/24). func ValidateCIDR(cidr string) bool { if cidr == "" { return false } // net.ParseCIDR validates CIDR; it also returns an IP, which we don't need here. if _, _, err := net.ParseCIDR(cidr); err != nil { return false } return true } // ValidatePublicKey returns true if the provided WireGuard public key is a valid base64-encoded 32-byte value. func ValidatePublicKey(key string) bool { if key == "" { return false } // Try to decode as base64 without padding (RawStdEncoding). if b, err := base64.RawStdEncoding.DecodeString(key); err == nil && len(b) == 32 { return true } // Fallback to standard base64 decoding with padding if present. if b, err := base64.StdEncoding.DecodeString(key); err == nil && len(b) == 32 { return true } return false }