fedimint_core::encoding

Trait Decodable

Source
pub trait Decodable: Sized {
    // Provided methods
    fn consensus_decode_from_finite_reader<R: Read>(
        r: &mut R,
        modules: &ModuleDecoderRegistry,
    ) -> Result<Self, DecodeError> { ... }
    fn consensus_decode<R: Read>(
        r: &mut R,
        modules: &ModuleDecoderRegistry,
    ) -> Result<Self, DecodeError> { ... }
    fn consensus_decode_hex(
        hex: &str,
        modules: &ModuleDecoderRegistry,
    ) -> Result<Self, DecodeError> { ... }
    fn consensus_decode_vec(
        bytes: Vec<u8>,
        modules: &ModuleDecoderRegistry,
    ) -> Result<Self, DecodeError> { ... }
}
Expand description

Data which can be encoded in a consensus-consistent way

Provided Methods§

Source

fn consensus_decode_from_finite_reader<R: Read>( r: &mut R, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>

Decode Self from a size-limited reader.

Like consensus_decode but relies on the reader being limited in the amount of data it returns, e.g. by being wrapped in std::io::Take.

Failing to abide to this requirement might lead to memory exhaustion caused by malicious inputs.

Users should default to consensus_decode, but when data to be decoded is already in a byte vector of a limited size, calling this function directly might be marginally faster (due to avoiding extra checks).

§Rules for trait implementations
  • Simple types that that have a fixed size (own and member fields), don’t have to overwrite this method, or be concern with it, should only impl consensus_decode.
  • Types that deserialize based on decoded untrusted length should implement consensus_decode_from_finite_reader only:
    • Default implementation of consensus_decode will forward to consensus_decode_bytes_from_finite_reader with the reader wrapped by Take, protecting from readers that keep returning data.
    • Implementation must make sure to put a cap on things like Vec::with_capacity and other allocations to avoid oversized allocations, and rely on the reader being finite and running out of data, and collections reallocating on a legitimately oversized input data, instead of trying to enforce arbitrary length limits.
  • Types that contain other types that might be require limited reader (thus implementing consensus_decode_from_finite_reader), should also implement it applying same rules, and in addition make sure to call consensus_decode_from_finite_reader on all members, to avoid creating redundant Take wrappers (Take<Take<...>>). Failure to do so might result only in a tiny performance hit.
Source

fn consensus_decode<R: Read>( r: &mut R, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>

Decode an object with a well-defined format.

This is the method that should be implemented for a typical, fixed sized type implementing this trait. Default implementation is wrapping the reader in std::io::Take to limit the input size to MAX_DECODE_SIZE, and forwards the call to Self::consensus_decode_from_finite_reader, which is convenient for types that override Self::consensus_decode_from_finite_reader instead.

Source

fn consensus_decode_hex( hex: &str, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>

Decode an object from hex

Source

fn consensus_decode_vec( bytes: Vec<u8>, modules: &ModuleDecoderRegistry, ) -> Result<Self, DecodeError>

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Decodable for Cow<'static, str>

Source§

impl Decodable for bool

Source§

impl Decodable for u8

Source§

impl Decodable for u16

Source§

impl Decodable for u32

Source§

impl Decodable for u64

Source§

impl Decodable for ()

Source§

impl Decodable for String

Source§

impl Decodable for Duration

Source§

impl Decodable for SystemTime

Source§

impl Decodable for Address<NetworkUnchecked>

Source§

impl Decodable for Amount

Source§

impl Decodable for BigSize

Source§

impl Decodable for BlockHash

Source§

impl Decodable for Bolt11Invoice

Source§

impl Decodable for Ciphertext

Source§

impl Decodable for DecryptionShare

Source§

impl Decodable for G1Affine

Source§

impl Decodable for G2Affine

Source§

impl Decodable for Hash

Source§

impl Decodable for Header

Source§

impl Decodable for Keypair

Source§

impl Decodable for Network

Source§

impl Decodable for OutPoint

Source§

impl Decodable for PartialMerkleTree

Source§

impl Decodable for Psbt

Source§

impl Decodable for PublicKey

Source§

impl Decodable for PublicKey

Source§

impl Decodable for PublicKeySet

Source§

impl Decodable for RoutingFees

Source§

impl Decodable for Scalar

Source§

impl Decodable for ScriptBuf

Source§

impl Decodable for SecretKey

Source§

impl Decodable for Signature

Source§

impl Decodable for Signature

Source§

impl Decodable for Transaction

Source§

impl Decodable for TxOut

Source§

impl Decodable for Txid

Source§

impl<K> Decodable for BTreeSet<K>
where K: Decodable + Ord,

Source§

impl<K> Decodable for Descriptor<K>
where Self: FromStr, <Self as FromStr>::Err: ToString + Error + Send + Sync + 'static, K: MiniscriptKey,

Source§

impl<K, V> Decodable for BTreeMap<K, V>
where K: Decodable + Ord, V: Decodable,

Source§

impl<T1: Decodable, T2: Decodable> Decodable for (T1, T2)

Source§

impl<T1: Decodable, T2: Decodable, T3: Decodable> Decodable for (T1, T2, T3)

Source§

impl<T1: Decodable, T2: Decodable, T3: Decodable, T4: Decodable> Decodable for (T1, T2, T3, T4)

Source§

impl<T> Decodable for Option<T>
where T: Decodable,

Source§

impl<T> Decodable for Box<T>
where T: Decodable,

Source§

impl<T> Decodable for VecDeque<T>
where T: Decodable + 'static,

Source§

impl<T> Decodable for Vec<T>
where T: Decodable + 'static,

Source§

impl<T, E> Decodable for Result<T, E>
where T: Decodable, E: Decodable,

Source§

impl<T, const SIZE: usize> Decodable for [T; SIZE]
where T: Decodable + Debug + Default + Copy + 'static,

Implementors§

Source§

impl Decodable for ConsensusItem

Source§

impl Decodable for InviteCodePart

Source§

impl Decodable for SessionStatus

Source§

impl Decodable for TransactionError

Source§

impl Decodable for TransactionSignature

Source§

impl Decodable for fedimint_core::amount::Amount

Source§

impl Decodable for ClientBackupKey

Source§

impl Decodable for ClientBackupKeyPrefix

Source§

impl Decodable for ClientBackupSnapshot

Source§

impl Decodable for ClientConfig

Source§

impl Decodable for ClientConfigV0

Source§

impl Decodable for ClientModuleConfig

Source§

impl Decodable for FederationId

Source§

impl Decodable for FederationIdPrefix

Source§

impl Decodable for GlobalClientConfig

Source§

impl Decodable for GlobalClientConfigV0

Source§

impl Decodable for PeerUrl

Source§

impl Decodable for ServerModuleConsensusConfig

Source§

impl Decodable for BackupRequest

Source§

impl Decodable for DynClientConfig

Source§

impl Decodable for DynInput

Source§

impl Decodable for DynInputError

Source§

impl Decodable for DynModuleConsensusItem

Source§

impl Decodable for DynOutput

Source§

impl Decodable for DynOutputError

Source§

impl Decodable for DynOutputOutcome

Source§

impl Decodable for ModuleKind

Source§

impl Decodable for OperationId

Source§

impl Decodable for DatabaseVersion

Source§

impl Decodable for DatabaseVersionKey

Source§

impl Decodable for DatabaseVersionKeyV0

Source§

impl Decodable for AltDbPrefixTestPrefix

Source§

impl Decodable for AltTestKey

Source§

impl Decodable for DbPrefixTestPrefix

Source§

impl Decodable for DbPrefixTestPrefixV0

Source§

impl Decodable for PercentPrefixTestPrefix

Source§

impl Decodable for PercentTestKey

Source§

impl Decodable for TestKey

Source§

impl Decodable for TestKeyV0

Source§

impl Decodable for TestVal

Source§

impl Decodable for BitcoinRpcConfig

Source§

impl Decodable for InviteCode

Source§

impl Decodable for InviteCodeV2

Source§

impl Decodable for ApiVersion

Source§

impl Decodable for CoreConsensusVersion

Source§

impl Decodable for ModuleConsensusVersion

Source§

impl Decodable for MultiApiVersion

Source§

impl Decodable for SupportedApiVersionsSummary

Source§

impl Decodable for SupportedCoreApiVersions

Source§

impl Decodable for SupportedModuleApiVersions

Source§

impl Decodable for ApiAnnouncement

Source§

impl Decodable for SignedApiAnnouncement

Source§

impl Decodable for SignedApiAnnouncementSubmission

Source§

impl Decodable for PeerId

Source§

impl Decodable for AcceptedItem

Source§

impl Decodable for SchnorrSignature

Source§

impl Decodable for SessionOutcome

Source§

impl Decodable for SignedSessionOutcome

Source§

impl Decodable for Feerate

Source§

impl Decodable for fedimint_core::OutPoint

Source§

impl Decodable for fedimint_core::transaction::Transaction

Source§

impl Decodable for TransactionSubmissionOutcome

Source§

impl Decodable for TransactionId

Source§

impl Decodable for TxOutProof

Source§

impl Decodable for SafeUrl

Source§

impl Decodable for NetworkLegacyEncodingWrapper

Source§

impl<C> Decodable for Tiered<C>
where C: Decodable,

Source§

impl<C> Decodable for TieredMulti<C>
where C: Decodable + 'static,

Source§

impl<T> Decodable for DynRawFallback<T>
where T: Decodable + 'static,