-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathurltosalt.go
More file actions
26 lines (24 loc) · 765 Bytes
/
urltosalt.go
File metadata and controls
26 lines (24 loc) · 765 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package main
import (
"fmt"
"golang.org/x/net/publicsuffix"
neturl "net/url"
)
// Extract the registerable part of the domain from the url and turn it into []byte.
// The result can then be passed to ecbpass.
func UrlToSalt(url string) (salt []byte, err error) {
parsedUrl, err := neturl.Parse(url)
if err != nil {
return nil, fmt.Errorf("Unable to parse url: %v", err.Error())
}
domain := parsedUrl.Hostname()
publicDomain, err := publicsuffix.EffectiveTLDPlusOne(domain)
if err != nil {
return nil, fmt.Errorf("Unable to look up public suffix for domain %v: %v", domain, err.Error())
}
if parsedUrl.Scheme == "https" {
return []byte(publicDomain), nil
} else {
return []byte(fmt.Sprintf("%v://%v", parsedUrl.Scheme, publicDomain)), nil
}
}