CodeSampleX

Exemple

digest 0.10.7: Update

Échantillon vérifié pour cargo digest 0.10.7: Update. Le contrat s'est exécuté sur rust 1 · linux alpine/x64 · docker et a réussi.

sha256:2f5f500321caff42ee248b319e0e5c76d537856e5b84aef76491e3569fd476e0

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré linux x64 cargo

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
rust 1 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · cargo@1rust:1-alpine@sha256:a10e64dd139b…
2026-11-04

Cas

HOW
Objectif
verify Update in pkg:cargo/digest@0.10.7
Paquets
Symboles
  • Update
Créé
2026-11-04T02:21:20Z

Contrat

  1. Update::update(&mut self, data: &[u8]) appends successive byte slices in call order, and an empty slice &[u8] leaves accumulated state unchanged
  2. Update::chain(self, data: impl AsRef<[u8]>) -> Self consumes self, invokes update(data.as_ref()), and returns the updated value for fluent chaining across &[u8], &str, and Vec<u8>
  3. Update is object-safe and dispatches update(&[u8]) through &mut dyn Update

Fichiers

  • Cargo.lock
  • Cargo.toml
  • PROMPT.md
  • csx.json
  • spec.json
  • test/contract.rs

Télécharger l’artefact source (tar.gz)

Code source

Cargo.lock
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4

[[package]]
name = "block-buffer"
version = "0.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
dependencies = [
 "generic-array",
]

[[package]]
name = "crypto-common"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a"
dependencies = [
 "generic-array",
 "typenum",
]

[[package]]
name = "digest"
version = "0.10.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
dependencies = [
 "block-buffer",
 "crypto-common",
]

[[package]]
name = "generic-array"
version = "0.14.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
dependencies = [
 "typenum",
 "version_check",
]

[[package]]
name = "sample"
version = "0.1.0"
dependencies = [
 "digest",
]

[[package]]
name = "typenum"
version = "1.20.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20"

[[package]]
name = "version_check"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
Cargo.toml
[package]
name = "sample"
version = "0.1.0"
edition = "2021"

[[bin]]
name = "sample"
path = "test/contract.rs"

[dependencies]
digest = "=0.10.7"
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 Update in pkg:cargo/digest@0.10.7
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/digest@0.10.7
Demonstrate these symbols/APIs:
  - Update

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:8e4aa5c3c51a31d0c04cc239bc33d856852ce79c03077d8a60079d99946bde77","contract":["Update::update(\u0026mut self, data: \u0026[u8]) appends successive byte slices in call order, and an empty slice \u0026[u8] leaves accumulated state unchanged","Update::chain(self, data: impl AsRef\u003c[u8]\u003e) -\u003e Self consumes self, invokes update(data.as_ref()), and returns the updated value for fluent chaining across \u0026[u8], \u0026str, and Vec\u003cu8\u003e","Update is object-safe and dispatches update(\u0026[u8]) through \u0026mut dyn Update"],"goal":"verify Update in pkg:cargo/digest@0.10.7","kind":"HOW","packages":["pkg:cargo/digest@0.10.7"],"schemaVersion":1,"symbols":["Update"]},"contractCommand":["cargo","run","--offline"],"environment":{"arch":"x64","ecosystem":"cargo","os":"linux","packageManager":"cargo","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/digest@0.10.7"],"schemaVersion":1,"subject":"pkg:cargo/digest@0.10.7","symbols":["Update"],"verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify Update in pkg:cargo/digest@0.10.7",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/digest@0.10.7"
  ],
  "symbols": [
    "Update"
  ]
}
test/contract.rs
use digest::Update;

#[derive(Default, Debug, PartialEq, Eq)]
struct ByteAccumulator {
    buf: Vec<u8>,
}

impl Update for ByteAccumulator {
    fn update(&mut self, data: &[u8]) {
        self.buf.extend_from_slice(data);
    }
}

fn accept_update_dyn(target: &mut dyn Update, chunk: &[u8]) {
    target.update(chunk);
}

fn main() {
    // 1. Direct Update::update calls accumulate slices in order
    let mut acc = ByteAccumulator::default();
    acc.update(b"hello");
    acc.update(b" ");
    acc.update(b"world");
    assert_eq!(acc.buf, b"hello world");

    // 2. Empty slice update preserves existing state
    acc.update(b"");
    assert_eq!(acc.buf, b"hello world");

    // 3. Update::chain consumes Self, appends AsRef<[u8]> inputs, and returns Self
    let chained = ByteAccumulator::default()
        .chain(b"alpha")
        .chain("-beta")
        .chain(vec![b'-', b'1']);
    assert_eq!(chained.buf, b"alpha-beta-1");

    // 4. Update is object-safe (&mut dyn Update)
    let mut dyn_acc = ByteAccumulator::default();
    accept_update_dyn(&mut dyn_acc, b"dyn-");
    accept_update_dyn(&mut dyn_acc, b"ok");
    assert_eq!(dyn_acc.buf, b"dyn-ok");
}

Seeder d'origine

anonyme