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, encode_dag_cbor,
36        is_valid_cid_string, sha2_256_content_hash, try_parse_cid, verify_dag_cbor_cid, CborError,
37        CborValue, ContentHash, DagCborMultihash, DAG_CBOR_CODEC,
38    };
39}
40
41/// Canonical lowercase hexadecimal encode/decode helpers.
42#[cfg(feature = "hex")]
43pub mod hex {
44    pub use codec_hex::{bytes_to_lower_hex, lower_hex_to_bytes, write_lower_hex, HexError};
45}
46
47/// JSON Canonicalization Scheme helpers.
48#[cfg(feature = "jcs")]
49pub mod jcs {
50    pub use codec_jcs::{canonicalize_json, JcsError};
51}
52
53/// Multibase self-describing base encodings.
54#[cfg(feature = "multibase")]
55pub mod multibase {
56    pub use codec_multibase::{
57        base58btc_decode, base58btc_encode, bytes_to_multibase58btc, bytes_to_multibase_base64url,
58        multibase_to_bytes, Base58Error, MultibaseError,
59    };
60}
61
62/// Multicodec varint prefix lookup and stripping.
63#[cfg(feature = "multicodec")]
64pub mod multicodec {
65    pub use codec_multicodec::{
66        lookup_codec_prefix, strip_codec_prefix, CodecLookupResult, CodecSpec, MULTICODEC_TABLE,
67    };
68}
69
70/// Multikey encoding/parsing that binds an algorithm to opaque key bytes.
71#[cfg(feature = "multikey")]
72pub mod multikey {
73    pub use codec_multikey::{
74        binding_type_matches_codec, encode_multikey, parse_multikey, validate_key_binding,
75        KeyBindingInput, MultikeyError, ParsedMultikey,
76    };
77}
78
79/// PEM text armor parsing and encoding.
80#[cfg(feature = "pem")]
81pub mod pem {
82    pub use codec_pem::{
83        decode_pem, encode_pem, PemDecodePolicy, PemDocument, PemEncodeOptions, PemError, PemLabel,
84        PemLineEnding,
85    };
86}