CodeSampleX

Exemple

cipher 0.5.2: cipher::Block

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

sha256:07644334c12b3d96bf73f6b0b93e3ec20ec9b2229f34b70ad57eae2698f84ec3

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-09

Cas

HOW
Objectif
verify cipher::Block in pkg:cargo/cipher@0.5.2
Paquets
Symboles
  • cipher::Block
Créé
2026-11-09T04:03:26Z

Contrat

  1. cipher::Block<B> resolves to hybrid_array::Array<u8, <B as BlockSizeUser>::BlockSize> with length equal to B::block_size()
  2. cipher::Block<B>::default() produces a zero-filled block array of length B::BlockSize::USIZE
  3. cipher::Block<&B> and cipher::Block<&mut B> resolve to the same block array type as cipher::Block<B> via blanket BlockSizeUser implementations
  4. <&cipher::Block<B>>::try_from(&[u8]) returns Ok(&Block<B>) when slice length equals B::block_size() and Err when slice length differs
  5. cipher::Block<B> integrates with BlockCipherEncrypt and BlockCipherDecrypt for in-place, buffer-to-buffer, and multi-block encryption and decryption

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 = "cipher"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8cf2a2c93cd704877c0858356ed03480ff301ee950b43f1cbe4573b088bfa6c"
dependencies = [
 "crypto-common",
 "inout",
]

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

[[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 = "inout"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a580c13f0ffc335ef42dd3f6b1a41b726051c5e1656d9a3aa6fddb3c5dfbbf9"
dependencies = [
 "hybrid-array",
]

[[package]]
name = "typenum"
version = "1.20.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20"
Cargo.toml
[package]
name = "cipher-block-sample"
version = "0.1.0"
edition = "2021"

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

[dependencies]
cipher = "=0.5.2"
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 cipher::Block in pkg:cargo/cipher@0.5.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/cipher@0.5.2
Demonstrate these symbols/APIs:
  - cipher::Block

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:6cfa1bf2f308b4dd9a387916b9bd015e96da444901d571d644972aa09d3b78e2","contract":["cipher::Block\u003cB\u003e resolves to hybrid_array::Array\u003cu8, \u003cB as BlockSizeUser\u003e::BlockSize\u003e with length equal to B::block_size()","cipher::Block\u003cB\u003e::default() produces a zero-filled block array of length B::BlockSize::USIZE","cipher::Block\u003c\u0026B\u003e and cipher::Block\u003c\u0026mut B\u003e resolve to the same block array type as cipher::Block\u003cB\u003e via blanket BlockSizeUser implementations","\u003c\u0026cipher::Block\u003cB\u003e\u003e::try_from(\u0026[u8]) returns Ok(\u0026Block\u003cB\u003e) when slice length equals B::block_size() and Err when slice length differs","cipher::Block\u003cB\u003e integrates with BlockCipherEncrypt and BlockCipherDecrypt for in-place, buffer-to-buffer, and multi-block encryption and decryption"],"goal":"verify cipher::Block in pkg:cargo/cipher@0.5.2","kind":"HOW","packages":["pkg:cargo/cipher@0.5.2"],"schemaVersion":1,"symbols":["cipher::Block"]},"contractCommand":["cargo","run","--offline"],"environment":{"arch":"x64","ecosystem":"cargo","os":"linux","packageManager":"cargo","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/cipher@0.5.2"],"schemaVersion":1,"subject":"pkg:cargo/cipher@0.5.2","symbols":["cipher::Block"],"verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify cipher::Block in pkg:cargo/cipher@0.5.2",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/cipher@0.5.2"
  ],
  "symbols": [
    "cipher::Block"
  ]
}
test/contract.rs
use cipher::{
    Block, BlockCipherDecBackend, BlockCipherDecClosure, BlockCipherDecrypt,
    BlockCipherEncBackend, BlockCipherEncClosure, BlockCipherEncrypt, BlockSizeUser, InOut,
    ParBlocksSizeUser,
    consts::{U1, U8},
};

struct XorBlockCipher {
    key: Block<Self>,
}

