ValidDomain checks whether the specified string is a valid DNS domain.
(domain string)
| 111 | |
| 112 | // ValidDomain checks whether the specified string is a valid DNS domain. |
| 113 | func ValidDomain(domain string) bool { |
| 114 | if len(domain) > 255 || len(domain) == 0 { |
| 115 | return false |
| 116 | } |
| 117 | if strings.HasPrefix(domain, ".") { |
| 118 | return false |
| 119 | } |
| 120 | if strings.Contains(domain, "..") { |
| 121 | return false |
| 122 | } |
| 123 | |
| 124 | // Length checks are to be applied to A-labels form. |
| 125 | // maddy uses U-labels representation across the code (for lookups, etc). |
| 126 | domainASCII, err := idna.ToASCII(domain) |
| 127 | if err != nil { |
| 128 | return false |
| 129 | } |
| 130 | labels := strings.Split(domainASCII, ".") |
| 131 | for _, label := range labels { |
| 132 | if len(label) > 64 { |
| 133 | return false |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | return true |
| 138 | } |
no outgoing calls