Skip to main content

reallyme_codec/
lib.rs

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