CodeSampleX

Exemplo

base64 0.22.1

Amostra verificada para cargo base64 0.22.1. O contrato rodou em rust 1 · linux alpine/x64 · docker e passou: STANDARD encodes byte slice to canonical base64…

sha256:64814337588f49af8cf151990735192fa06f495771edef8e2009d9f3f4efa688

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 · alpine · musl 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-09-19

Caso

HOW
Objetivo
verify pkg:cargo/base64@0.22.1
Pacotes
Criado
2026-09-18T11:10:33Z

Contrato

  1. STANDARD encodes byte slice to canonical base64 string with padding
  2. STANDARD decodes valid base64 string with padding back to bytes
  3. STANDARD_NO_PAD encodes without padding and rejects input with padding
  4. URL_SAFE encodes using url-safe alphabet without plus or slash
  5. URL_SAFE_NO_PAD encodes and decodes url-safe base64 without padding
  6. decode returns InvalidLength error when base64 string has invalid length
  7. decode returns InvalidByte error when input contains non-base64 character
  8. encode_slice and decode_slice operate on preallocated buffers without allocation

Arquivos

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

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

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

[[package]]
name = "base64"
version = "0.22.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"

[[package]]
name = "sample-base64"
version = "1.0.0"
dependencies = [
 "base64",
]
Cargo.toml
[package]
name = "sample-base64"
version = "1.0.0"
edition = "2021"
publish = false

[dependencies]
base64 = "=0.22.1"

[[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 pkg:cargo/base64@0.22.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/base64@0.22.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.
csx.json
{"case":{"caseId":"case:sha256:13d15ba9610e39502a872fbf9b1fc4fad4166d7e443769b2dfb06b9ffcce5973","contract":["STANDARD encodes byte slice to canonical base64 string with padding","STANDARD decodes valid base64 string with padding back to bytes","STANDARD_NO_PAD encodes without padding and rejects input with padding","URL_SAFE encodes using url-safe alphabet without plus or slash","URL_SAFE_NO_PAD encodes and decodes url-safe base64 without padding","decode returns InvalidLength error when base64 string has invalid length","decode returns InvalidByte error when input contains non-base64 character","encode_slice and decode_slice operate on preallocated buffers without allocation"],"goal":"verify pkg:cargo/base64@0.22.1","kind":"HOW","packages":["pkg:cargo/base64@0.22.1"],"schemaVersion":1},"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/base64@0.22.1"],"schemaVersion":1,"subject":"pkg:cargo/base64@0.22.1","verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:cargo/base64@0.22.1",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/base64@0.22.1"
  ]
}
src/lib.rs
//! Clean-room verification sample for base64.

pub use base64::*;
test/contract.rs
use base64::engine::general_purpose::{
    STANDARD, STANDARD_NO_PAD, URL_SAFE, URL_SAFE_NO_PAD,
};
use base64::prelude::*;
use base64::DecodeError;

fn main() {
    // 1. STANDARD encodes byte slice to canonical base64 string with padding
    let data = b"Hello, CodeSampleX!";
    let encoded = STANDARD.encode(data);
    assert_eq!(encoded, "SGVsbG8sIENvZGVTYW1wbGVYIQ==");

    // 2. STANDARD decodes valid base64 string with padding back to bytes
    let decoded = STANDARD.decode(&encoded).expect("valid decode");
    assert_eq!(decoded, data);

    // 3. STANDARD_NO_PAD encodes without padding and rejects input with padding
    let encoded_no_pad = STANDARD_NO_PAD.encode(data);
    assert_eq!(encoded_no_pad, "SGVsbG8sIENvZGVTYW1wbGVYIQ");
    let pad_err = STANDARD_NO_PAD.decode(&encoded);
    assert_eq!(pad_err, Err(DecodeError::InvalidPadding));

    // 4. URL_SAFE encodes using url-safe alphabet without plus or slash
    let url_data = b"\xfb\xff\xfe\x00\x01";
    let url_encoded = URL_SAFE.encode(url_data);
    assert!(!url_encoded.contains('+'));
    assert!(!url_encoded.contains('/'));
    assert_eq!(URL_SAFE.decode(&url_encoded).unwrap(), url_data);

    // 5. URL_SAFE_NO_PAD encodes and decodes url-safe base64 without padding
    let url_no_pad = URL_SAFE_NO_PAD.encode(url_data);
    assert!(!url_no_pad.contains('='));
    assert_eq!(URL_SAFE_NO_PAD.decode(&url_no_pad).unwrap(), url_data);

    // 6. decode returns InvalidLength error when base64 string has invalid length
    let invalid_len = STANDARD.decode("A");
    assert_eq!(invalid_len, Err(DecodeError::InvalidLength(1)));

    // 7. decode returns InvalidByte error when input contains non-base64 character
    let invalid_byte = STANDARD.decode("SGVsbG8*");
    assert_eq!(invalid_byte, Err(DecodeError::InvalidByte(7, b'*')));

    // 8. encode_slice and decode_slice operate on preallocated buffers without allocation
    let mut enc_buf = [0u8; 32];
    let enc_len = STANDARD.encode_slice(b"test", &mut enc_buf).expect("encode slice");
    assert_eq!(&enc_buf[..enc_len], b"dGVzdA==");

    let mut dec_buf = [0u8; 4];
    let dec_len = STANDARD.decode_slice(b"dGVzdA==", &mut dec_buf).expect("decode slice");
    assert_eq!(dec_len, 4);
    assert_eq!(&dec_buf, b"test");

    println!("All base64 contract assertions passed successfully.");
}

Seeder de origem

anônimo