Ejemplo n.º 1
0
func ExampleDecode() {
	ip, expires, salt, err := hostname.Decode("zmvtoaqaaaavkjlja2i2n2ligiol2idykqa3t7vk4vfakdv6.foo.com", "turnip4tea", "foo.com")
	if err != nil {
		log.Fatalf("Not able to decode example hostname")
	}
	fmt.Println(ip)
	fmt.Println(expires)
	fmt.Println(salt)
	// Output:
	// 203.43.55.2
	// 2016-06-06 11:11:27.889 +0000 UTC
	// [166 233]
}
Ejemplo n.º 2
0
func TestEncodeDecode(t *testing.T) {
	ip := net.IPv4(byte(203), byte(43), byte(55), byte(2))
	subdomain := "foo.com"
	expires := time.Now().Add(15 * time.Minute)
	secret := "turnip4tea"
	// encode
	fqdn := hostname.New(ip, subdomain, expires, secret)
	// decode
	ip2, expires2, _, err := hostname.Decode(fqdn, secret, subdomain)
	if err != nil {
		t.Fatalf("Error when creating hostname: %v", err)
	}
	if ip.String() != ip2.String() {
		t.Fatalf("Incorrect IP - got %v but was expecting %v", ip, ip2)
	}
	if expires.Unix() != expires2.Unix() {
		t.Fatalf("Incorrect Expiry - got %v but was expecting %v", expires, expires2)
	}
}
Ejemplo n.º 3
0
func main() {

	arguments, err := docopt.Parse(usage, nil, true, version, false, true)
	if err != nil {
		fmt.Println("Error parsing command line arguments!")
		os.Exit(1)
	}

	fqdn := arguments["FQDN"].(string)
	subdomain := arguments["SUBDOMAIN"].(string)
	secret := arguments["SECRET"].(string)

	ip, expires, salt, err := hostname.Decode(fqdn, secret, subdomain)

	if err != nil {
		log.Fatalf("Error occured: %v", err)
	}

	log.Printf("IP: %v", ip)
	log.Printf("Expires: %v", expires)
	log.Printf("Salt: %#v", salt)
}
Ejemplo n.º 4
0
func TestBadName(t *testing.T) {
	_, _, _, err := hostname.Decode("zmvtoaqaaaavkjlja2i2n2ligiol2idykqa3t7vk4vfakdw6.foo.com", "turnip4tea", "foo.com")
	if err == nil {
		log.Fatalf("Was expecting an error as hash is invalid")
	}
}