Skip to main content

reallyme_codec/
lib.rs

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