CodeSampleX

Ejemplo

pem 3.0.6: pem::encode_config

Muestra verificada para cargo pem 3.0.6: pem::encode_config. El contrato se ejecutó en rust 1 · linux alpine/x64 · docker y pasó.

sha256:01afb8a8b36c65b64cbff0097619cffd63d0646417b8457db7f54c959b42b9c4

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado linux · alpine · musl x64 cargo

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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-11-22

Caso

HOW
Objetivo
verify pem::encode_config in pkg:cargo/pem@3.0.6
Paquetes
Símbolos
  • pem::encode_config
Creado
2026-11-22T15:33:28Z

Contrato

  1. EncodeConfig::new and EncodeConfig::default use CRLF line endings and 64-character base64 line wrapping, matching pem::encode
  2. EncodeConfig::set_line_ending(LineEnding::LF) formats all lines with LF only and no CR characters
  3. EncodeConfig::set_line_wrap wraps base64 payload lines to custom chunk lengths and round-trips losslessly via pem::parse
  4. Headers added via Pem::headers_mut().add are emitted after the BEGIN line followed by a blank separator line using the configured LineEnding
  5. Empty Pem contents omit payload lines and emit only BEGIN and END framing with the configured LineEnding
  6. EncodeConfig::set_line_wrap(0) panics because base64 chunk size must be non-zero

Archivos

  • Cargo.lock
  • Cargo.toml
  • PROMPT.md
  • csx.json
  • spec.json
  • src/lib.rs
  • test/contract.rs

Descargar el artefacto de código fuente (tar.gz)

Código fuente

Cargo.lock
# 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 = "pem"
version = "3.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d30c53c26bc5b31a98cd02d20f25a7c8567146caf63ed593a9d87b2775291be"
dependencies = [
 "base64",
 "serde_core",
]

[[package]]
name = "proc-macro2"
version = "1.0.107"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
dependencies = [
 "unicode-ident",
]

[[package]]
name = "quote"
version = "1.0.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
dependencies = [
 "proc-macro2",
]

[[package]]
name = "sample-pem-encode-config"
version = "1.0.0"
dependencies = [
 "pem",
]

[[package]]
name = "serde_core"
version = "1.0.229"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
dependencies = [
 "serde_derive",
]

[[package]]
name = "serde_derive"
version = "1.0.229"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
dependencies = [
 "proc-macro2",
 "quote",
 "syn",
]

[[package]]
name = "syn"
version = "3.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79"
dependencies = [
 "proc-macro2",
 "quote",
 "unicode-ident",
]

[[package]]
name = "unicode-ident"
version = "1.0.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
Cargo.toml
[package]
name = "sample-pem-encode-config"
version = "1.0.0"
edition = "2021"
publish = false

[dependencies]
pem = "=3.0.6"

[[bin]]
name = "contract"
path = "test/contract.rs"
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 pem::encode_config in pkg:cargo/pem@3.0.6
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/pem@3.0.6
Demonstrate these symbols/APIs:
  - pem::encode_config

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:239eaf0aa21654f9c4fcd47f0ed855b762fdee901045182a5ba4557a3442e265","contract":["EncodeConfig::new and EncodeConfig::default use CRLF line endings and 64-character base64 line wrapping, matching pem::encode","EncodeConfig::set_line_ending(LineEnding::LF) formats all lines with LF only and no CR characters","EncodeConfig::set_line_wrap wraps base64 payload lines to custom chunk lengths and round-trips losslessly via pem::parse","Headers added via Pem::headers_mut().add are emitted after the BEGIN line followed by a blank separator line using the configured LineEnding","Empty Pem contents omit payload lines and emit only BEGIN and END framing with the configured LineEnding","EncodeConfig::set_line_wrap(0) panics because base64 chunk size must be non-zero"],"goal":"verify pem::encode_config in pkg:cargo/pem@3.0.6","kind":"HOW","packages":["pkg:cargo/pem@3.0.6"],"schemaVersion":1,"symbols":["pem::encode_config"]},"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/pem@3.0.6"],"schemaVersion":1,"subject":"pkg:cargo/pem@3.0.6","symbols":["pem::encode_config"],"verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pem::encode_config in pkg:cargo/pem@3.0.6",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/pem@3.0.6"
  ],
  "symbols": [
    "pem::encode_config"
  ]
}
src/lib.rs
//! Clean-room verification sample for `pem::encode_config`.

pub use pem::{encode_config, EncodeConfig, LineEnding, Pem};
test/contract.rs
use pem::{encode, encode_config, parse, EncodeConfig, LineEnding, Pem};
use std::panic::catch_unwind;

