CodeSampleX

Пример

ring 0.17.14: ring::digest::Context

Проверенный пример — cargo ring 0.17.14: ring::digest::Context. Контракт выполнен на rust 1 · linux alpine/x64 · docker и пройден.

sha256:3d19a99807e9aa3df4a91a330e7a5028fb765f2644d1f99708c69262d674a319

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. 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-20

Кейс

HOW
Цель
verify ring::digest::Context in pkg:cargo/ring@0.17.14
Пакеты
Символы
  • ring::digest::Context
Создан
2026-09-20T17:45:40Z

Контракт

  1. Context::new initializes a hashing context for the given digest algorithm
  2. Context::update accumulates data slices across single or multiple parts
  3. Context::finish completes hashing and matches one-shot digest output
  4. Context::algorithm returns the algorithm used to construct the context
  5. Context::clone creates an independent copy with preserved intermediate hashing state

Файлы

  • Cargo.lock
  • Cargo.toml
  • NOTES.md
  • 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 = "cc"
version = "1.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "54413ede23c2daf518f35156dfde027feb2374004d63bd497f983c8db9c0e313"
dependencies = [
 "find-msvc-tools",
 "shlex",
]

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

[[package]]
name = "find-msvc-tools"
version = "0.1.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef25905e51abafe4dcea6c15fec58c57b601cdbd0ee53d22ea1d3016c587d39b"

[[package]]
name = "getrandom"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0"
dependencies = [
 "cfg-if",
 "libc",
 "wasi",
]

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

[[package]]
name = "ring"
version = "0.17.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7"
dependencies = [
 "cc",
 "cfg-if",
 "getrandom",
 "libc",
 "untrusted",
 "windows-sys",
]

[[package]]
name = "sample-ring-digest"
version = "1.0.0"
dependencies = [
 "ring",
]

[[package]]
name = "shlex"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"

[[package]]
name = "untrusted"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1"

[[package]]
name = "wasi"
version = "0.11.1+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"

[[package]]
name = "windows-sys"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
dependencies = [
 "windows-targets",
]

[[package]]
name = "windows-targets"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
dependencies = [
 "windows_aarch64_gnullvm",
 "windows_aarch64_msvc",
 "windows_i686_gnu",
 "windows_i686_gnullvm",
 "windows_i686_msvc",
 "windows_x86_64_gnu",
 "windows_x86_64_gnullvm",
 "windows_x86_64_msvc",
]

[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"

[[package]]
name = "windows_aarch64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"

[[package]]
name = "windows_i686_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"

[[package]]
name = "windows_i686_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"

[[package]]
name = "windows_i686_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"

[[package]]
name = "windows_x86_64_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"

[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"

[[package]]
name = "windows_x86_64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
Cargo.toml
[package]
name = "sample-ring-digest"
version = "1.0.0"
edition = "2021"
publish = false

[dependencies]
ring = "=0.17.14"

[[bin]]
name = "contract"
path = "test/contract.rs"
NOTES.md
# ring 0.17.14 digest::Context API Contracts

## What `search_known_solution` answered
`search_known_solution` returned NO_SAFE_MATCH for `pkg:cargo/ring@0.17.14` and `ring::digest::Context`.

## What a model would have written instead
A model may treat `Algorithm::output_len` as a field instead of calling the accessor method `output_len()`, or fail to realize that `Context` implements `Clone` to branch hash calculations from an intermediate state.

## How the wrong version fails
Accessing `Algorithm::output_len` as a field fails with compiler error `E0616: field output_len of struct ring::digest::Algorithm is private`.
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 ring::digest::Context in pkg:cargo/ring@0.17.14
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/ring@0.17.14
Demonstrate these symbols/APIs:
  - ring::digest::Context

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:40b5d911d4e716e7cf3e72a6655bc9c7a1626367a39dc7e870df0a2f83e70e86","contract":["Context::new initializes a hashing context for the given digest algorithm","Context::update accumulates data slices across single or multiple parts","Context::finish completes hashing and matches one-shot digest output","Context::algorithm returns the algorithm used to construct the context","Context::clone creates an independent copy with preserved intermediate hashing state"],"goal":"verify ring::digest::Context in pkg:cargo/ring@0.17.14","kind":"HOW","packages":["pkg:cargo/ring@0.17.14"],"schemaVersion":1,"symbols":["ring::digest::Context"]},"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/ring@0.17.14"],"schemaVersion":1,"subject":"pkg:cargo/ring@0.17.14","symbols":["ring::digest::Context"],"verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify ring::digest::Context in pkg:cargo/ring@0.17.14",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/ring@0.17.14"
  ],
  "symbols": [
    "ring::digest::Context"
  ]
}
src/lib.rs
//! Clean-room verification sample for ring digest Context.

