@@ -423,7 +423,8 @@ public virtual string EncodeData(ReadOnlySpan<byte> data, Bech32EncodingType enc
423423 if ( SquashBytes )
424424 data = ByteSquasher ( data , 8 , 5 ) . AsSpan ( ) ;
425425#else
426- data = ByteSquasher ( data , 8 , 5 ) ;
426+ if ( SquashBytes )
427+ data = ByteSquasher ( data , offset , count , 8 , 5 ) ;
427428#endif
428429
429430#if HAS_SPAN
@@ -561,7 +562,11 @@ protected virtual byte[] DecodeDataCore(string encoded, out Bech32EncodingType e
561562#endif
562563 if ( SquashBytes )
563564 {
565+ #if HAS_SPAN
564566 arr = ByteSquasher ( arr , 5 , 8 ) ;
567+ #else
568+ arr = ByteSquasher ( arr , 0 , arr . Length , 5 , 8 ) ;
569+ #endif
565570 if ( arr is null )
566571 throw new FormatException ( "Invalid squashed bech32" ) ;
567572 }
@@ -570,15 +575,18 @@ protected virtual byte[] DecodeDataCore(string encoded, out Bech32EncodingType e
570575#if HAS_SPAN
571576 private static byte [ ] ByteSquasher ( ReadOnlySpan < byte > input , int inputWidth , int outputWidth )
572577#else
573- private static byte [ ] ByteSquasher ( byte [ ] input , int inputWidth , int outputWidth )
578+ private static byte [ ] ByteSquasher ( byte [ ] input , int offset , int count , int inputWidth , int outputWidth )
574579#endif
575580 {
576581 var bitstash = 0 ;
577582 var accumulator = 0 ;
578583 var output = new List < byte > ( ) ;
579584 var maxOutputValue = ( 1 << outputWidth ) - 1 ;
580-
585+ #if HAS_SPAN
581586 for ( var i = 0 ; i < input . Length ; i ++ )
587+ #else
588+ for ( var i = offset ; i < count ; i ++ )
589+ #endif
582590 {
583591 var c = input [ i ] ;
584592 if ( c >> inputWidth != 0 )
0 commit comments