Documentation

Need to think about the non-existing root-label and the label
functions.
This commit is contained in:
Miek Gieben 2012-02-12 11:34:28 +01:00
parent ea6da640d7
commit 2cb265697e
3 changed files with 23 additions and 2 deletions

View File

@ -5,6 +5,13 @@
// DNSSEC (DNS Security Extension) adds a layer of security to the DNS. It
// uses public key cryptography to securely sign resource records. The
// public keys are stored in DNSKEY records and the signatures in RRSIG records.
//
// Requesting DNSSEC information for a zone is done by adding the DO (DNSSEC OK) bit
// to an request.
//
// // Set UDP bufsize to 4096 and enable the DO bit
// m := new(dns.Msg)
// m.SetEdns0(4096, true)
package dns
import (

View File

@ -27,6 +27,10 @@ func TestCompareLabels(t *testing.T) {
t.Logf("%s with %s should be %d", s1, s5, 1)
t.Fail()
}
if CompareLabels(".", ".") != 1 {
t.Logf("%s with %s should be %d", ".", ".", 1)
t.Fail()
}
}
func TestSplitLabels(t *testing.T) {
@ -51,4 +55,9 @@ func TestSplitLabels(t *testing.T) {
t.Logf("Labels should be 3, %s\n", s4)
t.Fail()
}
// Should this be 1 or 0...
if len(SplitLabels(".")) != 1 {
t.Logf("Labels should be 1, %s\n", ".")
t.Fail()
}
}

View File

@ -3,6 +3,8 @@ package dns
// Holds a bunch of helper functions for dealing with labels.
// SplitLabels splits a domainname string into its labels.
// www.miek.nl. returns []string{"www", "miek", "nl"}
// . returns []string{"."}
func SplitLabels(s string) []string {
k := 0
labels := make([]string, 0)
@ -30,8 +32,11 @@ func SplitLabels(s string) []string {
// returns how many labels they have in common starting from the right.
// The comparison stops at the first inequality.
//
// www.miek.nl and miek.nl have two labels in common: miek and nl
// www.miek.nl and www.bla.nl have one label in common: nl
// www.miek.nl. and miek.nl. have two labels in common: miek and nl
// www.miek.nl. and www.bla.nl. have one label in common: nl
// Be aware of these corner cases:
// . and . have one label in common
// . and "" (empty) have one label in common
func CompareLabels(s1, s2 string) (n int) {
l1 := SplitLabels(s1)
l2 := SplitLabels(s2)