CodeSampleX

サンプル

github.com/caddyserver/certmagic v0.25.3

検証済みサンプル — golang github.com/caddyserver/certmagic v0.25.3. go 1.26 · linux alpine/x64 · docker で contract を実行し、成功しました: certmagic.NewDefault returns a valid…

sha256:d1b32c14dcc3e387dfcaab87809f9894fd8fdb15a5540f1e42a2460fb938caa0

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 linux 24 · ubuntu · glibc 2.39 x64 go

検証実行環境

環境 コントラクト ステージ 実行日
go 1.26 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f…
2026-08-28

ケース

HOW
ゴール
verify pkg:golang/github.com/caddyserver/certmagic@v0.25.3
パッケージ
作成日
2026-08-28T02:04:59Z

コントラクト

  1. certmagic.NewDefault returns a valid Config with default cache and TLS configuration
  2. certmagic.MatchWildcard correctly matches single-level subdomains case-insensitively and rejects multi-level subdomains or apex domains
  3. certmagic.SubjectQualifiesForCert validates domain formatting and rejects empty string or leading/trailing dots
  4. certmagic.SubjectQualifiesForPublicCert permits public domain names and single wildcards while rejecting localhost and private/loopback IP addresses
  5. certmagic.SubjectIsIP identifies IP addresses and SubjectIsInternal identifies loopback and private networks
  6. certmagic.StorageKeys generates sanitized and deterministic storage keys for certs and private keys
  7. certmagic.StandardKeyGenerator generates valid ed25519 private keys that can be PEM encoded and decoded
  8. certmagic.LooksLikeHTTPChallenge detects ACME HTTP-01 challenge paths and ignores normal paths
  9. certmagic.New initializes a Config using a custom Cache and preserves custom configuration fields

ファイル

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.go
  • spec.json
  • test/contract.go

ソースアーティファクトをダウンロード (tar.gz)

ソース