fn main() {
    let short_pem = Pem::new("TEST BLOCK", vec![1u8, 2, 3, 4]);

    // 1. Default EncodeConfig uses CRLF line endings and 64-char base64 line wrapping, matching pem::encode
    let default_new = encode_config(&short_pem, EncodeConfig::new());
    let default_trait = encode_config(&short_pem, EncodeConfig::default());
    assert_eq!(
        default_new,
        "-----BEGIN TEST BLOCK-----\r\nAQIDBA==\r\n-----END TEST BLOCK-----\r\n"
    );
    assert_eq!(default_new, default_trait);
    assert_eq!(default_new, encode(&short_pem));

    let payload_60: Vec<u8> = (0u8..60).collect();
    let long_pem = Pem::new("LONG BLOCK", payload_60.clone());
    let default_long = encode_config(&long_pem, EncodeConfig::new());
    let default_lines: Vec<&str> = default_long.split("\r\n").collect();
    assert_eq!(default_lines.len(), 5);
    assert_eq!(default_lines[0], "-----BEGIN LONG BLOCK-----");
    assert_eq!(default_lines[1].len(), 64);
    assert_eq!(default_lines[2].len(), 16);
    assert_eq!(default_lines[3], "-----END LONG BLOCK-----");
    assert_eq!(default_lines[4], "");

    // 2. EncodeConfig::set_line_ending(LineEnding::LF) emits LF-only output with no CR characters
    let lf_cfg = EncodeConfig::new().set_line_ending(LineEnding::LF);
    let lf_encoded = encode_config(&short_pem, lf_cfg);
    assert_eq!(
        lf_encoded,
        "-----BEGIN TEST BLOCK-----\nAQIDBA==\n-----END TEST BLOCK-----\n"
    );
    assert!(!lf_encoded.contains('\r'));
    let lf_decoded = parse(&lf_encoded).expect("LF output should parse");
    assert_eq!(lf_decoded, short_pem);

    // 3. EncodeConfig::set_line_wrap wraps base64 lines to custom widths and round-trips through pem::parse
    let wrap4_crlf = EncodeConfig::new().set_line_wrap(4);
    assert_eq!(
        encode_config(&short_pem, wrap4_crlf),
        "-----BEGIN TEST BLOCK-----\r\nAQID\r\nBA==\r\n-----END TEST BLOCK-----\r\n"
    );

    let wrap16_lf = EncodeConfig::new()
        .set_line_ending(LineEnding::LF)
        .set_line_wrap(16);
    let wrapped_long = encode_config(&long_pem, wrap16_lf);
    let wrapped_lines: Vec<&str> = wrapped_long.split('\n').collect();
    assert_eq!(wrapped_lines.len(), 8);
    assert_eq!(wrapped_lines[0], "-----BEGIN LONG BLOCK-----");
    for line in &wrapped_lines[1..6] {
        assert_eq!(line.len(), 16);
    }
    assert_eq!(wrapped_lines[6], "-----END LONG BLOCK-----");
    assert_eq!(wrapped_lines[7], "");
    let decoded_long = parse(&wrapped_long).expect("custom wrapped PEM should parse");
    assert_eq!(decoded_long.tag(), "LONG BLOCK");
    assert_eq!(decoded_long.contents(), payload_60.as_slice());

    // 4. Headers are emitted after BEGIN with a blank separator line using the configured line ending
    let mut hdr_pem = Pem::new("EXAMPLE MESSAGE", b"hello pem".to_vec());
    hdr_pem
        .headers_mut()
        .add("Proc-Type", "4,PLAIN")
        .expect("valid header");
    hdr_pem
        .headers_mut()
        .add("Content-Domain", "example.com")
        .expect("valid header");
    let hdr_encoded = encode_config(&hdr_pem, lf_cfg);
    assert_eq!(
        hdr_encoded,
        "-----BEGIN EXAMPLE MESSAGE-----\nProc-Type: 4,PLAIN\nContent-Domain: example.com\n\naGVsbG8gcGVt\n-----END EXAMPLE MESSAGE-----\n"
    );
    let hdr_decoded = parse(&hdr_encoded).expect("PEM with headers should parse");
    assert_eq!(hdr_decoded.tag(), "EXAMPLE MESSAGE");
    assert_eq!(hdr_decoded.headers().get("Proc-Type"), Some("4,PLAIN"));
    assert_eq!(
        hdr_decoded.headers().get("Content-Domain"),
        Some("example.com")
    );
    assert_eq!(hdr_decoded.contents(), b"hello pem");

    // 5. Empty contents omit payload lines and emit only BEGIN and END with the configured line ending
    let empty_pem = Pem::new("EMPTY BLOCK", Vec::<u8>::new());
    let empty_lf = encode_config(&empty_pem, lf_cfg);
    assert_eq!(
        empty_lf,
        "-----BEGIN EMPTY BLOCK-----\n-----END EMPTY BLOCK-----\n"
    );
    let empty_crlf = encode_config(
        &empty_pem,
        EncodeConfig::new().set_line_ending(LineEnding::CRLF),
    );
    assert_eq!(
        empty_crlf,
        "-----BEGIN EMPTY BLOCK-----\r\n-----END EMPTY BLOCK-----\r\n"
    );
    let empty_decoded = parse(&empty_lf).expect("empty PEM should parse");
    assert_eq!(empty_decoded.tag(), "EMPTY BLOCK");
    assert!(empty_decoded.contents().is_empty());

    // 6. set_line_wrap(0) panics because base64 chunk size must be non-zero
    let zero_wrap_result = catch_unwind(|| {
        let zero_cfg = EncodeConfig::new().set_line_wrap(0);
        let _ = encode_config(&short_pem, zero_cfg);
    });
    assert!(
        zero_wrap_result.is_err(),
        "set_line_wrap(0) must panic on zero chunk size"
    );

    println!("All pem::encode_config contract assertions passed.");
}

Seeder de origen

anónimo