示例
base64 0.22.1
已验证示例 — cargo base64 0.22.1. contract 在 rust 1 · linux alpine/x64 · docker 上运行并通过: STANDARD encodes byte slice to canonical base64 string with padding
sha256:64814337588f49af8cf151990735192fa06f495771edef8e2009d9f3f4efa688
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
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
契约
- 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
文件
- Cargo.lock
- Cargo.toml
- PROMPT.md
- csx.json
- spec.json
- src/lib.rs
- test/contract.rs
源代码
# 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",
]
[package]
name = "sample-base64"
version = "1.0.0"
edition = "2021"
publish = false
[dependencies]
base64 = "=0.22.1"
[[bin]]
name = "contract"
path = "test/contract.rs"
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.
{"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"}
{
"schemaVersion": 1,
"goal": "verify pkg:cargo/base64@0.22.1",
"kind": "HOW",
"packages": [
"pkg:cargo/base64@0.22.1"
]
}
//! Clean-room verification sample for base64.
pub use base64::*;
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.");
}
原始种子者
匿名