Sample
yasna 0.5.2: yasna::construct_der
Verified sample for cargo yasna 0.5.2: yasna::construct_der. The contract ran on rust 1 · linux alpine/x64 · docker and passed.
sha256:caa48dbbf690c023fe2ae7deaa36f171a482ef04921d48e9f03f2262e281d526
This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured.
How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people.
MIT-0
Execution evidence
The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.
- Evidence basis
- Signed contract pass
- Verification receipts
- 1
- Signing keys that built it
- 1
Declared environment
linux · alpine · musl x64 cargo
Verification-run environments
| Environment | Contract | Stages | Run |
|---|---|---|---|
| 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-27 |
Case
HOW- Goal
- verify yasna::construct_der in pkg:cargo/yasna@0.5.2
- Packages
- Symbols
-
- yasna::construct_der
- Created
- 2026-11-27T02:29:31Z
Contract
- yasna::construct_der encodes DER primitive integers (including negative and leading-zero positive values), booleans (0xff/0x00), null, and UTF8String with exact tag-length-value bytes
- yasna::construct_der encodes nested SEQUENCE values that round-trip cleanly through yasna::parse_der
- yasna::construct_der encodes OBJECT IDENTIFIER alongside explicit (0xa0) and implicit (0x81) context-specific tags
- yasna::construct_der write_set_of sorts SET OF elements lexicographically by DER encoding
- yasna::construct_der encodes long-form definite lengths for payloads of 128 or more bytes
Files
- Cargo.lock
- Cargo.toml
- PROMPT.md
- csx.json
- spec.json
- src/lib.rs
- test/contract.rs
Source
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "sample-yasna-construct-der"
version = "1.0.0"
dependencies = [
"yasna",
]
[[package]]
name = "yasna"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e17bb3549cc1321ae1296b9cdc2698e2b6cb1992adfa19a8c72e5b7a738f44cd"
[package]
name = "sample-yasna-construct-der"
version = "1.0.0"
edition = "2021"
publish = false
[dependencies]
yasna = "=0.5.2"
[[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 yasna::construct_der in pkg:cargo/yasna@0.5.2
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:cargo/yasna@0.5.2
Demonstrate these symbols/APIs:
- yasna::construct_der
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:582f7078abde7e5aebd2d5a258655310764b1287e0355d0ae0f694f8b525476c","contract":["yasna::construct_der encodes DER primitive integers (including negative and leading-zero positive values), booleans (0xff/0x00), null, and UTF8String with exact tag-length-value bytes","yasna::construct_der encodes nested SEQUENCE values that round-trip cleanly through yasna::parse_der","yasna::construct_der encodes OBJECT IDENTIFIER alongside explicit (0xa0) and implicit (0x81) context-specific tags","yasna::construct_der write_set_of sorts SET OF elements lexicographically by DER encoding","yasna::construct_der encodes long-form definite lengths for payloads of 128 or more bytes"],"goal":"verify yasna::construct_der in pkg:cargo/yasna@0.5.2","kind":"HOW","packages":["pkg:cargo/yasna@0.5.2"],"schemaVersion":1,"symbols":["yasna::construct_der"]},"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/yasna@0.5.2"],"schemaVersion":1,"subject":"pkg:cargo/yasna@0.5.2","symbols":["yasna::construct_der"],"verifierAdapter":"cargo@1"}
{
"schemaVersion": 1,
"goal": "verify yasna::construct_der in pkg:cargo/yasna@0.5.2",
"kind": "HOW",
"packages": [
"pkg:cargo/yasna@0.5.2"
],
"symbols": [
"yasna::construct_der"
]
}
use yasna::models::ObjectIdentifier;
use yasna::Tag;
pub fn build_record_der(id: i64, active: bool, payload: &[u8]) -> Vec<u8> {
yasna::construct_der(|writer| {
writer.write_sequence(|writer| {
writer.next().write_i64(id);
writer.next().write_bool(active);
writer.next().write_bytes(payload);
});
})
}
pub fn build_tagged_and_oid_der(oid_components: &[u64], explicit_val: i64, implicit_val: i64) -> Vec<u8> {
let oid = ObjectIdentifier::from_slice(oid_components);
yasna::construct_der(|writer| {
writer.write_sequence(|writer| {
writer.next().write_oid(&oid);
writer.next().write_tagged(Tag::context(0), |writer| {
writer.write_i64(explicit_val);
});
writer.next().write_tagged_implicit(Tag::context(1), |writer| {
writer.write_i64(implicit_val);
});
});
})
}
use sample_yasna_construct_der::{build_record_der, build_tagged_and_oid_der};
use yasna::models::ObjectIdentifier;
use yasna::Tag;
fn main() {
// 1. Primitive DER encodings via yasna::construct_der
let int_pos = yasna::construct_der(|w| w.write_i64(42));
assert_eq!(int_pos, vec![0x02, 0x01, 0x2a]);
let int_neg = yasna::construct_der(|w| w.write_i64(-1));
assert_eq!(int_neg, vec![0x02, 0x01, 0xff]);
let int_128 = yasna::construct_der(|w| w.write_i64(128));
assert_eq!(int_128, vec![0x02, 0x02, 0x00, 0x80]);
let bool_true = yasna::construct_der(|w| w.write_bool(true));
assert_eq!(bool_true, vec![0x01, 0x01, 0xff]);
let bool_false = yasna::construct_der(|w| w.write_bool(false));
assert_eq!(bool_false, vec![0x01, 0x01, 0x00]);
let null_der = yasna::construct_der(|w| w.write_null());
assert_eq!(null_der, vec![0x05, 0x00]);
let utf8_der = yasna::construct_der(|w| w.write_utf8_string("hi"));
assert_eq!(utf8_der, vec![0x0c, 0x02, b'h', b'i']);
// 2. SEQUENCE encoding and parse_der round-trip
let record_der = build_record_der(10, true, &[0x01, 0x02]);
assert_eq!(
record_der,
vec![0x30, 0x0a, 0x02, 0x01, 0x0a, 0x01, 0x01, 0xff, 0x04, 0x02, 0x01, 0x02]
);
let parsed_record = yasna::parse_der(&record_der, |reader| {
reader.read_sequence(|reader| {
let id = reader.next().read_i64()?;
let active = reader.next().read_bool()?;
let payload = reader.next().read_bytes()?;
Ok((id, active, payload))
})
})
.expect("construct_der SEQUENCE must parse with parse_der");
assert_eq!(parsed_record, (10, true, vec![0x01, 0x02]));
// 3. OID plus explicit and implicit context-specific tags
let tagged_der = build_tagged_and_oid_der(&[1, 2, 840, 113549], 7, 9);
assert_eq!(
tagged_der,
vec![
0x30, 0x10,
0x06, 0x06, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d,
0xa0, 0x03, 0x02, 0x01, 0x07,
0x81, 0x01, 0x09,
]
);
let parsed_tagged = yasna::parse_der(&tagged_der, |reader| {
reader.read_sequence(|reader| {
let oid = reader.next().read_oid()?;
let explicit_val = reader.next().read_tagged(Tag::context(0), |r| r.read_i64())?;
let implicit_val = reader
.next()
.read_tagged_implicit(Tag::context(1), |r| r.read_i64())?;
Ok((oid, explicit_val, implicit_val))
})
})
.expect("construct_der tagged SEQUENCE must parse with parse_der");
assert_eq!(
parsed_tagged,
(ObjectIdentifier::from_slice(&[1, 2, 840, 113549]), 7, 9)
);
// 4. SET OF canonical DER byte sorting
let set_der = yasna::construct_der(|writer| {
writer.write_set_of(|writer| {
writer.next().write_i64(200);
writer.next().write_i64(1);
writer.next().write_i64(5);
});
});
assert_eq!(
set_der,
vec![0x31, 0x0a, 0x02, 0x01, 0x01, 0x02, 0x01, 0x05, 0x02, 0x02, 0x00, 0xc8]
);
// 5. Long-form definite length encoding for payloads >= 128 bytes
let long_payload = vec![0xaa; 130];
let long_der = yasna::construct_der(|w| w.write_bytes(&long_payload));
assert_eq!(long_der.len(), 3 + 130);
assert_eq!(&long_der[..3], &[0x04, 0x81, 0x82]);
assert_eq!(&long_der[3..], long_payload.as_slice());
println!("All yasna::construct_der contract assertions passed.");
}
Origin Seeder
anonymous