pub use ring::*;
test/contract.rs
use ring::digest::{self, Context, SHA256, SHA384, SHA512};

fn main() {
    // 1. Context::new initializes a hashing context for the given digest algorithm
    let mut ctx256 = Context::new(&SHA256);
    assert_eq!(ctx256.algorithm(), &SHA256);

    let ctx384 = Context::new(&SHA384);
    assert_eq!(ctx384.algorithm(), &SHA384);

    let ctx512 = Context::new(&SHA512);
    assert_eq!(ctx512.algorithm(), &SHA512);

    // 2. Context::update accumulates data slices across single or multiple parts
    let data_full = b"The quick brown fox jumps over the lazy dog";
    let part1 = b"The quick brown ";
    let part2 = b"fox jumps over ";
    let part3 = b"the lazy dog";

    ctx256.update(part1);
    ctx256.update(part2);
    ctx256.update(part3);

    // 3. Context::finish completes hashing and matches one-shot digest output
    let multi_part_digest = ctx256.finish();
    let one_shot_digest = digest::digest(&SHA256, data_full);

    assert_eq!(multi_part_digest.as_ref(), one_shot_digest.as_ref());
    assert_eq!(multi_part_digest.algorithm(), &SHA256);
    assert_eq!(multi_part_digest.as_ref().len(), SHA256.output_len());

    // Standard SHA-256 test vector for "The quick brown fox jumps over the lazy dog"
    let expected_sha256 = [
        0xd7, 0xa8, 0xfb, 0xb3, 0x07, 0xd7, 0x80, 0x94,
        0x69, 0xca, 0x9a, 0xbc, 0xb0, 0x08, 0x2e, 0x4f,
        0x8d, 0x56, 0x51, 0xe4, 0x6d, 0x3c, 0xdb, 0x76,
        0x2d, 0x02, 0xd0, 0xbf, 0x37, 0xc9, 0xe5, 0x92,
    ];
    assert_eq!(multi_part_digest.as_ref(), &expected_sha256);

    // 4. Context::algorithm returns the algorithm used to construct the context
    let ctx = Context::new(&SHA384);
    assert_eq!(ctx.algorithm(), &SHA384);
    assert_eq!(ctx.algorithm().output_len(), 48);

    // 5. Context::clone creates an independent copy with preserved intermediate hashing state
    let mut base_ctx = Context::new(&SHA256);
    base_ctx.update(b"common prefix: ");

    let mut branch_a = base_ctx.clone();
    let mut branch_b = base_ctx;

    branch_a.update(b"branch A data");
    branch_b.update(b"branch B data");

    let digest_a = branch_a.finish();
    let digest_b = branch_b.finish();

    let expected_a = digest::digest(&SHA256, b"common prefix: branch A data");
    let expected_b = digest::digest(&SHA256, b"common prefix: branch B data");

    assert_eq!(digest_a.as_ref(), expected_a.as_ref());
    assert_eq!(digest_b.as_ref(), expected_b.as_ref());
    assert_ne!(digest_a.as_ref(), digest_b.as_ref());

    println!("All ring::digest::Context contract assertions passed successfully.");
}

Исходный сидер

аноним