impl BlockSizeUser for XorBlockCipher {
    type BlockSize = U8;
}

impl ParBlocksSizeUser for XorBlockCipher {
    type ParBlocksSize = U1;
}

impl BlockCipherEncBackend for XorBlockCipher {
    fn encrypt_block(&self, mut block: InOut<'_, '_, Block<Self>>) {
        block.xor_in2out(&self.key);
    }
}

impl BlockCipherDecBackend for XorBlockCipher {
    fn decrypt_block(&self, mut block: InOut<'_, '_, Block<Self>>) {
        block.xor_in2out(&self.key);
    }
}

impl BlockCipherEncrypt for XorBlockCipher {
    fn encrypt_with_backend(&self, f: impl BlockCipherEncClosure<BlockSize = Self::BlockSize>) {
        f.call(self);
    }
}

impl BlockCipherDecrypt for XorBlockCipher {
    fn decrypt_with_backend(&self, f: impl BlockCipherDecClosure<BlockSize = Self::BlockSize>) {
        f.call(self);
    }
}

fn main() {
    // 1. Default cipher::Block<B> initializes a zero-filled Array<u8, B::BlockSize>
    let zero_block: Block<XorBlockCipher> = Block::<XorBlockCipher>::default();
    assert_eq!(zero_block.len(), XorBlockCipher::block_size());
    assert_eq!(zero_block.len(), 8);
    assert_eq!(zero_block.as_slice(), &[0u8; 8]);

    // 2. Blanket BlockSizeUser impls on &B and &mut B yield identical Block<B> array types
    let plain_bytes = [0x10u8, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80];
    let block_val: Block<XorBlockCipher> = Block::<XorBlockCipher>::from(plain_bytes);
    let block_ref: Block<&XorBlockCipher> = block_val;
    let block_mut: Block<&mut XorBlockCipher> = block_ref;
    assert_eq!(block_mut.as_slice(), &plain_bytes);

    // 3. Slice conversion to &Block<B> succeeds on exact BlockSize and fails otherwise
    let from_exact = <&Block<XorBlockCipher>>::try_from(&plain_bytes[..]);
    assert!(from_exact.is_ok());
    assert_eq!(from_exact.unwrap().as_slice(), &plain_bytes);

    let from_short = <&Block<XorBlockCipher>>::try_from(&plain_bytes[..7]);
    assert!(from_short.is_err());

    // 4. Block<B> works with BlockCipherEncrypt and BlockCipherDecrypt (in-place, b2b, and slice of blocks)
    let cipher = XorBlockCipher {
        key: Block::<XorBlockCipher>::from([0xAA, 0x55, 0xFF, 0x00, 0x12, 0x34, 0x56, 0x78]),
    };

    let mut inplace_block: Block<XorBlockCipher> = Block::<XorBlockCipher>::from(plain_bytes);
    BlockCipherEncrypt::encrypt_block(&cipher, &mut inplace_block);
    assert_eq!(
        inplace_block.as_slice(),
        &[0xBA, 0x75, 0xCF, 0x40, 0x42, 0x54, 0x26, 0xF8]
    );

    let mut b2b_out: Block<XorBlockCipher> = Block::<XorBlockCipher>::default();
    cipher.encrypt_block_b2b(&block_val, &mut b2b_out);
    assert_eq!(b2b_out, inplace_block);

    BlockCipherDecrypt::decrypt_block(&cipher, &mut inplace_block);
    assert_eq!(inplace_block, block_val);

    let mut multi_blocks: [Block<XorBlockCipher>; 2] = [
        Block::<XorBlockCipher>::from([1, 2, 3, 4, 5, 6, 7, 8]),
        Block::<XorBlockCipher>::from([8, 7, 6, 5, 4, 3, 2, 1]),
    ];
    let orig_blocks = multi_blocks;
    cipher.encrypt_blocks(&mut multi_blocks);
    assert_ne!(multi_blocks, orig_blocks);
    cipher.decrypt_blocks(&mut multi_blocks);
    assert_eq!(multi_blocks, orig_blocks);
}

Seeder d'origine

anonyme