サンプル
github.com/miekg/dns v1.1.63: RR
検証済みサンプル — golang github.com/miekg/dns v1.1.63: RR. go 1.26 · linux debian/x64 · docker で contract を実行し、成功しました: dns.NewRR parses valid master format strings…
sha256:2971189ac45801fbbd5f3951f5f090ed35f78c0da80023876289768443a962ef
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
MIT-0
実行証拠
宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。
- 証拠の基準
- 署名済みコントラクト合格
- 検証レシート
- 1
- ビルドした署名鍵
- 1
宣言された環境
linux 24 · ubuntu · glibc 2.39 amd64 go 1.26 go 1
検証実行環境
| 環境 | コントラクト | ステージ | 実行日 |
|---|---|---|---|
| go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a… |
2026-09-04 |
ケース
HOW- ゴール
- verify github.com/miekg/dns.RR in pkg:golang/github.com/miekg/dns@v1.1.63
- シンボル
-
- github.com/miekg/dns.RR
- 作成日
- 2026-09-04T08:59:30Z
コントラクト
- dns.NewRR parses valid master format strings into concrete dns.RR implementations including TypeA, TypeAAAA, TypeMX, and TypeTXT
- dns.RR Header provides common resource record metadata including Name, Rrtype, Class, and Ttl
- dns.RR String formats resource records into canonical zone representation with round-trip fidelity
- dns.NewRR returns an error when parsing malformed or empty resource record strings
- dns.RR instances integrate into dns.Msg Answer sections to form valid DNS responses
ファイル
- PROMPT.md
- csx.json
- dns_rr.go
- go.mod
- go.sum
- spec.json
- test/contract_test.go
ソース
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify github.com/miekg/dns.RR in pkg:golang/github.com/miekg/dns@v1.1.63
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/github.com/miekg/dns@v1.1.63
Demonstrate these symbols/APIs:
- github.com/miekg/dns.RR
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:f0bfb006640c0cbe30c144ebf0308678dc7433c43bd05bcb3dce0e1c18d99869","contract":["dns.NewRR parses valid master format strings into concrete dns.RR implementations including TypeA, TypeAAAA, TypeMX, and TypeTXT","dns.RR Header provides common resource record metadata including Name, Rrtype, Class, and Ttl","dns.RR String formats resource records into canonical zone representation with round-trip fidelity","dns.NewRR returns an error when parsing malformed or empty resource record strings","dns.RR instances integrate into dns.Msg Answer sections to form valid DNS responses"],"goal":"verify github.com/miekg/dns.RR in pkg:golang/github.com/miekg/dns@v1.1.63","kind":"HOW","packages":["pkg:golang/github.com/miekg/dns@v1.1.63"],"schemaVersion":1,"symbols":["github.com/miekg/dns.RR"]},"contractCommand":["go","test","-v","./..."],"environment":{"arch":"amd64","compiler":"go","compilerVersion":"1.26.6","distro":"ubuntu","ecosystem":"golang","language":"go","languageVersion":"1.26.6","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","packageManagerVersion":"1.26.6","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/miekg/dns@v1.1.63"],"schemaVersion":1,"subject":"pkg:golang/github.com/miekg/dns@v1.1.63","symbols":["github.com/miekg/dns.RR"],"verifierAdapter":"golang@1"}
package dnsrr
import (
"fmt"
"github.com/miekg/dns"
)
// ParseRR parses a string representation of a DNS Resource Record into a dns.RR.
func ParseRR(s string) (dns.RR, error) {
rr, err := dns.NewRR(s)
if err != nil {
return nil, fmt.Errorf("failed to parse RR: %w", err)
}
if rr == nil {
return nil, fmt.Errorf("empty or comment-only RR string")
}
return rr, nil
}
// FormatRR formats a dns.RR into its canonical zone string representation.
func FormatRR(rr dns.RR) string {
if rr == nil {
return ""
}
return rr.String()
}
// GetHeaderDetails extracts the common header metadata from a dns.RR.
func GetHeaderDetails(rr dns.RR) (name string, rrtype uint16, class uint16, ttl uint32, err error) {
if rr == nil {
return "", 0, 0, 0, fmt.Errorf("rr is nil")
}
hdr := rr.Header()
if hdr == nil {
return "", 0, 0, 0, fmt.Errorf("rr header is nil")
}
return hdr.Name, hdr.Rrtype, hdr.Class, hdr.Ttl, nil
}
// AttachAnswer adds a dns.RR to the Answer section of a dns.Msg.
func AttachAnswer(msg *dns.Msg, rr dns.RR) {
msg.Answer = append(msg.Answer, rr)
}
module example.com/dnsrr
go 1.26.6
require github.com/miekg/dns v1.1.63
require (
golang.org/x/mod v0.18.0 // indirect
golang.org/x/net v0.31.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/tools v0.22.0 // indirect
)
github.com/miekg/dns v1.1.63 h1:8M5aAw6OMZfFXTT7K5V0Eu5YiiL8l7nUAkyN6C9YwaY=
github.com/miekg/dns v1.1.63/go.mod h1:6NGHfjhpmr5lt3XPLuyfDJi5AXbNIPM9PY6H6sF1Nfs=
golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0=
golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo=
golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA=
golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c=
{
"schemaVersion": 1,
"goal": "verify github.com/miekg/dns.RR in pkg:golang/github.com/miekg/dns@v1.1.63",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/miekg/dns@v1.1.63"
],
"symbols": [
"github.com/miekg/dns.RR"
]
}
package test
import (
"net"
"strings"
"testing"
"example.com/dnsrr"
"github.com/miekg/dns"
)
func TestParseRRAndConcreteImplementations(t *testing.T) {
testCases := []struct {
input string
expectedType uint16
verifyFunc func(t *testing.T, rr dns.RR)
}{
{
input: "example.com. 3600 IN A 93.184.216.34",
expectedType: dns.TypeA,
verifyFunc: func(t *testing.T, rr dns.RR) {
aRec, ok := rr.(*dns.A)
if !ok {
t.Fatalf("expected *dns.A, got %T", rr)
}
if !aRec.A.Equal(net.ParseIP("93.184.216.34")) {
t.Errorf("expected IP 93.184.216.34, got %s", aRec.A)
}
},
},
{
input: "example.com. 7200 IN AAAA 2606:2800:220:1:248:1893:25c8:1946",
expectedType: dns.TypeAAAA,
verifyFunc: func(t *testing.T, rr dns.RR) {
aaaaRec, ok := rr.(*dns.AAAA)
if !ok {
t.Fatalf("expected *dns.AAAA, got %T", rr)
}
if !aaaaRec.AAAA.Equal(net.ParseIP("2606:2800:220:1:248:1893:25c8:1946")) {
t.Errorf("expected IPv6, got %s", aaaaRec.AAAA)
}
},
},
{
input: "mail.example.com. 3600 IN MX 10 smtp.example.com.",
expectedType: dns.TypeMX,
verifyFunc: func(t *testing.T, rr dns.RR) {
mxRec, ok := rr.(*dns.MX)
if !ok {
t.Fatalf("expected *dns.MX, got %T", rr)
}
if mxRec.Preference != 10 || mxRec.Mx != "smtp.example.com." {
t.Errorf("expected preference 10 and smtp.example.com., got %d and %s", mxRec.Preference, mxRec.Mx)
}
},
},
{
input: "example.com. 300 IN TXT \"v=spf1 -all\"",
expectedType: dns.TypeTXT,
verifyFunc: func(t *testing.T, rr dns.RR) {
txtRec, ok := rr.(*dns.TXT)
if !ok {
t.Fatalf("expected *dns.TXT, got %T", rr)
}
if len(txtRec.Txt) != 1 || txtRec.Txt[0] != "v=spf1 -all" {
t.Errorf("unexpected TXT value: %v", txtRec.Txt)
}
},
},
}
for _, tc := range testCases {
rr, err := dnsrr.ParseRR(tc.input)
if err != nil {
t.Fatalf("failed to parse valid RR string %q: %v", tc.input, err)
}
if rr.Header().Rrtype != tc.expectedType {
t.Errorf("expected rrtype %d, got %d", tc.expectedType, rr.Header().Rrtype)
}
tc.verifyFunc(t, rr)
}
}
func TestRRHeaderMetadata(t *testing.T) {
raw := "sub.example.org. 1800 IN A 192.0.2.1"
rr, err := dnsrr.ParseRR(raw)
if err != nil {
t.Fatalf("unexpected parse error: %v", err)
}
name, rrtype, class, ttl, err := dnsrr.GetHeaderDetails(rr)
if err != nil {
t.Fatalf("GetHeaderDetails failed: %v", err)
}
if name != "sub.example.org." {
t.Errorf("expected name 'sub.example.org.', got %q", name)
}
if rrtype != dns.TypeA {
t.Errorf("expected rrtype TypeA (%d), got %d", dns.TypeA, rrtype)
}
if class != dns.ClassINET {
t.Errorf("expected class ClassINET (%d), got %d", dns.ClassINET, class)
}
if ttl != 1800 {
t.Errorf("expected TTL 1800, got %d", ttl)
}
}
func TestRRStringFormatting(t *testing.T) {
raw := "test.example.com. 3600 IN A 198.51.100.1"
rr, err := dnsrr.ParseRR(raw)
if err != nil {
t.Fatalf("unexpected parse error: %v", err)
}
formatted := dnsrr.FormatRR(rr)
if !strings.Contains(formatted, "test.example.com.") || !strings.Contains(formatted, "198.51.100.1") {
t.Errorf("formatted RR string does not contain expected tokens: %q", formatted)
}
// Re-parse formatted string to ensure round-trip fidelity
reparsed, err := dnsrr.ParseRR(formatted)
if err != nil {
t.Fatalf("failed to re-parse formatted string %q: %v", formatted, err)
}
if reparsed.Header().Name != rr.Header().Name || reparsed.Header().Rrtype != rr.Header().Rrtype {
t.Errorf("round-trip parsed RR header mismatch: got %v, want %v", reparsed.Header(), rr.Header())
}
}
func TestRRInvalidStringHandling(t *testing.T) {
invalidInputs := []string{
"example.com. 3600 IN A not-a-valid-ip",
"example.com. 3600 IN A 999.999.999.999",
"example.com. 3600 IN INVALIDTYPE 123",
"",
"; comment line only",
}
for _, input := range invalidInputs {
_, err := dnsrr.ParseRR(input)
if err == nil {
t.Errorf("expected error for invalid RR input %q, got nil", input)
}
}
}
func TestRRInDNSMessage(t *testing.T) {
msg := new(dns.Msg)
msg.SetQuestion(dns.Fqdn("example.com"), dns.TypeA)
rr, err := dnsrr.ParseRR("example.com. 300 IN A 93.184.216.34")
if err != nil {
t.Fatalf("failed to parse RR: %v", err)
}
dnsrr.AttachAnswer(msg, rr)
if len(msg.Answer) != 1 {
t.Fatalf("expected 1 record in Answer section, got %d", len(msg.Answer))
}
if msg.Answer[0].Header().Name != "example.com." {
t.Errorf("expected Answer[0] name 'example.com.', got %q", msg.Answer[0].Header().Name)
}
if msg.Answer[0].Header().Ttl != 300 {
t.Errorf("expected Answer[0] TTL 300, got %d", msg.Answer[0].Header().Ttl)
}
}
オリジンシーダー
匿名