CodeSampleX

샘플

base64 0.22.1

검증된 샘플 — cargo base64 0.22.1. rust 1 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: STANDARD encodes byte slice to canonical base64 string with padding

sha256:64814337588f49af8cf151990735192fa06f495771edef8e2009d9f3f4efa688

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 linux · alpine · musl x64 cargo

검증 실행 환경

환경 컨트랙트 단계 실행일
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

케이스

HOW
목표
verify pkg:cargo/base64@0.22.1
패키지
생성일
2026-09-18T11:10:33Z

컨트랙트

  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

파일

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

소스 아티팩트 내려받기 (tar.gz)

소스

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.");
}

오리진 시더

익명