<commit_before>// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// DNS packet assembly, see RFC 1035. Converting from - Unpack() -
// and to - Pack() - wire format.
// All the packers and unpackers take a (msg []byte, off int)
// and return (off1 int, ok bool).  If they return ok==false, they
// also return off1==len(msg), so that the next unpacker will
// also fail.  This lets us avoid checks of ok until the end of a
// packing sequence.

package dns

import (
	"encoding/base32"
	"encoding/base64"
	"encoding/hex"
	"fmt"
	"math/rand"
	"net"
	"reflect"
	"strconv"
	"time"
)

const maxCompressionOffset = 2 << 13 // We have 14 bits for the compression pointer

var (
	ErrFqdn      error = &Error{Err: "domain must be fully qualified"}
	ErrId        error = &Error{Err: "id mismatch"}
	ErrRdata     error = &Error{Err: "bad rdata"}
	ErrBuf       error = &Error{Err: "buffer size too small"}
	ErrShortRead error = &Error{Err: "short read"}
	ErrConn      error = &Error{Err: "conn holds both UDP and TCP connection"}
	ErrConnEmpty error = &Error{Err: "conn has no connection"}
	ErrServ      error = &Error{Err: "no servers could be reached"}
	ErrKey       error = &Error{Err: "bad key"}
	ErrPrivKey   error = &Error{Err: "bad private key"}
	ErrKeySize   error = &Error{Err: "bad key size"}
	ErrKeyAlg    error = &Error{Err: "bad key algorithm"}
	ErrAlg       error = &Error{Err: "bad algorithm"}
	ErrTime      error = &Error{Err: "bad time"}
	ErrNoSig     error = &Error{Err: "no signature found"}
	ErrSig       error = &Error{Err: "bad signature"}
	ErrSecret    error = &Error{Err: "no secrets defined"}
	ErrSigGen    error = &Error{Err: "bad signature generation"}
	ErrAuth      error = &Error{Err: "bad authentication"}
	ErrSoa       error = &Error{Err: "no SOA"}
	ErrRRset     error = &Error{Err: "bad rrset"}
)

// A manually-unpacked version of (id, bits).
// This is in its own struct for easy printing.
type MsgHdr struct {
	Id                 uint16
	Response           bool
	Opcode             int
	Authoritative      bool
	Truncated          bool
	RecursionDesired   bool
	RecursionAvailable bool
	Zero               bool
	AuthenticatedData  bool
	CheckingDisabled   bool
	Rcode              int
}

// The layout of a DNS message.
type Msg struct {
	MsgHdr
	Compress bool       // If true, the message will be compressed when converted to wire format.
	Question []Question // Holds the RR(s) of the question section.
	Answer   []RR       // Holds the RR(s) of the answer section.
	Ns       []RR       // Holds the RR(s) of the authority section.
	Extra    []RR       // Holds the RR(s) of the additional section.
}

// Map of strings for each RR wire type.
var TypeToString = map[uint16]string{
	TypeCNAME:      "CNAME",
	TypeHINFO:      "HINFO",
	TypeTLSA:       "TSLA",
	TypeMB:         "MB",
	TypeMG:         "MG",
	TypeRP:         "RP",
	TypeMD:         "MD",<commit_msg>Grree, typo<commit_after>// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// DNS packet assembly, see RFC 1035. Converting from - Unpack() -
// and to - Pack() - wire format.
// All the packers and unpackers take a (msg []byte, off int)
// and return (off1 int, ok bool).  If they return ok==false, they
// also return off1==len(msg), so that the next unpacker will
// also fail.  This lets us avoid checks of ok until the end of a
// packing sequence.

package dns

import (
	"encoding/base32"
	"encoding/base64"
	"encoding/hex"
	"fmt"
	"math/rand"
	"net"
	"reflect"
	"strconv"
	"time"
)

const maxCompressionOffset = 2 << 13 // We have 14 bits for the compression pointer

var (
	ErrFqdn      error = &Error{Err: "domain must be fully qualified"}
	ErrId        error = &Error{Err: "id mismatch"}
	ErrRdata     error = &Error{Err: "bad rdata"}
	ErrBuf       error = &Error{Err: "buffer size too small"}
	ErrShortRead error = &Error{Err: "short read"}
	ErrConn      error = &Error{Err: "conn holds both UDP and TCP connection"}
	ErrConnEmpty error = &Error{Err: "conn has no connection"}
	ErrServ      error = &Error{Err: "no servers could be reached"}
	ErrKey       error = &Error{Err: "bad key"}
	ErrPrivKey   error = &Error{Err: "bad private key"}
	ErrKeySize   error = &Error{Err: "bad key size"}
	ErrKeyAlg    error = &Error{Err: "bad key algorithm"}
	ErrAlg       error = &Error{Err: "bad algorithm"}
	ErrTime      error = &Error{Err: "bad time"}
	ErrNoSig     error = &Error{Err: "no signature found"}
	ErrSig       error = &Error{Err: "bad signature"}
	ErrSecret    error = &Error{Err: "no secrets defined"}
	ErrSigGen    error = &Error{Err: "bad signature generation"}
	ErrAuth      error = &Error{Err: "bad authentication"}
	ErrSoa       error = &Error{Err: "no SOA"}
	ErrRRset     error = &Error{Err: "bad rrset"}
)

// A manually-unpacked version of (id, bits).
// This is in its own struct for easy printing.
type MsgHdr struct {
	Id                 uint16
	Response           bool
	Opcode             int
	Authoritative      bool
	Truncated          bool
	RecursionDesired   bool
	RecursionAvailable bool
	Zero               bool
	AuthenticatedData  bool
	CheckingDisabled   bool
	Rcode              int
}

// The layout of a DNS message.
type Msg struct {
	MsgHdr
	Compress bool       // If true, the message will be compressed when converted to wire format.
	Question []Question // Holds the RR(s) of the question section.
	Answer   []RR       // Holds the RR(s) of the answer section.
	Ns       []RR       // Holds the RR(s) of the authority section.
	Extra    []RR       // Holds the RR(s) of the additional section.
}

// Map of strings for each RR wire type.
var TypeToString = map[uint16]string{
	TypeCNAME:      "CNAME",
	TypeHINFO:      "HINFO",
	TypeTLSA:       "TLSA",
	TypeMB:         "MB",
	TypeMG:         "MG",
	TypeRP:         "RP",
	TypeMD:         "MD",
{'fraction_non_alphanumeric': 0.1066066066066066, 'fraction_numerical': 0.007674341007674341, 'mean_word_length': 2.7236024844720497, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6895895', 'n_tokens_mistral': 1960, 'n_tokens_neox': 1898, 'n_words': 730}