Skip to main content

reallyme_codec/
lib.rs

1// SPDX-FileCopyrightText: Copyright © 2026 ReallyMe LLC. All rights reserved
2//
3// SPDX-License-Identifier: MIT OR Apache-2.0
4
5//! # reallyme-codec
6//!
7//! Codec-only utilities used by ReallyMe and DID tooling: base encodings,
8//! canonical JSON/CBOR serialization, multicodec lookup, multikey handling, and
9//! PEM text armor.
10//! SHA-256 is used for content identifiers. This crate does not expose signing,
11//! encryption, or key generation.
12
13#![forbid(unsafe_code)]
14
15/// Standard (RFC 4648) base64 encode/decode.
16#[cfg(feature = "base64")]
17pub mod base64 {
18    pub use codec_base64::{base64_to_bytes, bytes_to_base64, Base64Error};
19}
20
21/// URL-safe (RFC 4648 §5) base64 encode/decode without padding.
22#[cfg(feature = "base64url")]
23pub mod base64url {
24    pub use codec_base64url::{
25        base64url_bytes_to_bytes, base64url_to_bytes, bytes_to_base64url, Base64UrlError,
26    };
27
28    #[cfg(feature = "serde")]
29    pub use codec_base64url::{serde_bytes, serde_option_bytes};
30}
31
32/// Deterministic generic CBOR, DAG-CBOR, and content-identifier helpers.
33#[cfg(feature = "cbor")]
34pub mod cbor {
35    pub use codec_cbor::{
36        compute_cid_dag_cbor, dag_cbor_multihash, decode_dag_cbor, decode_deterministic_cbor,
37        encode_dag_cbor, encode_deterministic_cbor, is_valid_cid_string, sha2_256_content_hash,
38        try_parse_cid, verify_dag_cbor_cid, CborError, CborValue, ContentHash, DagCborMultihash,
39        DeterministicCborError, DeterministicCborInteger, DeterministicCborMapEntry,
40        DeterministicCborMapKey, DeterministicCborNegativeInteger, DeterministicCborProfileError,
41        DeterministicCborValue, DAG_CBOR_CODEC, DETERMINISTIC_CBOR_NEGATIVE_MAX,
42        DETERMINISTIC_CBOR_NEGATIVE_MIN, MAX_DETERMINISTIC_CBOR_AGGREGATE_BYTE_STRING_BYTES,
43        MAX_DETERMINISTIC_CBOR_AGGREGATE_TEXT_BYTES, MAX_DETERMINISTIC_CBOR_CONTAINER_ENTRIES,
44        MAX_DETERMINISTIC_CBOR_INPUT_LEN, MAX_DETERMINISTIC_CBOR_NESTING_DEPTH,
45        MAX_DETERMINISTIC_CBOR_NODES, MAX_DETERMINISTIC_CBOR_OUTPUT_LEN,
46    };
47}
48
49/// Canonical lowercase hexadecimal encode/decode helpers.
50#[cfg(feature = "hex")]
51pub mod hex {
52    pub use codec_hex::{bytes_to_lower_hex, lower_hex_to_bytes, write_lower_hex, HexError};
53}
54
55/// JSON Canonicalization Scheme helpers.
56#[cfg(feature = "jcs")]
57pub mod jcs {
58    pub use codec_jcs::{canonicalize_json_text, canonicalize_trusted_json_value, JcsError};
59}
60
61/// Multibase self-describing base encodings.
62#[cfg(feature = "multibase")]
63pub mod multibase {
64    pub use codec_multibase::{
65        base58btc_decode, base58btc_encode, bytes_to_multibase58btc, bytes_to_multibase_base64url,
66        multibase_to_bytes, Base58Error, MultibaseError,
67    };
68}
69
70/// Semantic multicodec registry lookup, prefix handling, and metadata.
71#[cfg(feature = "multicodec")]
72pub mod multicodec;
73
74/// Multikey encoding/parsing that binds an algorithm to opaque key bytes.
75#[cfg(feature = "multikey")]
76pub mod multikey {
77    pub use codec_multikey::{
78        binding_type_matches_codec, encode_multikey, parse_multikey, validate_key_binding,
79        KeyBindingInput, MultikeyError, ParsedMultikey,
80    };
81}
82
83/// PEM text armor parsing and encoding.
84#[cfg(feature = "pem")]
85pub mod pem {
86    pub use codec_pem::{
87        decode_pem, encode_pem, PemDecodePolicy, PemDocument, PemEncodeOptions, PemError, PemLabel,
88        PemLineEnding,
89    };
90}
91
92/// Generated protobuf operation contract lane.
93#[cfg(feature = "operation-contract")]
94pub mod operation_contract;
95
96/// Adapter-facing semantic layer for scalar and raw-byte operations.
97#[cfg(feature = "operation-contract")]
98#[doc(hidden)]
99pub mod scalar_ops;