Beispiel
rand_core 0.9.5: rand_core::RngCore
Verifiziertes Beispiel für cargo rand_core 0.9.5: rand_core::RngCore. Der Vertrag lief auf rust 1 · linux alpine/x64 · docker und bestand.
sha256:de76a77361dbeec808576814dcd0bbf71e20138ebb473dbe2834032c93f57f4c
Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen.
Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen.
MIT-0
Ausführungsbelege
Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.
- Beleggrundlage
- Signierter Vertrag bestanden
- Verifizierungsbelege
- 1
- Signaturschlüssel, die es gebaut haben
- 1
Deklarierte Umgebung
linux · alpine · musl x64 cargo
Umgebungen der Verifizierungsläufe
| Umgebung | Contract | Stufen | Lauf |
|---|---|---|---|
| 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-10-13 |
Fall
HOW- Ziel
- verify rand_core::RngCore in pkg:cargo/rand_core@0.9.5
- Pakete
- Symbole
-
- rand_core::RngCore
- Erstellt
- 2026-10-13T04:00:38Z
Contract
- Custom generator implements RngCore generating expected u32 and u64 sequences
- impls::fill_bytes_via_next fills byte slices in little-endian order
- Mutable references to RngCore implement RngCore transparently
- RngCore automatically implements TryRngCore with infallible results
- UnwrapErr wraps fallible generators into standard RngCore
Dateien
- Cargo.lock
- Cargo.toml
- PROMPT.md
- csx.json
- spec.json
- src/lib.rs
- test/contract.rs
Quelltext
# 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 rand_core::RngCore in pkg:cargo/rand_core@0.9.5
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:cargo/rand_core@0.9.5
Demonstrate these symbols/APIs:
- rand_core::RngCore
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:f9bb217aa0e7c56e7668487c086f12f81a734bbb4fa92821aac23563e42aaf57","contract":["Custom generator implements RngCore generating expected u32 and u64 sequences","impls::fill_bytes_via_next fills byte slices in little-endian order","Mutable references to RngCore implement RngCore transparently","RngCore automatically implements TryRngCore with infallible results","UnwrapErr wraps fallible generators into standard RngCore"],"goal":"verify rand_core::RngCore in pkg:cargo/rand_core@0.9.5","kind":"HOW","packages":["pkg:cargo/rand_core@0.9.5"],"schemaVersion":1,"symbols":["rand_core::RngCore"]},"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","symbols":["rand_core::RngCore"],"verifierAdapter":"cargo@1"}
{
"schemaVersion": 1,
"goal": "verify rand_core::RngCore in pkg:cargo/rand_core@0.9.5",
"kind": "HOW",
"packages": [
"pkg:cargo/rand_core@0.9.5"
],
"symbols": [
"rand_core::RngCore"
]
}
//! Clean-room verification sample for rand_core.
pub use rand_core::*;
use rand_core::{impls, RngCore, TryRngCore, UnwrapErr};
struct StepRng {
val: u64,
step: u64,
}
impl StepRng {
fn new(initial: u64, step: u64) -> Self {
Self { val: initial, step }
}
}
impl RngCore for StepRng {
fn next_u32(&mut self) -> u32 {
self.next_u64() as u32
}
fn next_u64(&mut self) -> u64 {
let res = self.val;
self.val = self.val.wrapping_add(self.step);
res
}
fn fill_bytes(&mut self, dest: &mut [u8]) {
impls::fill_bytes_via_next(self, dest);
}
}
#[derive(Debug)]
struct MockError;
impl core::fmt::Display for MockError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "MockError")
}
}
struct FallibleRng(u64);
impl TryRngCore for FallibleRng {
type Error = MockError;
fn try_next_u32(&mut self) -> Result<u32, Self::Error> {
Ok(self.0 as u32)
}
fn try_next_u64(&mut self) -> Result<u64, Self::Error> {
Ok(self.0)
}
fn try_fill_bytes(&mut self, dst: &mut [u8]) -> Result<(), Self::Error> {
for b in dst.iter_mut() {
*b = 0xAA;
}
Ok(())
}
}
fn generate_from_rng<R: RngCore + ?Sized>(rng: &mut R) -> u64 {
rng.next_u64()
}
fn main() {
// 1. Custom generator implements RngCore generating expected u32 and u64 sequences
let mut rng = StepRng::new(10, 5);
assert_eq!(rng.next_u64(), 10);
assert_eq!(rng.next_u64(), 15);
assert_eq!(rng.next_u32(), 20);
assert_eq!(rng.next_u32(), 25);
// 2. impls::fill_bytes_via_next fills byte slices in little-endian order
let mut fill_rng = StepRng::new(0x0102030405060708, 0);
let mut buf = [0u8; 8];
fill_rng.fill_bytes(&mut buf);
assert_eq!(buf, [0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01]);
// 3. Mutable references to RngCore implement RngCore transparently
let mut base_rng = StepRng::new(100, 1);
let mut ref_rng = &mut base_rng;
let val = generate_from_rng(&mut ref_rng);
assert_eq!(val, 100);
assert_eq!(base_rng.next_u64(), 101);
// 4. RngCore automatically implements TryRngCore with infallible results
let mut try_rng = StepRng::new(42, 1);
assert_eq!(try_rng.try_next_u32().unwrap(), 42);
assert_eq!(try_rng.try_next_u64().unwrap(), 43);
let mut dest = [0u8; 4];
assert!(try_rng.try_fill_bytes(&mut dest).is_ok());
// 5. UnwrapErr wraps fallible generators into standard RngCore
let fallible = FallibleRng(777);
let mut unwrapped = UnwrapErr(fallible);
assert_eq!(unwrapped.next_u64(), 777);
assert_eq!(unwrapped.next_u32(), 777);
let mut unwrap_buf = [0u8; 4];
unwrapped.fill_bytes(&mut unwrap_buf);
assert_eq!(unwrap_buf, [0xAA, 0xAA, 0xAA, 0xAA]);
println!("All rand_core::RngCore contract assertions passed successfully.");
}
Ursprungs-Seeder
anonym