CodeSampleX

Exemple

block-buffer 0.10.4: block_buffer::BlockBuffer, block_buffer::Eager, block_buffer::Lazy

Échantillon vérifié pour cargo block-buffer 0.10.4: block_buffer::BlockBuffer, block_buffer::Eager, block_buffer::Lazy. Le contrat s'est exécuté sur rust 1 …

sha256:7e4e314cb261f4a57ecfcadfca7e2ad3b2dca220d51198ab02ea4a651de8b4e0

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 pkg:cargo/block-buffer@0.10.4
Paquets
Symboles
  • block_buffer::BlockBuffer
  • block_buffer::Eager
  • block_buffer::Lazy
Créé
2026-11-04T02:28:52Z

Contrat

  1. BlockBuffer::<U4, Eager>::digest_blocks yields full 4-byte blocks immediately and leaves trailing bytes at get_pos()
  2. BlockBuffer::<U4, Lazy>::digest_blocks retains one full block in the buffer (get_pos() == 4) until at least one subsequent byte arrives
  3. BlockBuffer::pad_with_zeros zero-pads the remaining tail bytes into a complete block and resets get_pos() to 0

Fichiers

  • Cargo.lock
  • Cargo.toml
  • PROMPT.md
  • csx.json
  • spec.json
  • src/main.rs
  • tests/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 = "generic-array"
version = "0.14.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4bb6743198531e02858aeaea5398fcc883e71851fcbcb5a2f773e2fb6cb1edf2"
dependencies = [
 "typenum",
 "version_check",
]

[[package]]
name = "sample-block-buffer"
version = "0.1.0"
dependencies = [
 "block-buffer",
]

[[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-block-buffer"
version = "0.1.0"
edition = "2021"

[dependencies]
block-buffer = "=0.10.4"
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:cargo/block-buffer@0.10.4
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/block-buffer@0.10.4

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:ad907691efa7a768b93c3246ce74cd0a081cceb6d6fade90a5fc14a75210f61f","contract":["BlockBuffer::\u003cU4, Eager\u003e::digest_blocks yields full 4-byte blocks immediately and leaves trailing bytes at get_pos()","BlockBuffer::\u003cU4, Lazy\u003e::digest_blocks retains one full block in the buffer (get_pos() == 4) until at least one subsequent byte arrives","BlockBuffer::pad_with_zeros zero-pads the remaining tail bytes into a complete block and resets get_pos() to 0"],"goal":"verify pkg:cargo/block-buffer@0.10.4","kind":"HOW","packages":["pkg:cargo/block-buffer@0.10.4"],"schemaVersion":1,"symbols":["block_buffer::BlockBuffer","block_buffer::Eager","block_buffer::Lazy"]},"contractCommand":["cargo","run","--offline"],"environment":{"arch":"x64","ecosystem":"cargo","os":"linux","packageManager":"cargo","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/block-buffer@0.10.4"],"schemaVersion":1,"subject":"pkg:cargo/block-buffer@0.10.4","symbols":["block_buffer::BlockBuffer","block_buffer::Eager","block_buffer::Lazy"],"verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:cargo/block-buffer@0.10.4",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/block-buffer@0.10.4"
  ]
}
src/main.rs
use block_buffer::generic_array::typenum::U4;
use block_buffer::{BlockBuffer, Eager, Lazy};

fn main() {
    // 1. Eager mode: processes full 4-byte blocks immediately when 4th byte arrives
    let mut eager_buf = BlockBuffer::<U4, Eager>::default();
    let mut eager_blocks: Vec<[u8; 4]> = Vec::new();

    eager_buf.digest_blocks(b"abcdefghij", |blocks| {
        for block in blocks {
            eager_blocks.push((*block).into());
        }
    });

    assert_eq!(eager_blocks, vec![*b"abcd", *b"efgh"]);
    assert_eq!(eager_buf.get_pos(), 2);

    // Feed 2 more bytes ("kl"): Eager mode processes the 3rd block immediately
    eager_buf.digest_blocks(b"kl", |blocks| {
        for block in blocks {
            eager_blocks.push((*block).into());
        }
    });
    assert_eq!(eager_blocks, vec![*b"abcd", *b"efgh", *b"ijkl"]);
    assert_eq!(eager_buf.get_pos(), 0);

    // Feed 1 byte and pad remaining bytes with zeros
    eager_buf.digest_blocks(b"z", |_| unreachable!());
    assert_eq!(eager_buf.get_pos(), 1);
    let padded_arr: [u8; 4] = (*eager_buf.pad_with_zeros()).into();
    assert_eq!(padded_arr, [b'z', 0, 0, 0]);
    assert_eq!(eager_buf.get_pos(), 0);

    // 2. Lazy mode: keeps a full block buffered until at least 1 additional byte arrives
    let mut lazy_buf = BlockBuffer::<U4, Lazy>::default();
    let mut lazy_blocks: Vec<[u8; 4]> = Vec::new();

    // Feeding 4 bytes in Lazy mode keeps them in the buffer (pos == 4)
    lazy_buf.digest_blocks(b"1234", |blocks| {
        for block in blocks {
            lazy_blocks.push((*block).into());
        }
    });
    assert!(lazy_blocks.is_empty());
    assert_eq!(lazy_buf.get_pos(), 4);

    // Feeding 1 more byte triggers processing of the buffered block "1234"
    lazy_buf.digest_blocks(b"5", |blocks| {
        for block in blocks {
            lazy_blocks.push((*block).into());
        }
    });
    assert_eq!(lazy_blocks, vec![*b"1234"]);
    assert_eq!(lazy_buf.get_pos(), 1);

    let lazy_padded: [u8; 4] = (*lazy_buf.pad_with_zeros()).into();
    assert_eq!(lazy_padded, [b'5', 0, 0, 0]);
}
tests/contract.rs
use block_buffer::generic_array::typenum::U4;
use block_buffer::{BlockBuffer, Eager, Lazy};

#[test]
fn contract_block_buffer_eager_and_lazy() {
    let mut eager_buf = BlockBuffer::<U4, Eager>::default();
    let mut eager_blocks: Vec<[u8; 4]> = Vec::new();
    eager_buf.digest_blocks(b"abcdefgh", |blocks| {
        for b in blocks {
            eager_blocks.push((*b).into());
        }
    });
    assert_eq!(eager_blocks, vec![*b"abcd", *b"efgh"]);
    assert_eq!(eager_buf.get_pos(), 0);

    let mut lazy_buf = BlockBuffer::<U4, Lazy>::default();
    let mut lazy_blocks: Vec<[u8; 4]> = Vec::new();
    lazy_buf.digest_blocks(b"abcdefgh", |blocks| {
        for b in blocks {
            lazy_blocks.push((*b).into());
        }
    });
    assert_eq!(lazy_blocks, vec![*b"abcd"]);
    assert_eq!(lazy_buf.get_pos(), 4);
}

Seeder d'origine

anonyme