Skip to main content

reallyme_codec/
lib.rs

1// SPDX-FileCopyrightText: 2026 ReallyMe Technologies Limited
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/// Borrowed general CBOR, deterministic CBOR, DAG-CBOR, and CID helpers.
36#[cfg(feature = "cbor")]
37pub mod cbor {
38    pub use codec_cbor::general;
39    pub use codec_cbor::{
40        compute_cid_dag_cbor, dag_cbor_multihash, decode_dag_cbor, decode_deterministic_cbor,
41        encode_dag_cbor, encode_deterministic_cbor, is_valid_cid_string, sha2_256_content_hash,
42        try_parse_cid, verify_dag_cbor_cid, CborError, CborValue, CidVerificationStatus,
43        ContentHash, DagCborCidVerification, DagCborMultihash, DeterministicCborError,
44        DeterministicCborInteger, DeterministicCborMapEntry, DeterministicCborMapKey,
45        DeterministicCborNegativeInteger, DeterministicCborProfileError, DeterministicCborValue,
46        ParsedCid, DAG_CBOR_CODEC, DETERMINISTIC_CBOR_NEGATIVE_MAX,
47        DETERMINISTIC_CBOR_NEGATIVE_MIN, MAX_DETERMINISTIC_CBOR_AGGREGATE_BYTE_STRING_BYTES,
48        MAX_DETERMINISTIC_CBOR_AGGREGATE_TEXT_BYTES, MAX_DETERMINISTIC_CBOR_CONTAINER_ENTRIES,
49        MAX_DETERMINISTIC_CBOR_INPUT_LEN, MAX_DETERMINISTIC_CBOR_NESTING_DEPTH,
50        MAX_DETERMINISTIC_CBOR_NODES, MAX_DETERMINISTIC_CBOR_OUTPUT_LEN,
51    };
52}
53
54/// Strict, bounded, schema-directed DER parsing for Rust consumers.
55#[cfg(feature = "der")]
56pub mod der;
57
58/// Canonical lowercase hexadecimal encode/decode helpers.
59#[cfg(feature = "hex")]
60pub mod hex {
61    pub use codec_hex::{bytes_to_lower_hex, lower_hex_to_bytes, write_lower_hex, HexError};
62}
63
64/// JSON Canonicalization Scheme helpers.
65#[cfg(feature = "jcs")]
66pub mod jcs {
67    pub use codec_jcs::{canonicalize_json_text, canonicalize_trusted_json_value, JcsError};
68}
69
70/// Multibase self-describing base encodings.
71#[cfg(feature = "multibase")]
72pub mod multibase {
73    pub use codec_multibase::{
74        base58btc_decode, base58btc_encode, bytes_to_multibase58btc, bytes_to_multibase_base64url,
75        multibase_to_bytes, Base58Error, MultibaseError,
76    };
77}
78
79/// Semantic multicodec registry lookup, prefix handling, and metadata.
80#[cfg(feature = "multicodec")]
81pub mod multicodec;
82
83/// Multikey encoding/parsing that binds an algorithm to opaque key bytes.
84#[cfg(feature = "multikey")]
85pub mod multikey {
86    #[allow(deprecated)]
87    pub use codec_multikey::{
88        binding_type_matches_codec, encode_multikey, parse_multikey, validate_key_binding,
89        validate_multikey_binding, KeyBindingInput, MultikeyError, ParsedMultikey,
90    };
91}
92
93/// PEM text armor parsing and encoding.
94#[cfg(feature = "pem")]
95pub mod pem {
96    pub use codec_pem::{
97        decode_pem, encode_pem, PemDecodePolicy, PemDocument, PemEncodeOptions, PemError, PemLabel,
98        PemLineEnding,
99    };
100}
101
102/// Generated protobuf operation contract lane.
103#[cfg(feature = "operation-contract")]
104pub mod operation_contract;