Trait strict_encoding::StrictDecode
source · pub trait StrictDecode: Sized {
fn strict_decode<D: Read>(d: D) -> Result<Self, Error>;
fn strict_deserialize(data: impl AsRef<[u8]>) -> Result<Self, Error> { ... }
fn strict_file_load(path: impl AsRef<Path>) -> Result<Self, Error> { ... }
}
Expand description
Binary decoding according to the strict rules that usually apply to
consensus-critical data structures. May be used for network communications.
MUST NOT be used for commitment verification: even if the commit procedure
uses StrictEncode
, the actual commit verification MUST be done with
CommitVerify
, TryCommitVerify
and EmbedCommitVerify
traits, which,
instead of deserializing (nonce operation for commitments) repeat the
commitment procedure for the revealed message and verify it against the
provided commitment.
Required Methods§
sourcefn strict_decode<D: Read>(d: D) -> Result<Self, Error>
fn strict_decode<D: Read>(d: D) -> Result<Self, Error>
Decode with the given std::io::Read
instance; must either
construct an instance or return implementation-specific error type.
Provided Methods§
sourcefn strict_deserialize(data: impl AsRef<[u8]>) -> Result<Self, Error>
fn strict_deserialize(data: impl AsRef<[u8]>) -> Result<Self, Error>
Tries to deserialize byte array into the current type using
StrictDecode::strict_decode
. If there are some data remains in the
buffer once deserialization is completed, fails with
Error::DataNotEntirelyConsumed
. Use io::Cursor
over the buffer and
StrictDecode::strict_decode
to avoid such failures.
sourcefn strict_file_load(path: impl AsRef<Path>) -> Result<Self, Error>
fn strict_file_load(path: impl AsRef<Path>) -> Result<Self, Error>
Reads data from file at path
and reconstructs object from it. Fails
with Error::DataNotEntirelyConsumed
if file contains remaining
data after the object reconstruction.
Implementations on Foreign Types§
source§impl StrictDecode for FlagVec
impl StrictDecode for FlagVec
source§impl StrictDecode for u256
impl StrictDecode for u256
source§impl StrictDecode for u512
impl StrictDecode for u512
source§impl StrictDecode for u1024
impl StrictDecode for u1024
source§impl StrictDecode for i256
impl StrictDecode for i256
source§impl StrictDecode for i512
impl StrictDecode for i512
source§impl StrictDecode for i1024
impl StrictDecode for i1024
source§impl StrictDecode for bf16
impl StrictDecode for bf16
source§impl StrictDecode for Half
impl StrictDecode for Half
source§impl StrictDecode for Oct
impl StrictDecode for Oct
source§impl StrictDecode for Quad
impl StrictDecode for Quad
source§impl StrictDecode for X87DoubleExtended
impl StrictDecode for X87DoubleExtended
source§impl StrictDecode for LeafVersion
impl StrictDecode for LeafVersion
source§impl StrictDecode for FutureLeafVersion
impl StrictDecode for FutureLeafVersion
source§impl StrictDecode for TaprootMerkleBranch
impl StrictDecode for TaprootMerkleBranch
source§impl StrictDecode for SecretKey
impl StrictDecode for SecretKey
source§impl StrictDecode for TweakedKeyPair
impl StrictDecode for TweakedKeyPair
source§impl StrictDecode for KeyPair
impl StrictDecode for KeyPair
source§impl StrictDecode for PublicKey
impl StrictDecode for PublicKey
source§impl StrictDecode for XOnlyPublicKey
impl StrictDecode for XOnlyPublicKey
source§impl StrictDecode for TweakedPublicKey
impl StrictDecode for TweakedPublicKey
source§impl StrictDecode for Signature
impl StrictDecode for Signature
source§impl StrictDecode for Signature
impl StrictDecode for Signature
source§impl StrictDecode for PsbtSighashType
impl StrictDecode for PsbtSighashType
source§impl StrictDecode for EcdsaSighashType
impl StrictDecode for EcdsaSighashType
source§impl StrictDecode for SchnorrSighashType
impl StrictDecode for SchnorrSighashType
source§impl StrictDecode for EcdsaSig
impl StrictDecode for EcdsaSig
source§impl StrictDecode for SchnorrSig
impl StrictDecode for SchnorrSig
source§impl StrictDecode for Payload
impl StrictDecode for Payload
source§impl StrictDecode for Address
impl StrictDecode for Address
source§impl StrictDecode for Amount
impl StrictDecode for Amount
source§impl StrictDecode for Script
impl StrictDecode for Script
source§impl StrictDecode for ControlBlock
impl StrictDecode for ControlBlock
source§impl StrictDecode for Network
impl StrictDecode for Network
source§impl StrictDecode for ChildNumber
impl StrictDecode for ChildNumber
source§impl StrictDecode for DerivationPath
impl StrictDecode for DerivationPath
source§impl StrictDecode for ChainCode
impl StrictDecode for ChainCode
source§impl StrictDecode for Fingerprint
impl StrictDecode for Fingerprint
source§impl StrictDecode for ExtendedPubKey
impl StrictDecode for ExtendedPubKey
source§impl StrictDecode for ExtendedPrivKey
impl StrictDecode for ExtendedPrivKey
source§impl StrictDecode for Key
impl StrictDecode for Key
source§impl StrictDecode for Pair
impl StrictDecode for Pair
source§impl StrictDecode for ProprietaryKey
impl StrictDecode for ProprietaryKey
source§impl StrictDecode for TapTree
impl StrictDecode for TapTree
source§impl<T> StrictDecode for Range<T>where
T: StrictDecode,
impl<T> StrictDecode for Range<T>where
T: StrictDecode,
In terms of strict decoding, ranges are represented as a tuples of two values: start and end.
source§impl<T> StrictDecode for RangeInclusive<T>where
T: StrictDecode,
impl<T> StrictDecode for RangeInclusive<T>where
T: StrictDecode,
In terms of strict decoding, inclusive ranges are represented as a tuples of two values: start and end.
source§impl<T> StrictDecode for RangeFrom<T>where
T: StrictDecode,
impl<T> StrictDecode for RangeFrom<T>where
T: StrictDecode,
In terms of strict decoding, partial ranges are represented as a single value.
source§impl<T> StrictDecode for RangeTo<T>where
T: StrictDecode,
impl<T> StrictDecode for RangeTo<T>where
T: StrictDecode,
In terms of strict decoding, partial ranges are represented as a single value.
source§impl<T> StrictDecode for RangeToInclusive<T>where
T: StrictDecode,
impl<T> StrictDecode for RangeToInclusive<T>where
T: StrictDecode,
In terms of strict decoding, partial ranges are represented as a single value.
source§impl<T> StrictDecode for Option<T>where
T: StrictDecode,
impl<T> StrictDecode for Option<T>where
T: StrictDecode,
In terms of strict encoding, Option
(optional values) are
represented by a significator byte, which MUST be either 0
(for no
value present) or 1
, followed by the value strict encoding.
For decoding an attempt to read Option
from a encoded non-0
or non-1 length Vec will result in Error::WrongOptionalEncoding
.
source§impl<T> StrictDecode for Vec<T>where
T: StrictDecode,
impl<T> StrictDecode for Vec<T>where
T: StrictDecode,
In terms of strict encoding, Vec
is stored in form of
usize-encoded length (see StrictEncode
implementation for usize
type for encoding platform-independent constant-length
encoding rules) followed by a consequently-encoded vec items,
according to their type.
An attempt to encode Vec
with more items than can fit in usize
encoding rules will result in Error::ExceedMaxItems
.
source§impl<T> StrictDecode for HashSet<T>where
T: StrictDecode + Eq + Ord + Hash + Debug,
impl<T> StrictDecode for HashSet<T>where
T: StrictDecode + Eq + Ord + Hash + Debug,
Strict decoding of a unique value collection represented by a rust
HashSet
type is performed alike Vec
decoding with the only
exception: if the repeated value met a Error::RepeatedValue is
returned.
source§impl<T> StrictDecode for BTreeSet<T>where
T: StrictDecode + Eq + Ord + Debug,
impl<T> StrictDecode for BTreeSet<T>where
T: StrictDecode + Eq + Ord + Debug,
Strict decoding of a unique value collection represented by a rust
BTreeSet
type is performed alike Vec
decoding with the only
exception: if the repeated value met a Error::RepeatedValue is
returned.
source§impl<T> StrictDecode for HashMap<usize, T>where
T: StrictDecode + Clone,
impl<T> StrictDecode for HashMap<usize, T>where
T: StrictDecode + Clone,
LNP/BP library uses HashMap<usize, T: StrictEncode>
s to encode
ordered lists, where the position of the list item must be fixed, since
the item is referenced from elsewhere by its index. Thus, the library
does not supports and recommends not to support strict encoding
of any other HashMap
variants.
Strict encoding of the HashMap<usize, T>
type is performed by
converting into a fixed-order Vec<T>
and serializing it according to
the Vec
strict encoding rules. This operation is internally
performed via conversion into BTreeMap<usize, T: StrictEncode>
.
source§impl<K, V> StrictDecode for BTreeMap<K, V>where
K: StrictDecode + Ord + Clone + Debug,
V: StrictDecode + Clone,
impl<K, V> StrictDecode for BTreeMap<K, V>where
K: StrictDecode + Ord + Clone + Debug,
V: StrictDecode + Clone,
LNP/BP library uses BTreeMap<usize, T: StrictEncode>
s to encode
ordered lists, where the position of the list item must be fixed, since
the item is referenced from elsewhere by its index. Thus, the library
does not supports and recommends not to support strict encoding
of any other BTreeMap
variants.
Strict encoding of the BTreeMap<usize, T>
type is performed
by converting into a fixed-order Vec<T>
and serializing it according
to the Vec
strict encoding rules.
source§impl<K, V> StrictDecode for (K, V)where
K: StrictDecode + Clone,
V: StrictDecode + Clone,
impl<K, V> StrictDecode for (K, V)where
K: StrictDecode + Clone,
V: StrictDecode + Clone,
Two-component tuples are decoded as they were fields in the parent data structure