Exemplo
block-buffer 0.12.1: block_buffer::LazyBuffer
Amostra verificada para cargo block-buffer 0.12.1: block_buffer::LazyBuffer. O contrato rodou em rust 1 · linux alpine/x64 · docker e passou.
sha256:35194a67fa80405ebe2c48a129c93fba35ec2ee399457b00d223cb9700961707
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
- 1
- Chaves de assinatura que o compilaram
- 1
Ambiente declarado
linux x64 cargo
Ambientes das execuções de verificação
| Ambiente | Contrato | Etapas | Execução |
|---|---|---|---|
| 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 block_buffer::LazyBuffer in pkg:cargo/block-buffer@0.12.1
- Pacotes
- Símbolos
-
- block_buffer::LazyBuffer
- Criado
- 2026-11-08T15:27:25Z
Contrato
- LazyBuffer::<U4>::try_new accepts slices up to len <= 4 (preserving get_pos() == len and remaining() == 4 - len) and rejects len > 4 with Error
- LazyBuffer::<U4>::digest_blocks retains one full 4-byte block in the buffer (get_pos() == 4, remaining() == 0) until at least one subsequent byte arrives
- LazyBuffer::<U4>::serialize and deserialize round-trip the 5-byte SerializedBuffer<U4, Lazy> (1-byte pos prefix in 0..=4 plus 4 data bytes) and reject non-zero trailing bytes beyond pos with Error
- LazyBuffer::<U4>::pad_with_zeros returns the buffered block padded with zeros as Array<u8, U4> (or the full 4-byte block directly when get_pos() == 4) and resets get_pos() to 0
Arquivos
- Cargo.lock
- Cargo.toml
- PROMPT.md
- csx.json
- spec.json
- src/main.rs
- tests/contract.rs
Código-fonte
# 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-lazy-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-lazy-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 block_buffer::LazyBuffer in pkg:cargo/block-buffer@0.12.1
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:cargo/block-buffer@0.12.1
Demonstrate these symbols/APIs:
- block_buffer::LazyBuffer
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:4058fb1498563d0c0563b875f5a35c4cb2c3b461e9ae8a655aad79ade678d92c","contract":["LazyBuffer::\u003cU4\u003e::try_new accepts slices up to len \u003c= 4 (preserving get_pos() == len and remaining() == 4 - len) and rejects len \u003e 4 with Error","LazyBuffer::\u003cU4\u003e::digest_blocks retains one full 4-byte block in the buffer (get_pos() == 4, remaining() == 0) until at least one subsequent byte arrives","LazyBuffer::\u003cU4\u003e::serialize and deserialize round-trip the 5-byte SerializedBuffer\u003cU4, Lazy\u003e (1-byte pos prefix in 0..=4 plus 4 data bytes) and reject non-zero trailing bytes beyond pos with Error","LazyBuffer::\u003cU4\u003e::pad_with_zeros returns the buffered block padded with zeros as Array\u003cu8, U4\u003e (or the full 4-byte block directly when get_pos() == 4) and resets get_pos() to 0"],"goal":"verify block_buffer::LazyBuffer in pkg:cargo/block-buffer@0.12.1","kind":"HOW","packages":["pkg:cargo/block-buffer@0.12.1"],"schemaVersion":1,"symbols":["block_buffer::LazyBuffer"]},"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","symbols":["block_buffer::LazyBuffer"],"verifierAdapter":"cargo@1"}
{
"schemaVersion": 1,
"goal": "verify block_buffer::LazyBuffer in pkg:cargo/block-buffer@0.12.1",
"kind": "HOW",
"packages": [
"pkg:cargo/block-buffer@0.12.1"
],
"symbols": [
"block_buffer::LazyBuffer"
]
}
use block_buffer::array::{Array, typenum::U4};
use block_buffer::{Error, LazyBuffer};
fn verify_lazy_buffer() {
// 1. Construction and try_new boundary: LazyBuffer::<U4> allows slices up to 4 bytes (0..=4)
let empty = LazyBuffer::<U4>::default();
assert_eq!(empty.size(), 4);
assert_eq!(empty.get_pos(), 0);
assert_eq!(empty.remaining(), 4);
assert_eq!(empty.get_data(), b"");
let full_init = LazyBuffer::<U4>::try_new(b"abcd").expect("len == 4 is valid for LazyBuffer::<U4>");
assert_eq!(full_init.get_pos(), 4);
assert_eq!(full_init.remaining(), 0);
assert_eq!(full_init.get_data(), b"abcd");
assert_eq!(LazyBuffer::<U4>::try_new(b"abcde").unwrap_err(), Error);
// 2. Lazy block digestion: retains one full block until at least one additional byte arrives
let mut buf = LazyBuffer::<U4>::default();
let mut emitted: Vec<[u8; 4]> = Vec::new();
buf.digest_blocks(b"1234", |blocks| {
for block in blocks {
emitted.push((*block).into());
}
});
assert!(emitted.is_empty());
assert_eq!(buf.get_pos(), 4);
assert_eq!(buf.remaining(), 0);
assert_eq!(buf.get_data(), b"1234");
buf.digest_blocks(b"5678", |blocks| {
for block in blocks {
emitted.push((*block).into());
}
});
assert_eq!(emitted, vec![*b"1234"]);
assert_eq!(buf.get_pos(), 4);
assert_eq!(buf.get_data(), b"5678");
buf.digest_blocks(b"9", |blocks| {
for block in blocks {
emitted.push((*block).into());
}
});
assert_eq!(emitted, vec![*b"1234", *b"5678"]);
assert_eq!(buf.get_pos(), 1);
assert_eq!(buf.remaining(), 3);
assert_eq!(buf.get_data(), b"9");
// 3. Serialization and deserialization (Overhead = U1, so SerializedBuffer<U4, Lazy> is 5 bytes)
let ser = buf.serialize();
assert_eq!(ser.as_slice(), &[1, b'9', 0, 0, 0]);
let restored = LazyBuffer::<U4>::deserialize(&ser).expect("valid lazy serialization");
assert_eq!(restored.get_pos(), 1);
assert_eq!(restored.get_data(), b"9");
let full_ser = full_init.serialize();
assert_eq!(full_ser.as_slice(), &[4, b'a', b'b', b'c', b'd']);
let full_restored = LazyBuffer::<U4>::deserialize(&full_ser).expect("valid full lazy serialization");
assert_eq!(full_restored.get_pos(), 4);
assert_eq!(full_restored.get_data(), b"abcd");
let mut invalid_ser = ser;
invalid_ser[4] = 1; // non-zero trailing byte beyond pos must fail
assert_eq!(LazyBuffer::<U4>::deserialize(&invalid_ser).unwrap_err(), Error);
// 4. Padding and reset operations
let padded: Array<u8, U4> = buf.pad_with_zeros();
assert_eq!(padded.as_slice(), &[b'9', 0, 0, 0]);
assert_eq!(buf.get_pos(), 0);
// When LazyBuffer holds a full 4-byte block, pad_with_zeros returns that full block directly
let mut full_for_pad = LazyBuffer::<U4>::try_new(b"wxyz").unwrap();
assert_eq!(full_for_pad.pad_with_zeros().as_slice(), b"wxyz");
assert_eq!(full_for_pad.get_pos(), 0);
// reset clears buffered state back to pos 0
let mut to_reset = LazyBuffer::<U4>::try_new(b"ABCD").unwrap();
assert_eq!(to_reset.get_pos(), 4);
to_reset.reset();
assert_eq!(to_reset.get_pos(), 0);
assert_eq!(to_reset.remaining(), 4);
assert_eq!(to_reset.get_data(), b"");
}
fn main() {
verify_lazy_buffer();
}
use block_buffer::array::typenum::U4;
use block_buffer::{Error, LazyBuffer};
#[test]
fn contract_lazy_buffer() {
assert!(LazyBuffer::<U4>::try_new(b"abcd").is_ok());
assert_eq!(LazyBuffer::<U4>::try_new(b"abcde").unwrap_err(), Error);
let mut buf = LazyBuffer::<U4>::default();
let mut blocks_out: Vec<[u8; 4]> = Vec::new();
buf.digest_blocks(b"1234", |blocks| {
for b in blocks {
blocks_out.push((*b).into());
}
});
assert!(blocks_out.is_empty());
assert_eq!(buf.get_pos(), 4);
assert_eq!(buf.remaining(), 0);
buf.digest_blocks(b"5", |blocks| {
for b in blocks {
blocks_out.push((*b).into());
}
});
assert_eq!(blocks_out, vec![*b"1234"]);
assert_eq!(buf.get_pos(), 1);
assert_eq!(buf.get_data(), b"5");
let serialized = buf.serialize();
assert_eq!(serialized.as_slice(), &[1, b'5', 0, 0, 0]);
let deserialized = LazyBuffer::<U4>::deserialize(&serialized).unwrap();
assert_eq!(deserialized.get_data(), b"5");
let padded = buf.pad_with_zeros();
assert_eq!(padded.as_slice(), &[b'5', 0, 0, 0]);
assert_eq!(buf.get_pos(), 0);
}
Seeder de origem
anônimo