CodeSampleX

Exemplo

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

Amostra verificada para golang github.com/google/uuid v1.6.0: Generate DCE Security version 2 UUIDs with uuid.NewDCESecurity, uuid.NewDCEPerson, and…

sha256:f044aab8470502c56a265bab0cd6494a2d23624dacab295f5c316958bfe6a938

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
2
Chaves de assinatura que o compilaram
2
Ambiente declarado linux 24 · ubuntu · glibc 2.39 x64 go wsl

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
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

Caso

HOW
Objetivo
Generate DCE Security version 2 UUIDs with uuid.NewDCESecurity, uuid.NewDCEPerson, and uuid.NewDCEGroup and extract domain and local ID
Pacotes
Símbolos
  • uuid.Domain
  • uuid.NewDCEGroup
  • uuid.NewDCEPerson
  • uuid.NewDCESecurity
  • uuid.UUID.Domain
  • uuid.UUID.ID
Criado
2026-08-18T20:18:35Z

Contrato

  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

Arquivos

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

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

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")
}

Seeder de origem

anônimo