Skip to main content

Crate bytepeel_core

Crate bytepeel_core 

Source
Expand description

Zero-dependency recursive decoder for encoded and binary data.

bytepeel-core takes opaque input (a hex dump, a base64 blob, a PEM block, raw bytes) and peels it layer by layer into a Node tree. Where the bytes are genuinely ambiguous (a protobuf length-delimited field could be a string, a submessage or packed varints) it keeps the top interpretations with scores instead of silently picking one.

use bytepeel_core::{peel, Options, Detail};

let node = peel(b"SGVsbG8gd29ybGQ=", &Options::default()).unwrap();
assert_eq!(node.codec.name(), "base64");
let Detail::Layer { child, .. } = &node.detail else { panic!() };
assert!(matches!(&child.detail, Detail::Text { text, .. } if text == "Hello world"));

Modules§

varint
LEB128 varints as used by protobuf.

Structs§

Alt
Asn1
One DER element (tag, length, value).
B64
Result of decoding base64 text.
Diag
A machine-readable diagnostic: used both for hard errors and node warnings.
Field
JsonPick
A value inside JSON text.
JwtPick
A JWT part picked by select_jwt, optionally narrowed to one JSON value inside the header or payload.
Node
Options
Decoding options.
Value
One decoded value: a byte range and its kind.

Enums§

Alphabet
AltKind
Asn1Value
Codec
Detail
FieldValue
Force
Force the interpretation of the first non-text-encoding layer.
InputForm
How to read the top-level input.
NewValue
A new value for a field, parsed from the CLI syntax (see parse_value).
Op
One edit for edit. Paths are the --get paths of the decoded tree.
Pick
What a path selected.
TagClass
ASN.1 tag class.
ValueKind

Constants§

BYTES_HEAD
Bytes kept in a Detail::Bytes leaf for its preview.
MAX_ITEMS
Default for Options::max_items.
TEXT_HEAD
Characters kept in a Detail::Text leaf.

Functions§

asn1_to_json
Serialize a single DER element (e.g. the result of select_der) as JSON.
asn1_to_tree
Render a single DER element as an indented outline.
decode_b64
Decode base64 text: standard (+/) or URL-safe (-_) alphabet, padded or unpadded, with line breaks allowed (PEM-style wrapping). Other whitespace inside the data is rejected.
decode_hex
Strictly decode hex text. Whitespace and : separate tokens; each token may carry a 0x prefix and must have an even number of digits.
diag_to_json
Serialize a diagnostic as {"error":{"code":..,"message":..,"offset":..}}.
edit
Apply one edit and re-encode every enclosing layer in its original style. The output is decoded again with the same options and checked; the result is returned only if it holds exactly the requested change.
field_to_json
Serialize a single protobuf field (e.g. the result of select) as JSON.
field_to_tree
Render a single protobuf field as an indented outline.
get
Select by a path that may cross formats, e.g. 2.0.0.5 for the subject of a base64 certificate in protobuf string field 2, or token.payload.sub for a JWT in a CBOR byte string.
innermost
The bytes the innermost item was decoded from: the decoded bytes of the last text or compression layer (hex, base64, PEM, dump, gzip, zlib, zstd), or input itself when root is not a layer. root must be peel(input, ..)’s result. This is the whole payload, never a preview: base64 → gzip → text gives the full text.
is_der
True when node (after any text layers) is DER, so paths are element indices. A PEM bundle counts when every block is DER.
is_jwt
True when node (after any text layers) is a JWT.
is_values
True when node (after any text layers) is CBOR or MessagePack.
parse_value
Parse a value in the CLI syntax.
peel
Decode input into a tree of layers.
select
Select a protobuf field by path.
select_der
Select a DER element by path.
select_jwt
Select a JWT part by name (payload) or index (1), then optionally a value inside its JSON (payload.sub, header.alg, payload.roles.0). JSON segments are object keys (matched exactly; the first of duplicate keys wins) or array indices. Keys containing . cannot be addressed.
select_value
Select a CBOR or MessagePack value by path.
set
Set the field at path to value: edit(input, opts, &Op::Set(..)).
to_json
Serialize a node tree as compact JSON. See docs/DESIGN.md for the schema.
to_tree
Render a node tree as an indented, human-readable outline.
value_to_json
Serialize a single CBOR value (e.g. the result of select_value) as JSON.
value_to_tree
Render a single CBOR value as an indented outline.