示例
rand_core 0.9.5
已验证示例 — cargo rand_core 0.9.5. contract 在 rust 1 · linux alpine/x64 · docker 上运行并通过: RngCore next_u32 and next_u64 produce expected sequential values
sha256:ab17eb7f08d5f435996186ca0224cb02dfefdc63b9e4973c8fa63a29663f3f4c
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 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/rand_core@0.9.5
- 创建时间
- 2026-09-19T02:51:54Z
契约
- RngCore next_u32 and next_u64 produce expected sequential values
- RngCore fill_bytes populates buffer using helper
- SeedableRng seed_from_u64 initializes deterministic generator
- TryRngCore blanket implementation for RngCore provides infallible try_fill_bytes
- UnwrapMut wraps TryRngCore and reborrows correctly
文件
- 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 = "rand_core"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c"
[[package]]
name = "sample-rand-core"
version = "1.0.0"
dependencies = [
"rand_core",
]
[package]
name = "sample-rand-core"
version = "1.0.0"
edition = "2021"
publish = false
[dependencies]
rand_core = "=0.9.5"
[[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/rand_core@0.9.5
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:cargo/rand_core@0.9.5
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:f6e294e43dc44e91501dbaa5f58f38a4c7f622c963b8924cf20166bdb1175ed9","contract":["RngCore next_u32 and next_u64 produce expected sequential values","RngCore fill_bytes populates buffer using helper","SeedableRng seed_from_u64 initializes deterministic generator","TryRngCore blanket implementation for RngCore provides infallible try_fill_bytes","UnwrapMut wraps TryRngCore and reborrows correctly"],"goal":"verify pkg:cargo/rand_core@0.9.5","kind":"HOW","packages":["pkg:cargo/rand_core@0.9.5"],"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/rand_core@0.9.5"],"schemaVersion":1,"subject":"pkg:cargo/rand_core@0.9.5","verifierAdapter":"cargo@1"}
{
"schemaVersion": 1,
"goal": "verify pkg:cargo/rand_core@0.9.5",
"kind": "HOW",
"packages": [
"pkg:cargo/rand_core@0.9.5"
]
}
//! Clean-room verification sample for rand_core.
pub use rand_core::*;
use rand_core::{RngCore, SeedableRng, TryRngCore, impls, le};
struct StepRng(u64);
impl RngCore for StepRng {
fn next_u32(&mut self) -> u32 {
self.next_u64() as u32
}
fn next_u64(&mut self) -> u64 {
let val = self.0;
self.0 = self.0.wrapping_add(1);
val
}
fn fill_bytes(&mut self, dst: &mut [u8]) {
impls::fill_bytes_via_next(self, dst);
}
}
struct SeedableNum(u64);
impl RngCore for SeedableNum {
fn next_u32(&mut self) -> u32 {
self.next_u64() as u32
}
fn next_u64(&mut self) -> u64 {
let val = self.0;
self.0 = self.0.wrapping_add(1);
val
}
fn fill_bytes(&mut self, dst: &mut [u8]) {
impls::fill_bytes_via_next(self, dst);
}
}
impl SeedableRng for SeedableNum {
type Seed = [u8; 8];
fn from_seed(seed: Self::Seed) -> Self {
let mut x = [0u64; 1];
le::read_u64_into(&seed, &mut x);
SeedableNum(x[0])
}
}
fn main() {
// 1. RngCore next_u32 and next_u64 produce expected sequential values
let mut rng = StepRng(100);
assert_eq!(rng.next_u64(), 100);
assert_eq!(rng.next_u64(), 101);
assert_eq!(rng.next_u32(), 102);
// 2. RngCore fill_bytes populates buffer using helper
let mut buf = [0u8; 8];
let mut rng2 = StepRng(1);
rng2.fill_bytes(&mut buf);
assert_eq!(buf, [1, 0, 0, 0, 0, 0, 0, 0]);
// 3. SeedableRng seed_from_u64 initializes deterministic generator
let mut seeded = SeedableNum::seed_from_u64(42);
let val1 = seeded.next_u64();
let mut seeded2 = SeedableNum::seed_from_u64(42);
let val2 = seeded2.next_u64();
assert_eq!(val1, val2);
// 4. TryRngCore blanket implementation for RngCore provides infallible try_fill_bytes
let mut try_buf = [0u8; 4];
let mut rng3 = StepRng(5);
assert!(rng3.try_fill_bytes(&mut try_buf).is_ok());
// 5. UnwrapMut wraps TryRngCore and reborrows correctly
let mut rng4 = StepRng(10);
let mut unwrapped = rng4.unwrap_mut();
assert_eq!(unwrapped.next_u64(), 10);
let mut reborrowed = unwrapped.re();
assert_eq!(reborrowed.next_u64(), 11);
println!("All rand_core contract assertions passed successfully.");
}
原始种子者
匿名