PROMPT.md
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 pkg:golang/github.com/caddyserver/certmagic@v0.25.3
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/caddyserver/certmagic@v0.25.3

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.
csx.json
{"case":{"caseId":"case:sha256:58d98066c9002785cae7ffcfd4a05436a1b8aa6c7cc489ce1cba2c0aba83f5eb","contract":["certmagic.NewDefault returns a valid Config with default cache and TLS configuration","certmagic.MatchWildcard correctly matches single-level subdomains case-insensitively and rejects multi-level subdomains or apex domains","certmagic.SubjectQualifiesForCert validates domain formatting and rejects empty string or leading/trailing dots","certmagic.SubjectQualifiesForPublicCert permits public domain names and single wildcards while rejecting localhost and private/loopback IP addresses","certmagic.SubjectIsIP identifies IP addresses and SubjectIsInternal identifies loopback and private networks","certmagic.StorageKeys generates sanitized and deterministic storage keys for certs and private keys","certmagic.StandardKeyGenerator generates valid ed25519 private keys that can be PEM encoded and decoded","certmagic.LooksLikeHTTPChallenge detects ACME HTTP-01 challenge paths and ignores normal paths","certmagic.New initializes a Config using a custom Cache and preserves custom configuration fields"],"goal":"verify pkg:golang/github.com/caddyserver/certmagic@v0.25.3","kind":"HOW","packages":["pkg:golang/github.com/caddyserver/certmagic@v0.25.3"],"schemaVersion":1},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/caddyserver/certmagic@v0.25.3"],"schemaVersion":1,"subject":"pkg:golang/github.com/caddyserver/certmagic@v0.25.3","verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.26.6

require github.com/caddyserver/certmagic v0.25.3

require (
	github.com/caddyserver/zerossl v0.1.5 // indirect
	github.com/klauspost/cpuid/v2 v2.3.0 // indirect
	github.com/libdns/libdns v1.1.1 // indirect
	github.com/mholt/acmez/v3 v3.1.6 // indirect
	github.com/miekg/dns v1.1.72 // indirect
	github.com/zeebo/blake3 v0.2.4 // indirect
	go.uber.org/multierr v1.11.0 // indirect
	go.uber.org/zap v1.27.1 // indirect
	go.uber.org/zap/exp v0.3.0 // indirect
	golang.org/x/crypto v0.50.0 // indirect
	golang.org/x/mod v0.35.0 // indirect
	golang.org/x/net v0.53.0 // indirect
	golang.org/x/sync v0.20.0 // indirect
	golang.org/x/sys v0.43.0 // indirect
	golang.org/x/text v0.36.0 // indirect
	golang.org/x/tools v0.44.0 // indirect
)
go.sum
code.pfad.fr/check v1.1.0 h1:GWvjdzhSEgHvEHe2uJujDcpmZoySKuHQNrZMfzfO0bE=
code.pfad.fr/check v1.1.0/go.mod h1:NiUH13DtYsb7xp5wll0U4SXx7KhXQVCtRgdC96IPfoM=
github.com/caddyserver/certmagic v0.25.3 h1:mGf5ba8F7xA4c5jfDZZbK2buY1VEkbnwpMDixaju94A=
github.com/caddyserver/certmagic v0.25.3/go.mod h1:YVs43D5+H/Dckt4bTga1KSO/xYfFBfVZainGDywYPAA=
github.com/caddyserver/zerossl v0.1.5 h1:dkvOjBAEEtY6LIGAHei7sw2UgqSD6TrWweXpV7lvEvE=
github.com/caddyserver/zerossl v0.1.5/go.mod h1:CxA0acn7oEGO6//4rtrRjYgEoa4MFw/XofZnrYwGqG4=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-jose/go-jose/v4 v4.1.3 h1:CVLmWDhDVRa6Mi/IgCgaopNosCaHz7zrMeF9MlZRkrs=
github.com/go-jose/go-jose/v4 v4.1.3/go.mod h1:x4oUasVrzR7071A4TnHLGSPpNOm2a21K9Kf04k1rs08=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
github.com/letsencrypt/challtestsrv v1.4.2 h1:0ON3ldMhZyWlfVNYYpFuWRTmZNnyfiL9Hh5YzC3JVwU=
github.com/letsencrypt/challtestsrv v1.4.2/go.mod h1:GhqMqcSoeGpYd5zX5TgwA6er/1MbWzx/o7yuuVya+Wk=
github.com/letsencrypt/pebble/v2 v2.10.0 h1:Wq6gYXlsY6ubqI3hhxsTzdyotvfdjFBxuwYqCLCnj/U=
github.com/letsencrypt/pebble/v2 v2.10.0/go.mod h1:Sk8cmUIPcIdv2nINo+9PB4L+ZBhzY+F9A1a/h/xmWiQ=
github.com/libdns/libdns v1.1.1 h1:wPrHrXILoSHKWJKGd0EiAVmiJbFShguILTg9leS/P/U=
github.com/libdns/libdns v1.1.1/go.mod h1:4Bj9+5CQiNMVGf87wjX4CY3HQJypUHRuLvlsfsZqLWQ=
github.com/mholt/acmez/v3 v3.1.6 h1:eGVQNObP0pBN4sxqrXeg7MYqTOWyoiYpQqITVWlrevk=
github.com/mholt/acmez/v3 v3.1.6/go.mod h1:5nTPosTGosLxF3+LU4ygbgMRFDhbAVpqMI4+a4aHLBY=
github.com/miekg/dns v1.1.72 h1:vhmr+TF2A3tuoGNkLDFK9zi36F2LS+hKTRW0Uf8kbzI=
github.com/miekg/dns v1.1.72/go.mod h1:+EuEPhdHOsfk6Wk5TT2CzssZdqkmFhf8r+aVyDEToIs=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/zeebo/assert v1.1.0 h1:hU1L1vLTHsnO8x8c9KAR5GmM5QscxHg5RNU5z5qbUWY=
github.com/zeebo/assert v1.1.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0=
github.com/zeebo/blake3 v0.2.4 h1:KYQPkhpRtcqh0ssGYcKLG1JYvddkEA8QwCM/yBqhaZI=
github.com/zeebo/blake3 v0.2.4/go.mod h1:7eeQ6d2iXWRGF6npfaxl2CU+xy2Fjo2gxeyZGCRUjcE=
github.com/zeebo/pcg v1.0.1 h1:lyqfGeWiv4ahac6ttHs+I5hwtH/+1mrhlCtVNQM2kHo=
github.com/zeebo/pcg v1.0.1/go.mod h1:09F0S9iiKrwn9rlI5yjLkmrug154/YRW6KnnXVDM/l4=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.27.1 h1:08RqriUEv8+ArZRYSTXy1LeBScaMpVSTBhCeaZYfMYc=
go.uber.org/zap v1.27.1/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
go.uber.org/zap/exp v0.3.0 h1:6JYzdifzYkGmTdRR59oYH+Ng7k49H9qVpWwNSsGJj3U=
go.uber.org/zap/exp v0.3.0/go.mod h1:5I384qq7XGxYyByIhHm6jg5CHkGY0nsTfbDLgDDlgJQ=
golang.org/x/crypto v0.50.0 h1:zO47/JPrL6vsNkINmLoo/PH1gcxpls50DNogFvB5ZGI=
golang.org/x/crypto v0.50.0/go.mod h1:3muZ7vA7PBCE6xgPX7nkzzjiUq87kRItoJQM1Yo8S+Q=
golang.org/x/mod v0.35.0 h1:Ww1D637e6Pg+Zb2KrWfHQUnH2dQRLBQyAtpr/haaJeM=
golang.org/x/mod v0.35.0/go.mod h1:+GwiRhIInF8wPm+4AoT6L0FA1QWAad3OMdTRx4tFYlU=
golang.org/x/net v0.53.0 h1:d+qAbo5L0orcWAr0a9JweQpjXF19LMXJE8Ey7hwOdUA=
golang.org/x/net v0.53.0/go.mod h1:JvMuJH7rrdiCfbeHoo3fCQU24Lf5JJwT9W3sJFulfgs=
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
golang.org/x/sys v0.43.0 h1:Rlag2XtaFTxp19wS8MXlJwTvoh8ArU6ezoyFsMyCTNI=
golang.org/x/sys v0.43.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/text v0.36.0 h1:JfKh3XmcRPqZPKevfXVpI1wXPTqbkE5f7JA92a55Yxg=
golang.org/x/text v0.36.0/go.mod h1:NIdBknypM8iqVmPiuco0Dh6P5Jcdk8lJL0CUebqK164=
golang.org/x/tools v0.44.0 h1:UP4ajHPIcuMjT1GqzDWRlalUEoY+uzoZKnhOjbIPD2c=
golang.org/x/tools v0.44.0/go.mod h1:KA0AfVErSdxRZIsOVipbv3rQhVXTnlU6UhKxHd1seDI=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
main.go
package main

import (
	"fmt"
	"log"

	"github.com/caddyserver/certmagic"
)

func main() {
	// 1. Initialize default CertMagic configuration
	cfg := certmagic.NewDefault()
	tlsConfig := cfg.TLSConfig()
	fmt.Printf("Initialized default CertMagic config (TLS configured: %v)\n", tlsConfig != nil)

	// 2. Generate and encode a private key using StandardKeyGenerator
	keyGen := certmagic.StandardKeyGenerator{KeyType: certmagic.ED25519}
	privKey, err := keyGen.GenerateKey()
	if err != nil {
		log.Fatalf("Failed to generate private key: %v", err)
	}

	pemBytes, err := certmagic.PEMEncodePrivateKey(privKey)
	if err != nil {
		log.Fatalf("Failed to PEM-encode key: %v", err)
	}

	signer, err := certmagic.PEMDecodePrivateKey(pemBytes)
	if err != nil {
		log.Fatalf("Failed to PEM-decode key: %v", err)
	}
	fmt.Printf("Generated and decoded ED25519 signer: %T\n", signer)

	// 3. Evaluate domain qualification and wildcard matching
	domains := []string{"example.com", "sub.example.com", "localhost", "192.168.1.1"}
	for _, domain := range domains {
		qualifies := certmagic.SubjectQualifiesForPublicCert(domain)
		matchesWildcard := certmagic.MatchWildcard(domain, "*.example.com")
		fmt.Printf("Domain: %s -> Qualifies: %v, Matches Wildcard (*.example.com): %v\n", domain, qualifies, matchesWildcard)
	}

	// 4. Derive storage key names
	certStorageKey := certmagic.StorageKeys.SiteCert("acme", "example.com")
	fmt.Printf("Storage key for site certificate: %s\n", certStorageKey)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/github.com/caddyserver/certmagic@v0.25.3",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/caddyserver/certmagic@v0.25.3"
  ]
}
test/contract.go
package main

