Add nsec3 search functions

This commit is contained in:
Miek Gieben 2011-07-29 20:06:52 +02:00
parent e6fb6095c4
commit 7e644793fe
1 changed files with 65 additions and 36 deletions

29
zone.go
View File

@ -172,3 +172,32 @@ func (z Zone) LookupName(qname string, qclass, qtype uint16) (*ZRRset, os.Error)
func intval(c, t uint16) int {
return int(c)*_CLASS + int(t)
}
// Needed for NSEC/NSEC3 in DNSSEC
// SortInsert insert the string s in the already sorted
// vector p. If s is already present it is not inserted again.
func SortInsert(p *vector.StringVector, s string) {
sa := sort.StringArray(*p)
i := sa.Search(s)
if i < p.Len() && p.At(i) == s {
// element already there
return
}
p.Insert(i, s)
}
// Search searches the sorted vector p using binary search. If
// the element s can not be found, the previous element is returned.
func SortSearch(p *vector.StringVector, s string) string {
sa := sort.StringArray(*p)
i := sa.Search(s)
// with zones there must always be one before
if p.At(i) == s {
return s
}
if i > 0 {
i--
}
return p.At(i)
}