@@ -743,18 +743,18 @@ impl<'a> Instructions<'a> {
743
743
/// takes `len` bytes long slice from iterator and returns it advancing iterator
744
744
/// if the iterator is not long enough `None` is returned and the iterator is killed
745
745
/// to avoid returning an infinite stream of errors.
746
- fn take_slice_or_kill ( & mut self , len : usize ) -> Option < & ' a [ u8 ] > {
746
+ fn take_slice_or_kill ( & mut self , len : usize ) -> Result < & ' a [ u8 ] , Error > {
747
747
if self . data . len ( ) >= len {
748
748
let slice = & self . data . as_slice ( ) [ ..len] ;
749
749
self . data . nth ( len. max ( 1 ) - 1 ) ;
750
- Some ( slice)
750
+ Ok ( slice)
751
751
} else {
752
752
self . kill ( ) ;
753
- None
753
+ Err ( Error :: EarlyEndOfScript )
754
754
}
755
755
}
756
756
757
- fn next_push_data_len ( & mut self , len : usize , max : usize ) -> Option < Result < Instruction < ' a > , Error > > {
757
+ fn next_push_data_len ( & mut self , len : usize , min_push_len : usize ) -> Option < Result < Instruction < ' a > , Error > > {
758
758
let n = match read_uint_iter ( & mut self . data , len) {
759
759
Ok ( n) => n,
760
760
// We do exhaustive matching to not forget to handle new variants if we extend
@@ -766,11 +766,11 @@ impl<'a> Instructions<'a> {
766
766
return Some ( Err ( Error :: EarlyEndOfScript ) ) ;
767
767
} ,
768
768
} ;
769
- if self . enforce_minimal && n < max {
769
+ if self . enforce_minimal && n < min_push_len {
770
770
self . kill ( ) ;
771
771
return Some ( Err ( Error :: NonMinimalPush ) ) ;
772
772
}
773
- Some ( self . take_slice_or_kill ( n) . map ( Instruction :: PushBytes ) . ok_or ( Error :: EarlyEndOfScript ) )
773
+ Some ( self . take_slice_or_kill ( n) . map ( Instruction :: PushBytes ) )
774
774
}
775
775
}
776
776
@@ -801,7 +801,7 @@ impl<'a> Iterator for Instructions<'a> {
801
801
Some ( Ok ( Instruction :: PushBytes ( & [ ] ) ) )
802
802
} ,
803
803
_ => {
804
- Some ( self . take_slice_or_kill ( n) . map ( Instruction :: PushBytes ) . ok_or ( Error :: EarlyEndOfScript ) )
804
+ Some ( self . take_slice_or_kill ( n) . map ( Instruction :: PushBytes ) )
805
805
}
806
806
}
807
807
}
@@ -816,8 +816,7 @@ impl<'a> Iterator for Instructions<'a> {
816
816
}
817
817
// Everything else we can push right through
818
818
_ => {
819
- let ret = Some ( Ok ( Instruction :: Op ( opcodes:: All :: from ( byte) ) ) ) ;
820
- ret
819
+ Some ( Ok ( Instruction :: Op ( opcodes:: All :: from ( byte) ) ) )
821
820
}
822
821
}
823
822
}
0 commit comments