Skip to content
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions iana/iana.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import (
"fmt"

"github.com/weppos/publicsuffix-go/publicsuffix"
zlintutil "github.com/zmap/zlint/v3/util"
)

// ExtractSuffix returns the public suffix of the domain using only the "ICANN"
// section of the Public Suffix List database.
// If the domain does not end in a suffix that belongs to an IANA-assigned
// domain, ExtractSuffix returns an error.
// It confirms with zlint's TLD list.
func ExtractSuffix(name string) (string, error) {
if name == "" {
return "", fmt.Errorf("Blank name argument passed to ExtractSuffix")
Expand All @@ -28,5 +30,9 @@ func ExtractSuffix(name string) (string, error) {
suffix = name
}

if !zlintutil.IsInTLDMap(suffix) {
return "", fmt.Errorf("Domain %s has an unknown TLD %s", name, suffix)
}

return suffix, nil
}