func TestPrivateByteSlice(t *testing.T) { dns.PrivateHandle("ISBN", TypeISBN, NewISBN) defer dns.PrivateHandleRemove(TypeISBN) rr, err := dns.NewRR(testrecord) if err != nil { t.Fatal(err) } buf := make([]byte, 100) off, err := dns.PackRR(rr, buf, 0, nil, false) if err != nil { t.Errorf("got error packing ISBN: %v", err) } custrr := rr.(*dns.PrivateRR) if ln := custrr.Data.Len() + len(custrr.Header().Name) + 11; ln != off { t.Errorf("offset is not matching to length of Private RR: %d!=%d", off, ln) } rr1, off1, err := dns.UnpackRR(buf[:off], 0) if err != nil { t.Errorf("got error unpacking ISBN: %v", err) } if off1 != off { t.Errorf("Offset after unpacking differs: %d != %d", off1, off) } if rr1.String() != testrecord { t.Errorf("Record string representation did not match original %#v != %#v", rr1.String(), testrecord) } else { t.Log(rr1.String()) } }
// Key serializes the RRset and return a signature cache key. func key(rrs []dns.RR) string { h := fnv.New64() buf := make([]byte, 256) for _, r := range rrs { off, err := dns.PackRR(r, buf, 0, nil, false) if err == nil { h.Write(buf[:off]) } } i := h.Sum64() return strconv.FormatUint(i, 10) }
func marshalCanonicalCAASet(set []*dns.CAA) ([]byte, error) { var err error offset, size := 0, 0 sortedSet := caaSet(set) sort.Sort(sortedSet) for _, rr := range sortedSet { size += dns.Len(rr) } tbh := make([]byte, size) for _, rr := range sortedSet { ttl := rr.Hdr.Ttl rr.Hdr.Ttl = 0 // only variable that should jitter offset, err = dns.PackRR(rr, tbh, offset, nil, false) if err != nil { return nil, err } rr.Hdr.Ttl = ttl } return tbh, nil }