CodeSampleX

Ejemplo

crypto-common 0.2.2: crypto_common::BlockSizeUser

Muestra verificada para cargo crypto-common 0.2.2: crypto_common::BlockSizeUser. El contrato se ejecutó en rust 1 · linux alpine/x64 · docker y pasó.

sha256:9efabef4bf54a57e573f350072c191ee8a274470f6b5b32029a0d690d0bd15ea

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 · alpine · musl 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-12

Caso

HOW
Objetivo
verify crypto_common::BlockSizeUser in pkg:cargo/crypto-common@0.2.2
Paquetes
Símbolos
  • crypto_common::BlockSizeUser
Creado
2026-11-12T06:05:10Z

Contrato

  1. Implementing BlockSizeUser with a typenum ArraySize sets BlockSize::USIZE and returns the byte count from block_size() via static dispatch (BlockSizeUser is not dyn-compatible because block_size has no self receiver)
  2. Block<B> constructs a fixed-size hybrid_array::Array<u8, B::BlockSize> matching B::block_size() and rejects mismatched slice lengths in TryFrom<&[u8]>
  3. Blanket BlockSizeUser implementations for &T and &mut T preserve T::BlockSize across shared, mutable, and owned generic callers
  4. AddBlockSize, SubBlockSize, and ParBlocksSizeUser compose type-level block sizes from BlockSizeUser::BlockSize

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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

[[package]]
name = "crypto-common"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce6e4c961d6cd6c9a86db418387425e8bdeaf05b3c8bc1411e6dca4c252f1453"
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-crypto-common-block-size-user"
version = "1.0.0"
dependencies = [
 "crypto-common",
]

[[package]]
name = "typenum"
version = "1.20.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20"
Cargo.toml
[package]
name = "sample-crypto-common-block-size-user"
version = "1.0.0"
edition = "2021"
publish = false

[dependencies]
crypto-common = "=0.2.2"

[[bin]]
name = "contract"
path = "test/contract.rs"
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 crypto_common::BlockSizeUser in pkg:cargo/crypto-common@0.2.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/crypto-common@0.2.2
Demonstrate these symbols/APIs:
  - crypto_common::BlockSizeUser

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:d31fedf0724e2b66f1ec074a61938d53d31e00854d03ce84437d5ee255e478bc","contract":["Implementing BlockSizeUser with a typenum ArraySize sets BlockSize::USIZE and returns the byte count from block_size() via static dispatch (BlockSizeUser is not dyn-compatible because block_size has no self receiver)","Block\u003cB\u003e constructs a fixed-size hybrid_array::Array\u003cu8, B::BlockSize\u003e matching B::block_size() and rejects mismatched slice lengths in TryFrom\u003c\u0026[u8]\u003e","Blanket BlockSizeUser implementations for \u0026T and \u0026mut T preserve T::BlockSize across shared, mutable, and owned generic callers","AddBlockSize, SubBlockSize, and ParBlocksSizeUser compose type-level block sizes from BlockSizeUser::BlockSize"],"goal":"verify crypto_common::BlockSizeUser in pkg:cargo/crypto-common@0.2.2","kind":"HOW","packages":["pkg:cargo/crypto-common@0.2.2"],"schemaVersion":1,"symbols":["crypto_common::BlockSizeUser"]},"contractCommand":["cargo","run","--offline"],"environment":{"arch":"x64","distro":"alpine","ecosystem":"cargo","libc":"musl","os":"linux","packageManager":"cargo","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/crypto-common@0.2.2"],"schemaVersion":1,"subject":"pkg:cargo/crypto-common@0.2.2","symbols":["crypto_common::BlockSizeUser"],"verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify crypto_common::BlockSizeUser in pkg:cargo/crypto-common@0.2.2",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/crypto-common@0.2.2"
  ],
  "symbols": [
    "crypto_common::BlockSizeUser"
  ]
}
src/lib.rs
//! Minimal verification library for `crypto_common::BlockSizeUser`.

pub use crypto_common::BlockSizeUser;
test/contract.rs
use crypto_common::{
    AddBlockSize, Block, BlockSizeUser, ParBlocks, ParBlocksSizeUser, SubBlockSize,
    typenum::{U4, U8, U16, U24, U64, Unsigned},
};

struct BlockCipher128;

impl BlockSizeUser for BlockCipher128 {
    type BlockSize = U16;
}

impl ParBlocksSizeUser for BlockCipher128 {
    type ParBlocksSize = U4;
}

struct BlockHash512;

impl BlockSizeUser for BlockHash512 {
    type BlockSize = U64;
}

fn mask_block<B: BlockSizeUser>(_processor: B, block: &mut Block<B>, mask: u8) -> usize {
    for byte in block.as_mut_slice() {
        *byte ^= mask;
    }
    B::block_size()
}

fn main() {
    // 1. Implementing BlockSizeUser defines BlockSize (ArraySize) and derives block_size() via static dispatch
    assert_eq!(BlockCipher128::block_size(), 16);
    assert_eq!(<BlockCipher128 as BlockSizeUser>::BlockSize::USIZE, 16);
    assert_eq!(BlockHash512::block_size(), 64);
    assert_eq!(<BlockHash512 as BlockSizeUser>::BlockSize::USIZE, 64);

    // 2. Block<B> allocates a fixed-size hybrid_array::Array<u8, B::BlockSize> with exact slice conversion
    let mut block = Block::<BlockCipher128>::default();
    assert_eq!(block.len(), BlockCipher128::block_size());
    assert_eq!(block.as_slice(), &[0u8; 16]);

    let sample_bytes = [0xA5u8; 16];
    let borrowed_block =
        <&Block<BlockCipher128>>::try_from(sample_bytes.as_slice()).expect("exact 16-byte slice");
    assert_eq!(borrowed_block.as_slice(), &sample_bytes);
    assert!(<&Block<BlockCipher128>>::try_from(&[0u8; 15][..]).is_err());
    assert!(<&Block<BlockCipher128>>::try_from(&[0u8; 17][..]).is_err());

    // 3. Blanket BlockSizeUser impls on &T and &mut T preserve BlockSize for generic static dispatch
    assert_eq!(<&BlockCipher128 as BlockSizeUser>::block_size(), 16);
    assert_eq!(<&mut BlockCipher128 as BlockSizeUser>::block_size(), 16);
    assert_eq!(<&BlockHash512 as BlockSizeUser>::block_size(), 64);

    let mut cipher = BlockCipher128;
    assert_eq!(mask_block(&cipher, &mut block, 0x5A), 16);
    assert_eq!(block.as_slice(), &[0x5Au8; 16]);
    assert_eq!(mask_block(&mut cipher, &mut block, 0x5A), 16);
    assert_eq!(block.as_slice(), &[0x00u8; 16]);
    assert_eq!(mask_block(cipher, &mut block, 0xFF), 16);
    assert_eq!(block.as_slice(), &[0xFFu8; 16]);

    // 4. AddBlockSize, SubBlockSize, and ParBlocksSizeUser compose type-level sizes from BlockSizeUser
    assert_eq!(<AddBlockSize<U8, BlockCipher128> as Unsigned>::USIZE, 24);
    assert_eq!(<SubBlockSize<U24, BlockCipher128> as Unsigned>::USIZE, 8);

    let par_blocks = ParBlocks::<BlockCipher128>::default();
    assert_eq!(par_blocks.len(), 4);
    assert_eq!(par_blocks[0].len(), BlockCipher128::block_size());
}

Seeder de origen

anónimo