CodeSampleX

示例

github.com/google/uuid v1.6.0: Generate DCE Security version 2 UUIDs with uuid.NewDCESecurity, uuid.NewDCEPerson, and uuid.NewDCEGroup and extract domain and local ID

已验证示例 — golang github.com/google/uuid v1.6.0: Generate DCE Security version 2 UUIDs with uuid.NewDCESecurity, uuid.NewDCEPerson, and uuid.NewDCEGroup and…

sha256:f044aab8470502c56a265bab0cd6494a2d23624dacab295f5c316958bfe6a938

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 MIT-0

执行证据

声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。

证据依据
签名契约通过
验证回执
2
构建过它的签名密钥
2
声明的环境 linux 24 · ubuntu · glibc 2.39 x64 go wsl

验证运行环境

环境 契约 阶段 运行日期
go 1.26 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1
2026-08-19
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-07

案例

HOW
目标
Generate DCE Security version 2 UUIDs with uuid.NewDCESecurity, uuid.NewDCEPerson, and uuid.NewDCEGroup and extract domain and local ID
包
符号
  • uuid.Domain
  • uuid.NewDCEGroup
  • uuid.NewDCEPerson
  • uuid.NewDCESecurity
  • uuid.UUID.Domain
  • uuid.UUID.ID
创建时间
2026-08-18T20:18:35Z

契约

  1. assert NewDCESecurity creates Version 2 UUID with RFC4122 variant for given Domain and ID
  2. assert Domain and ID methods correctly extract embedded domain and local ID from UUIDv2
  3. assert NewDCEPerson creates UUIDv2 with Person domain and current process UID
  4. assert NewDCEGroup creates UUIDv2 with Group domain and current process GID

文件

  • 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: Generate DCE Security version 2 UUIDs with uuid.NewDCESecurity, uuid.NewDCEPerson, and uuid.NewDCEGroup and extract domain and local ID
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/google/uuid@v1.6.0
Demonstrate these symbols/APIs:
  - uuid.Domain
  - uuid.NewDCEGroup
  - uuid.NewDCEPerson
  - uuid.NewDCESecurity
  - uuid.UUID.Domain
  - uuid.UUID.ID

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:3e72c72f85d9ff9b3ff6f02050f8fc29ffd2db696a449728745f9cddf10e8af5","contract":["assert NewDCESecurity creates Version 2 UUID with RFC4122 variant for given Domain and ID","assert Domain and ID methods correctly extract embedded domain and local ID from UUIDv2","assert NewDCEPerson creates UUIDv2 with Person domain and current process UID","assert NewDCEGroup creates UUIDv2 with Group domain and current process GID"],"goal":"Generate DCE Security version 2 UUIDs with uuid.NewDCESecurity, uuid.NewDCEPerson, and uuid.NewDCEGroup and extract domain and local ID","kind":"HOW","packages":["pkg:golang/github.com/google/uuid@v1.6.0"],"schemaVersion":1,"symbols":["uuid.Domain","uuid.NewDCEGroup","uuid.NewDCEPerson","uuid.NewDCESecurity","uuid.UUID.Domain","uuid.UUID.ID"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1,"virtualization":"wsl"},"license":"MIT-0","packages":["pkg:golang/github.com/google/uuid@v1.6.0"],"schemaVersion":1,"symbols":["uuid.Domain","uuid.NewDCEGroup","uuid.NewDCEPerson","uuid.NewDCESecurity","uuid.UUID.Domain","uuid.UUID.ID"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.22

require github.com/google/uuid v1.6.0
go.sum
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
main.go
package main

import (
	"fmt"

	"github.com/google/uuid"
)

func main() {
	// 1. Generate DCE Security (UUIDv2) with explicit Domain and ID
	const customID uint32 = 1001
	dceUUID, err := uuid.NewDCESecurity(uuid.Person, customID)
	if err != nil {
		fmt.Printf("Failed to generate DCE UUID: %v\n", err)
		return
	}

	fmt.Printf("DCE UUID:      %s\n", dceUUID.String())
	fmt.Printf("Version:       %d\n", dceUUID.Version())
	fmt.Printf("Variant:       %s\n", dceUUID.Variant())
	fmt.Printf("Domain:        %s (%d)\n", dceUUID.Domain(), dceUUID.Domain())
	fmt.Printf("Local ID:      %d\n", dceUUID.ID())

	// 2. Generate DCE UUID for current process user (Person domain)
	personUUID, err := uuid.NewDCEPerson()
	if err != nil {
		fmt.Printf("Failed to generate DCE Person UUID: %v\n", err)
		return
	}
	fmt.Printf("Person UUID:   %s (UID=%d, Domain=%s)\n", personUUID.String(), personUUID.ID(), personUUID.Domain())

	// 3. Generate DCE UUID for current process group (Group domain)
	groupUUID, err := uuid.NewDCEGroup()
	if err != nil {
		fmt.Printf("Failed to generate DCE Group UUID: %v\n", err)
		return
	}
	fmt.Printf("Group UUID:    %s (GID=%d, Domain=%s)\n", groupUUID.String(), groupUUID.ID(), groupUUID.Domain())
}
spec.json
{
  "schemaVersion": 1,
  "goal": "Generate DCE Security version 2 UUIDs with uuid.NewDCESecurity, uuid.NewDCEPerson, and uuid.NewDCEGroup and extract domain and local ID",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/google/uuid@v1.6.0"
  ],
  "symbols": [
    "uuid.Domain",
    "uuid.NewDCEGroup",
    "uuid.NewDCEPerson",
    "uuid.NewDCESecurity",
    "uuid.UUID.Domain",
    "uuid.UUID.ID"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"

	"github.com/google/uuid"
)

