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 } ;
@@ -30,6 +29,7 @@ use crate::{AssetId, BlockHash, Script, Transaction, TxOut, Txid};
3029use bitcoin;
3130use bitcoin:: bip32:: { ChildNumber , Fingerprint , KeySource } ;
3231use bitcoin:: { key:: XOnlyPublicKey , PublicKey } ;
32+ use crate :: internals:: slice:: SliceExt ;
3333use secp256k1_zkp:: { self , RangeProof , SurjectionProof , Tweak } ;
3434
3535use super :: map:: { PsbtSighashType , TapTree } ;
@@ -176,20 +176,17 @@ impl Serialize for KeySource {
176176
177177impl Deserialize for KeySource {
178178 fn deserialize ( bytes : & [ u8 ] ) -> Result < Self , encode:: Error > {
179- let prefix = match < [ u8 ; 4 ] > :: try_from ( & bytes[ 0 .. 4 ] ) {
180- Ok ( prefix ) => prefix ,
181- Err ( _ ) => return Err ( io:: Error :: from ( io:: ErrorKind :: UnexpectedEof ) . into ( ) ) ,
179+ let ( prefix, mut rest ) = match SliceExt :: split_first_chunk :: < 4 > ( bytes) {
180+ Some ( v ) => v ,
181+ None => return Err ( io:: Error :: from ( io:: ErrorKind :: UnexpectedEof ) . into ( ) ) ,
182182 } ;
183183
184184 let fprint: Fingerprint = Fingerprint :: from ( prefix) ;
185185 let mut dpath: Vec < ChildNumber > = Vec :: default ( ) ;
186186
187- let mut d = & bytes[ 4 ..] ;
188- while !d. is_empty ( ) {
189- match u32:: consensus_decode ( & mut d) {
190- Ok ( index) => dpath. push ( index. into ( ) ) ,
191- Err ( e) => return Err ( e) ,
192- }
187+ while !rest. is_empty ( ) {
188+ let index = u32:: consensus_decode ( & mut rest) ?;
189+ dpath. push ( index. into ( ) ) ;
193190 }
194191
195192 Ok ( ( fprint, dpath. into ( ) ) )
0 commit comments