import (
	"context"
	"crypto/ed25519"
	"fmt"
	"net/http"
	"os"

	"github.com/caddyserver/certmagic"
)

func main() {
	// 1. certmagic.NewDefault returns a valid Config with default cache and TLS configuration
	cfg := certmagic.NewDefault()
	if cfg == nil {
		fmt.Fprintf(os.Stderr, "certmagic.NewDefault returned nil\n")
		os.Exit(1)
	}
	tlsCfg := cfg.TLSConfig()
	if tlsCfg == nil || tlsCfg.GetCertificate == nil {
		fmt.Fprintf(os.Stderr, "certmagic.NewDefault().TLSConfig() or GetCertificate is nil\n")
		os.Exit(1)
	}

	// 2. certmagic.MatchWildcard correctly matches single-level subdomains case-insensitively and rejects multi-level subdomains or apex domains
	if !certmagic.MatchWildcard("sub.example.com", "*.example.com") {
		fmt.Fprintf(os.Stderr, "certmagic.MatchWildcard failed for valid single-level subdomain\n")
		os.Exit(1)
	}
	if !certmagic.MatchWildcard("SUB.EXAMPLE.COM", "*.example.com") {
		fmt.Fprintf(os.Stderr, "certmagic.MatchWildcard failed for case-insensitive match\n")
		os.Exit(1)
	}
	if certmagic.MatchWildcard("nested.sub.example.com", "*.example.com") {
		fmt.Fprintf(os.Stderr, "certmagic.MatchWildcard unexpectedly matched nested subdomain\n")
		os.Exit(1)
	}
	if certmagic.MatchWildcard("example.com", "*.example.com") {
		fmt.Fprintf(os.Stderr, "certmagic.MatchWildcard unexpectedly matched apex domain\n")
		os.Exit(1)
	}

	// 3. certmagic.SubjectQualifiesForCert validates domain formatting and rejects empty string or leading/trailing dots
	if !certmagic.SubjectQualifiesForCert("example.com") {
		fmt.Fprintf(os.Stderr, "certmagic.SubjectQualifiesForCert failed for valid domain\n")
		os.Exit(1)
	}
	if certmagic.SubjectQualifiesForCert(".example.com") {
		fmt.Fprintf(os.Stderr, "certmagic.SubjectQualifiesForCert unexpectedly accepted leading dot\n")
		os.Exit(1)
	}
	if certmagic.SubjectQualifiesForCert("example.com.") {
		fmt.Fprintf(os.Stderr, "certmagic.SubjectQualifiesForCert unexpectedly accepted trailing dot\n")
		os.Exit(1)
	}
	if certmagic.SubjectQualifiesForCert("") {
		fmt.Fprintf(os.Stderr, "certmagic.SubjectQualifiesForCert unexpectedly accepted empty domain\n")
		os.Exit(1)
	}

	// 4. certmagic.SubjectQualifiesForPublicCert permits public domain names and single wildcards while rejecting localhost and private/loopback IP addresses
	if !certmagic.SubjectQualifiesForPublicCert("example.com") {
		fmt.Fprintf(os.Stderr, "certmagic.SubjectQualifiesForPublicCert failed for public domain\n")
		os.Exit(1)
	}
	if !certmagic.SubjectQualifiesForPublicCert("*.example.com") {
		fmt.Fprintf(os.Stderr, "certmagic.SubjectQualifiesForPublicCert failed for valid wildcard\n")
		os.Exit(1)
	}
	if certmagic.SubjectQualifiesForPublicCert("localhost") {
		fmt.Fprintf(os.Stderr, "certmagic.SubjectQualifiesForPublicCert unexpectedly accepted localhost\n")
		os.Exit(1)
	}
	if certmagic.SubjectQualifiesForPublicCert("127.0.0.1") {
		fmt.Fprintf(os.Stderr, "certmagic.SubjectQualifiesForPublicCert unexpectedly accepted loopback IP\n")
		os.Exit(1)
	}
	if certmagic.SubjectQualifiesForPublicCert("192.168.1.1") {
		fmt.Fprintf(os.Stderr, "certmagic.SubjectQualifiesForPublicCert unexpectedly accepted private IP\n")
		os.Exit(1)
	}
	if certmagic.SubjectQualifiesForPublicCert("*.*.example.com") {
		fmt.Fprintf(os.Stderr, "certmagic.SubjectQualifiesForPublicCert unexpectedly accepted multi-level wildcard\n")
		os.Exit(1)
	}

	// 5. certmagic.SubjectIsIP identifies IP addresses and SubjectIsInternal identifies loopback and private networks
	if !certmagic.SubjectIsIP("192.168.1.1") || !certmagic.SubjectIsIP("::1") {
		fmt.Fprintf(os.Stderr, "certmagic.SubjectIsIP failed for IPv4/IPv6 address\n")
		os.Exit(1)
	}
	if certmagic.SubjectIsIP("example.com") {
		fmt.Fprintf(os.Stderr, "certmagic.SubjectIsIP returned true for domain name\n")
		os.Exit(1)
	}
	if !certmagic.SubjectIsInternal("localhost") || !certmagic.SubjectIsInternal("10.0.0.1") {
		fmt.Fprintf(os.Stderr, "certmagic.SubjectIsInternal failed for internal host/IP\n")
		os.Exit(1)
	}
	if certmagic.SubjectIsInternal("example.com") {
		fmt.Fprintf(os.Stderr, "certmagic.SubjectIsInternal returned true for public domain\n")
		os.Exit(1)
	}

	// 6. certmagic.StorageKeys generates sanitized and deterministic storage keys for certs and private keys
	siteCertKey := certmagic.StorageKeys.SiteCert("acme", "example.com")
	if siteCertKey != "certificates/acme/example.com/example.com.crt" {
		fmt.Fprintf(os.Stderr, "certmagic.StorageKeys.SiteCert returned unexpected key: %s\n", siteCertKey)
		os.Exit(1)
	}
	siteKeyKey := certmagic.StorageKeys.SitePrivateKey("acme", "example.com")
	if siteKeyKey != "certificates/acme/example.com/example.com.key" {
		fmt.Fprintf(os.Stderr, "certmagic.StorageKeys.SitePrivateKey returned unexpected key: %s\n", siteKeyKey)
		os.Exit(1)
	}
	safeStr := certmagic.StorageKeys.Safe("foo/bar:baz")
	if safeStr == "" || safeStr == "foo/bar:baz" {
		fmt.Fprintf(os.Stderr, "certmagic.StorageKeys.Safe failed to sanitize special characters: %s\n", safeStr)
		os.Exit(1)
	}

	// 7. certmagic.StandardKeyGenerator generates valid ed25519 private keys that can be PEM encoded and decoded
	kg := certmagic.StandardKeyGenerator{KeyType: certmagic.ED25519}
	privKey, err := kg.GenerateKey()
	if err != nil {
		fmt.Fprintf(os.Stderr, "certmagic.StandardKeyGenerator.GenerateKey failed: %v\n", err)
		os.Exit(1)
	}
	if _, ok := privKey.(ed25519.PrivateKey); !ok {
		fmt.Fprintf(os.Stderr, "Generated key is not ed25519.PrivateKey: %T\n", privKey)
		os.Exit(1)
	}
	pemBytes, err := certmagic.PEMEncodePrivateKey(privKey)
	if err != nil {
		fmt.Fprintf(os.Stderr, "certmagic.PEMEncodePrivateKey failed: %v\n", err)
		os.Exit(1)
	}
	decodedSigner, err := certmagic.PEMDecodePrivateKey(pemBytes)
	if err != nil {
		fmt.Fprintf(os.Stderr, "certmagic.PEMDecodePrivateKey failed: %v\n", err)
		os.Exit(1)
	}
	if decodedSigner == nil {
		fmt.Fprintf(os.Stderr, "certmagic.PEMDecodePrivateKey returned nil signer\n")
		os.Exit(1)
	}

	// 8. certmagic.LooksLikeHTTPChallenge detects ACME HTTP-01 challenge paths and ignores normal paths
	reqChallenge, _ := http.NewRequestWithContext(context.Background(), "GET", "http://example.com/.well-known/acme-challenge/token123", nil)
	if !certmagic.LooksLikeHTTPChallenge(reqChallenge) {
		fmt.Fprintf(os.Stderr, "certmagic.LooksLikeHTTPChallenge returned false for ACME challenge URL\n")
		os.Exit(1)
	}
	reqNormal, _ := http.NewRequestWithContext(context.Background(), "GET", "http://example.com/index.html", nil)
	if certmagic.LooksLikeHTTPChallenge(reqNormal) {
		fmt.Fprintf(os.Stderr, "certmagic.LooksLikeHTTPChallenge returned true for normal URL\n")
		os.Exit(1)
	}

	// 9. certmagic.New initializes a Config using a custom Cache and preserves custom configuration fields
	var customCache *certmagic.Cache
	customCache = certmagic.NewCache(certmagic.CacheOptions{
		GetConfigForCert: func(cert certmagic.Certificate) (*certmagic.Config, error) {
			return certmagic.New(customCache, certmagic.Config{}), nil
		},
	})
	defer customCache.Stop()
	customCfg := certmagic.New(customCache, certmagic.Config{
		DefaultServerName: "example.com",
	})
	if customCfg == nil {
		fmt.Fprintf(os.Stderr, "certmagic.New with custom cache returned nil\n")
		os.Exit(1)
	}
	if customCfg.DefaultServerName != "example.com" {
		fmt.Fprintf(os.Stderr, "certmagic.Config DefaultServerName mismatch: got %s, want example.com\n", customCfg.DefaultServerName)
		os.Exit(1)
	}

	fmt.Println("All certmagic contract assertions passed.")
}

オリジンシーダー

匿名