func main() {
	// 1. assert NewDCESecurity creates Version 2 UUID with RFC4122 variant for given Domain and ID
	const testID uint32 = 42000
	u, err := uuid.NewDCESecurity(uuid.Org, testID)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: uuid.NewDCESecurity failed: %v\n", err)
		os.Exit(1)
	}

	if u.Version() != 2 {
		fmt.Fprintf(os.Stderr, "FAIL: expected Version 2, got %d\n", u.Version())
		os.Exit(1)
	}

	if u.Variant() != uuid.RFC4122 {
		fmt.Fprintf(os.Stderr, "FAIL: expected Variant RFC4122, got %s\n", u.Variant())
		os.Exit(1)
	}

	// 2. assert Domain and ID methods correctly extract embedded domain and local ID from UUIDv2
	if u.Domain() != uuid.Org {
		fmt.Fprintf(os.Stderr, "FAIL: expected Domain Org (%d), got %s (%d)\n", uuid.Org, u.Domain(), u.Domain())
		os.Exit(1)
	}

	if u.ID() != testID {
		fmt.Fprintf(os.Stderr, "FAIL: expected ID %d, got %d\n", testID, u.ID())
		os.Exit(1)
	}

	// Also verify Person domain with explicit ID
	uPerson, err := uuid.NewDCESecurity(uuid.Person, 12345)
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: uuid.NewDCESecurity(Person) failed: %v\n", err)
		os.Exit(1)
	}
	if uPerson.Domain() != uuid.Person || uPerson.ID() != 12345 {
		fmt.Fprintf(os.Stderr, "FAIL: uPerson Domain/ID mismatch: domain=%s, id=%d\n", uPerson.Domain(), uPerson.ID())
		os.Exit(1)
	}

	// 3. assert NewDCEPerson creates UUIDv2 with Person domain and current process UID
	personUUID, err := uuid.NewDCEPerson()
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: uuid.NewDCEPerson failed: %v\n", err)
		os.Exit(1)
	}

	if personUUID.Version() != 2 {
		fmt.Fprintf(os.Stderr, "FAIL: personUUID version expected 2, got %d\n", personUUID.Version())
		os.Exit(1)
	}
	if personUUID.Variant() != uuid.RFC4122 {
		fmt.Fprintf(os.Stderr, "FAIL: personUUID variant expected RFC4122, got %s\n", personUUID.Variant())
		os.Exit(1)
	}
	if personUUID.Domain() != uuid.Person {
		fmt.Fprintf(os.Stderr, "FAIL: personUUID expected Domain Person, got %s\n", personUUID.Domain())
		os.Exit(1)
	}
	expectedUID := uint32(os.Getuid())
	if personUUID.ID() != expectedUID {
		fmt.Fprintf(os.Stderr, "FAIL: personUUID expected ID %d (UID), got %d\n", expectedUID, personUUID.ID())
		os.Exit(1)
	}

	// 4. assert NewDCEGroup creates UUIDv2 with Group domain and current process GID
	groupUUID, err := uuid.NewDCEGroup()
	if err != nil {
		fmt.Fprintf(os.Stderr, "FAIL: uuid.NewDCEGroup failed: %v\n", err)
		os.Exit(1)
	}

	if groupUUID.Version() != 2 {
		fmt.Fprintf(os.Stderr, "FAIL: groupUUID version expected 2, got %d\n", groupUUID.Version())
		os.Exit(1)
	}
	if groupUUID.Variant() != uuid.RFC4122 {
		fmt.Fprintf(os.Stderr, "FAIL: groupUUID variant expected RFC4122, got %s\n", groupUUID.Variant())
		os.Exit(1)
	}
	if groupUUID.Domain() != uuid.Group {
		fmt.Fprintf(os.Stderr, "FAIL: groupUUID expected Domain Group, got %s\n", groupUUID.Domain())
		os.Exit(1)
	}
	expectedGID := uint32(os.Getgid())
	if groupUUID.ID() != expectedGID {
		fmt.Fprintf(os.Stderr, "FAIL: groupUUID expected ID %d (GID), got %d\n", expectedGID, groupUUID.ID())
		os.Exit(1)
	}

	fmt.Println("PASS: all uuid.NewDCESecurity contract assertions satisfied")
}

原始种子者

匿名