CodeSampleX

Exemple

getrandom 0.3.4: getrandom 0.3 replaces getrandom::getrandom and js/custom cargo features with getrandom::fill and --cfg getrandom_backend="custom" linking __getrandom_v03_custom

Échantillon vérifié pour cargo getrandom 0.3.4: getrandom 0.3 replaces getrandom::getrandom and js/custom cargo features with getrandom::fill and --cfg…

sha256:c2eb1cbf62ff348c61fce622c4530f916dcacb95669348c5545ad7c5a4153384

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
3
Clés de signature qui l’ont compilé
3
Environnement déclaré rust linux x64 rust rust cargo

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
rust 1 · linux alpine/x64 · docker ed25519:ac1544ece1e22594 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · cargo@1
2026-08-15
rust 1 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · cargo@1
2026-08-18
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-08

Cas

HOW
Objectif
getrandom 0.3 replaces getrandom::getrandom and js/custom cargo features with getrandom::fill and --cfg getrandom_backend="custom" linking __getrandom_v03_custom
Paquets
Symboles
  • getrandom::fill
  • getrandom::fill_uninit
  • getrandom::u32
  • __getrandom_v03_custom
Environnement
rust
Créé
2026-08-15T03:17:23Z

Contrat

  1. assert getrandom::fill routes to __getrandom_v03_custom when compiled with --cfg getrandom_backend="custom"
  2. assert getrandom::fill_uninit initializes buffer via __getrandom_v03_custom
  3. assert getrandom::u32 reads random bytes via __getrandom_v03_custom

Fichiers

  • .cargo/config.toml
  • .gitignore
  • Cargo.lock
  • Cargo.toml
  • NOTES.md
  • csx.json
  • src/lib.rs

Télécharger l’artefact source (tar.gz)

Code source

.cargo/config.toml
[build]
rustflags = ["--cfg", "getrandom_backend=\"custom\""]
.gitignore
/target
Cargo.lock
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4

[[package]]
name = "cfg-if"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"

[[package]]
name = "getrandom"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd"
dependencies = [
 "cfg-if",
 "libc",
 "r-efi",
 "wasip2",
]

[[package]]
name = "libc"
version = "0.2.189"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2"

[[package]]
name = "r-efi"
version = "5.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"

[[package]]
name = "sample-getrandom"
version = "0.1.0"
dependencies = [
 "getrandom",
]

[[package]]
name = "wasip2"
version = "1.0.4+wasi-0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b67efb37e106e55ce722a510d6b5f9c17f083e5fc79afc2badeb12cc313d9487"
dependencies = [
 "wit-bindgen",
]

[[package]]
name = "wit-bindgen"
version = "0.57.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e"
Cargo.toml
[package]
name = "sample-getrandom"
version = "0.1.0"
edition = "2021"

[dependencies]
getrandom = "0.3.4"
NOTES.md
A model would write `getrandom = { version = "0.3", features = ["js"] }` or `features = ["custom"]` and call `getrandom::getrandom(&mut buf)` with `register_custom_getrandom!`.
Fails loudly at compile time: cargo errors that features "js"/"custom" do not exist in getrandom 0.3, rustc fails with E0425 (`getrandom::getrandom` does not exist; use `getrandom::fill`), and `register_custom_getrandom!` is an unresolved macro.
csx.json
{"case":{"caseId":"case:sha256:d40729c4d65ec1524cd4fe110131aaea42750daf1ea364a840c3192614b582d9","constraints":{"runtime":"rust"},"contract":["assert getrandom::fill routes to __getrandom_v03_custom when compiled with --cfg getrandom_backend=\"custom\"","assert getrandom::fill_uninit initializes buffer via __getrandom_v03_custom","assert getrandom::u32 reads random bytes via __getrandom_v03_custom"],"goal":"getrandom 0.3 replaces getrandom::getrandom and js/custom cargo features with getrandom::fill and --cfg getrandom_backend=\"custom\" linking __getrandom_v03_custom","kind":"HOW","packages":["pkg:cargo/getrandom@0.3.4"],"schemaVersion":1,"symbols":["getrandom::fill","getrandom::fill_uninit","getrandom::u32","__getrandom_v03_custom"]},"contractCommand":["cargo","test","--offline"],"environment":{"arch":"x64","ecosystem":"cargo","executionContext":"rust","language":"rust","os":"linux","packageManager":"cargo","runtime":"rust","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/getrandom@0.3.4"],"schemaVersion":1,"symbols":["getrandom::fill","getrandom::fill_uninit","getrandom::u32","__getrandom_v03_custom"],"verifierAdapter":"cargo@1"}
src/lib.rs
use getrandom::Error;

/// Custom backend implementation for getrandom v0.3.
/// When compiled with `--cfg getrandom_backend="custom"`, getrandom delegates
/// all entropy requests (`fill`, `fill_uninit`, `u32`, `u64`) to this symbol.
#[no_mangle]
unsafe extern "Rust" fn __getrandom_v03_custom(dest: *mut u8, len: usize) -> Result<(), Error> {
    unsafe {
        for i in 0..len {
            *dest.add(i) = 0x5A ^ (i as u8);
        }
    }
    Ok(())
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_custom_backend_routing() {
        let mut buf = [0u8; 8];
        getrandom::fill(&mut buf).expect("fill should succeed via custom backend");

        let expected: [u8; 8] = [
            0x5A ^ 0,
            0x5A ^ 1,
            0x5A ^ 2,
            0x5A ^ 3,
            0x5A ^ 4,
            0x5A ^ 5,
            0x5A ^ 6,
            0x5A ^ 7,
        ];
        assert_eq!(
            buf, expected,
            "getrandom::fill must route to __getrandom_v03_custom"
        );

        let mut uninit_buf = [std::mem::MaybeUninit::uninit(); 4];
        let slice = getrandom::fill_uninit(&mut uninit_buf)
            .expect("fill_uninit should succeed via custom backend");
        assert_eq!(
            slice,
            &expected[..4],
            "getrandom::fill_uninit must initialize slice via __getrandom_v03_custom"
        );

        let val = getrandom::u32().expect("u32 should succeed via custom backend");
        let expected_u32 = u32::from_ne_bytes([0x5A ^ 0, 0x5A ^ 1, 0x5A ^ 2, 0x5A ^ 3]);
        assert_eq!(
            val, expected_u32,
            "getrandom::u32 must derive value from custom backend"
        );
    }
}

Seeder d'origine

anonymous