サンプル
pem 3.0.6: pem::encode_many_config
検証済みサンプル — cargo pem 3.0.6: pem::encode_many_config. rust 1 · linux alpine/x64 · docker で contract を実行し、成功しました: pem::encode_many_config with…
sha256:9d438cde72135902c547696e2b6800924a975142293c377f4ade7ba5b8e56c7b
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
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-11-22 |
ケース
HOW- ゴール
- verify pem::encode_many_config in pkg:cargo/pem@3.0.6
- パッケージ
- シンボル
-
- pem::encode_many_config
- 作成日
- 2026-11-22T16:11:33Z
コントラクト
- pem::encode_many_config with EncodeConfig::default uses CRLF line endings, wraps base64 lines at 64 characters, and separates blocks with a blank CRLF line
- pem::encode_many_config applies configured LineEnding::LF and custom set_line_wrap consistently across every block and block separator without CR bytes
- pem::encode_many_config preserves Pem headers before a blank line, encodes empty contents without body lines, and round-trips through pem::parse_many
- pem::encode_many_config returns an empty String when given an empty Pem slice
ファイル
- 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 = "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-many-config"
version = "0.1.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"
[package]
name = "sample-pem-encode-many-config"
version = "0.1.0"
edition = "2021"
publish = false
[dependencies]
pem = "=3.0.6"
[[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 pem::encode_many_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_many_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.
{"case":{"caseId":"case:sha256:daf8dc28cfff42e81337c73dbc9edabbd7c095ca6514a9dd4ef109ce543276c9","contract":["pem::encode_many_config with EncodeConfig::default uses CRLF line endings, wraps base64 lines at 64 characters, and separates blocks with a blank CRLF line","pem::encode_many_config applies configured LineEnding::LF and custom set_line_wrap consistently across every block and block separator without CR bytes","pem::encode_many_config preserves Pem headers before a blank line, encodes empty contents without body lines, and round-trips through pem::parse_many","pem::encode_many_config returns an empty String when given an empty Pem slice"],"goal":"verify pem::encode_many_config in pkg:cargo/pem@3.0.6","kind":"HOW","packages":["pkg:cargo/pem@3.0.6"],"schemaVersion":1,"symbols":["pem::encode_many_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_many_config"],"verifierAdapter":"cargo@1"}
{
"schemaVersion": 1,
"goal": "verify pem::encode_many_config in pkg:cargo/pem@3.0.6",
"kind": "HOW",
"packages": [
"pkg:cargo/pem@3.0.6"
],
"symbols": [
"pem::encode_many_config"
]
}
use pem::{encode_many_config, EncodeConfig, LineEnding, Pem};
/// Encode a slice of PEM blocks with explicit line ending and line wrap settings.
pub fn encode_bundle(pems: &[Pem], line_ending: LineEnding, line_wrap: usize) -> String {
let config = EncodeConfig::new()
.set_line_ending(line_ending)
.set_line_wrap(line_wrap);
encode_many_config(pems, config)
}
use pem::{encode_many_config, parse_many, EncodeConfig, LineEnding, Pem};
use sample_pem_encode_many_config::encode_bundle;
fn main() {
// 1. Default EncodeConfig uses CRLF line endings, 64-char base64 wrap, and CRLF between blocks.
let payload_a: Vec<u8> = (0u8..60).collect(); // 60 bytes -> 80 base64 chars (wraps at 64 + 16)
let payload_b: Vec<u8> = vec![1, 2, 3, 4]; // 4 bytes -> "AQIDBA=="
let blocks = vec![
Pem::new("FIRST BLOCK", payload_a.clone()),
Pem::new("SECOND BLOCK", payload_b.clone()),
];
let default_encoded = encode_many_config(&blocks, EncodeConfig::default());
assert!(
default_encoded.contains("\r\n\r\n-----BEGIN SECOND BLOCK-----\r\n"),
"default config must separate blocks with a blank CRLF line"
);
assert!(
default_encoded.ends_with("-----END SECOND BLOCK-----\r\n"),
"default config must terminate final block with CRLF"
);
for line in default_encoded.split("\r\n") {
if !line.starts_with("-----") && !line.is_empty() {
assert!(
line.len() <= 64,
"default line wrap must cap base64 lines at 64 chars, got {}",
line.len()
);
}
}
let parsed_default = parse_many(&default_encoded).expect("default output must parse back");
assert_eq!(parsed_default, blocks);
// 2. LF line endings and custom line_wrap apply uniformly to every block and separator.
let lf_wrap_16 = encode_bundle(&blocks, LineEnding::LF, 16);
assert!(
!lf_wrap_16.contains('\r'),
"LF config must not emit any CR characters"
);
assert!(
lf_wrap_16.contains("-----END FIRST BLOCK-----\n\n-----BEGIN SECOND BLOCK-----\n"),
"LF config must join blocks with a blank LF line"
);
let first_body_lines: Vec<&str> = lf_wrap_16
.lines()
.skip(1)
.take_while(|line| !line.starts_with("-----END"))
.collect();
// 80 base64 chars wrapped at 16 -> 5 lines of 16 chars each.
assert_eq!(first_body_lines.len(), 5);
assert!(first_body_lines.iter().all(|line| line.len() == 16));
// Custom wrap shorter than the second block's 8-char base64 body ("AQIDBA==" -> "AQID" + "BA==").
let lf_wrap_4 = encode_many_config(
&[Pem::new("SHORT", vec![1, 2, 3, 4])],
EncodeConfig::new()
.set_line_ending(LineEnding::LF)
.set_line_wrap(4),
);
assert_eq!(
lf_wrap_4,
"-----BEGIN SHORT-----\nAQID\nBA==\n-----END SHORT-----\n"
);
// 3. Headers and empty contents are encoded with the configured line ending and round-trip via parse_many.
let mut with_header = Pem::new("METADATA BLOCK", b"sample payload".to_vec());
with_header
.headers_mut()
.add("Version", "1")
.expect("header add must succeed");
let empty_block = Pem::new("EMPTY BLOCK", Vec::<u8>::new());
let mixed = vec![with_header, empty_block];
let mixed_encoded = encode_many_config(
&mixed,
EncodeConfig::new()
.set_line_ending(LineEnding::LF)
.set_line_wrap(64),
);
assert!(
mixed_encoded.starts_with("-----BEGIN METADATA BLOCK-----\nVersion: 1\n\n"),
"headers must precede a blank line before base64 body"
);
assert!(
mixed_encoded.ends_with("-----BEGIN EMPTY BLOCK-----\n-----END EMPTY BLOCK-----\n"),
"empty contents must emit begin and end markers with no body lines"
);
let parsed_mixed = parse_many(&mixed_encoded).expect("mixed output must parse back");
assert_eq!(parsed_mixed, mixed);
assert_eq!(parsed_mixed[0].headers().get("Version"), Some("1"));
assert!(parsed_mixed[1].contents().is_empty());
// 4. Empty input slice encodes to an empty string.
let empty_encoded = encode_many_config(&[], EncodeConfig::new().set_line_ending(LineEnding::LF));
assert_eq!(empty_encoded, "");
}
オリジンシーダー
匿名