Ejemplo
block-buffer 0.12.1
Muestra verificada para cargo block-buffer 0.12.1. El contrato se ejecutó en rust 1 · linux alpine/x64 · docker y pasó: EagerBuffer::<U4>::digest_blocks…
sha256:f9b47721d03bb47bf71ad68db88657017284c80a1f9a310e64cc8639d911e0dd
Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido.
Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas.
MIT-0
Evidencia de ejecución
El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.
- Base de evidencia
- Contrato firmado aprobado
- Recibos de verificación
- 1
- Claves de firma que lo compilaron
- 1
Entorno declarado
linux x64 cargo
Entornos de las ejecuciones de verificación
| Entorno | Contrato | Etapas | Ejecución |
|---|---|---|---|
| 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-08 |
Caso
HOW- Objetivo
- verify pkg:cargo/block-buffer@0.12.1
- Paquetes
- Creado
- 2026-11-08T14:18:03Z
Contrato
- EagerBuffer::<U4>::digest_blocks yields full 4-byte hybrid_array::Array<u8, U4> blocks immediately (pos in 0..4), try_new rejects slices with len >= 4 with Error, and pad_with_zeros returns an owned Array<u8, U4> while resetting get_pos() to 0
- EagerBuffer::<U4>::serialize and deserialize round-trip the 4-byte SerializedBuffer<U4, Eager> (1-byte pos prefix plus up to 3 data bytes, Overhead = U0) and reject non-zero trailing bytes beyond pos
- LazyBuffer::<U4>::digest_blocks retains one full block in the buffer (get_pos() == 4) until at least one subsequent byte arrives, and try_new accepts slices up to len <= 4
- ReadBuffer::<U4>::read generates 4-byte blocks on demand, caches unread tail bytes for read_cached, and zeroizes consumed prefix bytes in serialize
Archivos
- Cargo.lock
- Cargo.toml
- PROMPT.md
- csx.json
- spec.json
- src/main.rs
- tests/contract.rs
Código fuente
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "block-buffer"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2f6c7dbe95a6ed67ad9f18e57daf93a2f034c524b99fd2b76d18fdfeb6660aa"
dependencies = [
"hybrid-array",
]
[[package]]
name = "hybrid-array"
version = "0.4.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "27f864f10dfb56725ce5ce5472bc52252c8f93a4ab86327122cebf62c5f59a17"
dependencies = [
"typenum",
]
[[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 = "sample-block-buffer"
version = "0.1.0"
edition = "2021"
[dependencies]
block-buffer = "=0.12.1"
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.12.1
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:cargo/block-buffer@0.12.1
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.
{"case":{"caseId":"case:sha256:6d5fc7394a2f4dc55ce1e87c75c4ebbe6151217d4998e2d96ff12b6866fc56c3","contract":["EagerBuffer::\u003cU4\u003e::digest_blocks yields full 4-byte hybrid_array::Array\u003cu8, U4\u003e blocks immediately (pos in 0..4), try_new rejects slices with len \u003e= 4 with Error, and pad_with_zeros returns an owned Array\u003cu8, U4\u003e while resetting get_pos() to 0","EagerBuffer::\u003cU4\u003e::serialize and deserialize round-trip the 4-byte SerializedBuffer\u003cU4, Eager\u003e (1-byte pos prefix plus up to 3 data bytes, Overhead = U0) and reject non-zero trailing bytes beyond pos","LazyBuffer::\u003cU4\u003e::digest_blocks retains one full block in the buffer (get_pos() == 4) until at least one subsequent byte arrives, and try_new accepts slices up to len \u003c= 4","ReadBuffer::\u003cU4\u003e::read generates 4-byte blocks on demand, caches unread tail bytes for read_cached, and zeroizes consumed prefix bytes in serialize"],"goal":"verify pkg:cargo/block-buffer@0.12.1","kind":"HOW","packages":["pkg:cargo/block-buffer@0.12.1"],"schemaVersion":1},"contractCommand":["cargo","run","--offline"],"environment":{"arch":"x64","ecosystem":"cargo","os":"linux","packageManager":"cargo","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/block-buffer@0.12.1"],"schemaVersion":1,"subject":"pkg:cargo/block-buffer@0.12.1","verifierAdapter":"cargo@1"}
{
"schemaVersion": 1,
"goal": "verify pkg:cargo/block-buffer@0.12.1",
"kind": "HOW",
"packages": [
"pkg:cargo/block-buffer@0.12.1"
]
}
use block_buffer::array::{Array, typenum::U4};
use block_buffer::{BlockBuffer, Eager, EagerBuffer, Error, Lazy, LazyBuffer, ReadBuffer};
fn run_contract() {
// 1. EagerBuffer::<U4> (BlockBuffer::<U4, Eager>): invariant pos < 4
assert!(BlockBuffer::<U4, Eager>::try_new(b"abc").is_ok());
assert_eq!(BlockBuffer::<U4, Eager>::try_new(b"abcd").unwrap_err(), Error);
let mut eager = EagerBuffer::<U4>::default();
assert_eq!(eager.size(), 4);
assert_eq!(eager.get_pos(), 0);
assert_eq!(eager.remaining(), 4);
let mut eager_out: Vec<[u8; 4]> = Vec::new();
eager.digest_blocks(b"abcdefghij", |blocks| {
for b in blocks {
eager_out.push((*b).into());
}
});
assert_eq!(eager_out, vec![*b"abcd", *b"efgh"]);
assert_eq!(eager.get_pos(), 2);
assert_eq!(eager.get_data(), b"ij");
assert_eq!(eager.remaining(), 2);
// Serialize & deserialize EagerBuffer state (Overhead = U0, so length is 4)
let serialized = eager.serialize();
assert_eq!(serialized.as_slice(), &[2, b'i', b'j', 0]);
let restored = EagerBuffer::<U4>::deserialize(&serialized).expect("valid eager serialization");
assert_eq!(restored.get_data(), b"ij");
let mut bad_serialized = serialized;
bad_serialized[3] = 1; // non-zero tail byte must fail deserialization
assert_eq!(EagerBuffer::<U4>::deserialize(&bad_serialized).unwrap_err(), Error);
// Completing the 3rd block in Eager mode emits immediately
eager.digest_blocks(b"kl", |blocks| {
for b in blocks {
eager_out.push((*b).into());
}
});
assert_eq!(eager_out, vec![*b"abcd", *b"efgh", *b"ijkl"]);
assert_eq!(eager.get_pos(), 0);
// pad_with_zeros returns owned Array<u8, U4> and resets pos to 0
eager.digest_blocks(b"z", |_| unreachable!());
let padded: Array<u8, U4> = eager.pad_with_zeros();
assert_eq!(padded.as_slice(), &[b'z', 0, 0, 0]);
assert_eq!(eager.get_pos(), 0);
// digest_pad with delimiter and suffix
eager.digest_blocks(b"ab", |_| unreachable!());
let mut pad_blocks: Vec<[u8; 4]> = Vec::new();
eager.digest_pad(0x80, &[0x99], |blk| pad_blocks.push((*blk).into()));
assert_eq!(pad_blocks, vec![[b'a', b'b', 0x80, 0x99]]);
assert_eq!(eager.get_pos(), 0);
// 2. LazyBuffer::<U4> (BlockBuffer::<U4, Lazy>): invariant pos <= 4
assert!(BlockBuffer::<U4, Lazy>::try_new(b"abcd").is_ok());
assert_eq!(BlockBuffer::<U4, Lazy>::try_new(b"abcde").unwrap_err(), Error);
let mut lazy = LazyBuffer::<U4>::default();
let mut lazy_out: Vec<[u8; 4]> = Vec::new();
lazy.digest_blocks(b"1234", |blocks| {
for b in blocks {
lazy_out.push((*b).into());
}
});
assert!(lazy_out.is_empty());
assert_eq!(lazy.get_pos(), 4);
assert_eq!(lazy.get_data(), b"1234");
lazy.digest_blocks(b"5", |blocks| {
for b in blocks {
lazy_out.push((*b).into());
}
});
assert_eq!(lazy_out, vec![*b"1234"]);
assert_eq!(lazy.get_pos(), 1);
assert_eq!(lazy.get_data(), b"5");
assert_eq!(lazy.pad_with_zeros().as_slice(), &[b'5', 0, 0, 0]);
assert_eq!(lazy.get_pos(), 0);
// 3. ReadBuffer::<U4>: block-generated stream reader with caching and serialization
let mut reader = ReadBuffer::<U4>::default();
assert_eq!(reader.size(), 4);
assert_eq!(reader.get_pos(), 4);
assert_eq!(reader.remaining(), 0);
let mut counter = 0u8;
let mut out = [0u8; 6];
reader.read(&mut out, |block| {
for slot in block.iter_mut() {
counter += 1;
*slot = counter * 10;
}
});
assert_eq!(out, [10, 20, 30, 40, 50, 60]);
assert_eq!(reader.get_pos(), 2);
assert_eq!(reader.remaining(), 2);
let r_ser = reader.serialize();
assert_eq!(r_ser.as_slice(), &[2, 0, 70, 80]);
let mut reader2 = ReadBuffer::<U4>::deserialize(&r_ser).expect("valid ReadBuffer serialization");
assert_eq!(reader2.read_cached(2), &[70, 80]);
assert_eq!(reader2.remaining(), 0);
}
fn main() {
run_contract();
}
use block_buffer::array::typenum::U4;
use block_buffer::{BlockBuffer, Eager, EagerBuffer, Error, Lazy, LazyBuffer, ReadBuffer};
#[test]
fn contract_block_buffer_v0_12_1() {
assert!(BlockBuffer::<U4, Eager>::try_new(b"abc").is_ok());
assert_eq!(BlockBuffer::<U4, Eager>::try_new(b"abcd").unwrap_err(), Error);
assert!(BlockBuffer::<U4, Lazy>::try_new(b"abcd").is_ok());
assert_eq!(BlockBuffer::<U4, Lazy>::try_new(b"abcde").unwrap_err(), Error);
let mut eager = EagerBuffer::<U4>::default();
let mut eager_blocks: Vec<[u8; 4]> = Vec::new();
eager.digest_blocks(b"abcdefghij", |blocks| {
for b in blocks {
eager_blocks.push((*b).into());
}
});
assert_eq!(eager_blocks, vec![*b"abcd", *b"efgh"]);
assert_eq!(eager.get_pos(), 2);
let ser = eager.serialize();
let de = EagerBuffer::<U4>::deserialize(&ser).unwrap();
assert_eq!(de.get_data(), b"ij");
let padded = eager.pad_with_zeros();
assert_eq!(padded.as_slice(), &[b'i', b'j', 0, 0]);
assert_eq!(eager.get_pos(), 0);
let mut lazy = LazyBuffer::<U4>::default();
let mut lazy_blocks: Vec<[u8; 4]> = Vec::new();
lazy.digest_blocks(b"1234", |blocks| {
for b in blocks {
lazy_blocks.push((*b).into());
}
});
assert!(lazy_blocks.is_empty());
assert_eq!(lazy.get_pos(), 4);
let mut reader = ReadBuffer::<U4>::default();
let mut out = [0u8; 3];
reader.read(&mut out, |block| {
block.copy_from_slice(&[1, 2, 3, 4]);
});
assert_eq!(out, [1, 2, 3]);
assert_eq!(reader.remaining(), 1);
assert_eq!(reader.read_cached(1), &[4]);
}
Seeder de origen
anónimo