1717//! Defines traits used for (de)serializing PSET values into/from raw
1818//! bytes in PSET key-value pairs.
1919
20- use std:: convert:: TryFrom ;
2120use std:: io;
2221
2322use crate :: confidential:: { self , AssetBlindingFactor } ;
@@ -29,6 +28,7 @@ use crate::{AssetId, BlockHash, Script, Transaction, TxOut, Txid};
2928use bitcoin;
3029use bitcoin:: bip32:: { ChildNumber , Fingerprint , KeySource } ;
3130use bitcoin:: { key:: XOnlyPublicKey , PublicKey } ;
31+ use internals:: slice:: SliceExt ;
3232use secp256k1_zkp:: { self , RangeProof , SurjectionProof , Tweak } ;
3333
3434use super :: map:: { PsbtSighashType , TapTree } ;
@@ -176,16 +176,15 @@ impl Serialize for KeySource {
176176
177177impl Deserialize for KeySource {
178178 fn deserialize ( bytes : & [ u8 ] ) -> Result < Self , encode:: Error > {
179- let Ok ( prefix) = < [ u8 ; 4 ] > :: try_from ( & bytes[ 0 .. 4 ] ) else {
179+ let Some ( ( prefix, mut rest ) ) = SliceExt :: split_first_chunk :: < 4 > ( bytes) else {
180180 return Err ( io:: Error :: from ( io:: ErrorKind :: UnexpectedEof ) . into ( ) ) ;
181181 } ;
182182
183183 let fprint: Fingerprint = Fingerprint :: from ( prefix) ;
184184 let mut dpath: Vec < ChildNumber > = Vec :: default ( ) ;
185185
186- let mut d = & bytes[ 4 ..] ;
187- while !d. is_empty ( ) {
188- let index = u32:: consensus_decode ( & mut d) ?;
186+ while !rest. is_empty ( ) {
187+ let index = u32:: consensus_decode ( & mut rest) ?;
189188 dpath. push ( index. into ( ) ) ;
190189 }
191190
0 commit comments