@@ -423,7 +423,12 @@ public virtual string EncodeData(ReadOnlySpan<byte> data, Bech32EncodingType enc
423
423
if ( SquashBytes )
424
424
data = ByteSquasher ( data , 8 , 5 ) . AsSpan ( ) ;
425
425
#else
426
- data = ByteSquasher ( data , 8 , 5 ) ;
426
+ if ( SquashBytes )
427
+ {
428
+ data = ByteSquasher ( data , offset , count , 8 , 5 ) ;
429
+ count = data . Length ;
430
+ offset = 0 ;
431
+ }
427
432
#endif
428
433
429
434
#if HAS_SPAN
@@ -561,7 +566,11 @@ protected virtual byte[] DecodeDataCore(string encoded, out Bech32EncodingType e
561
566
#endif
562
567
if ( SquashBytes )
563
568
{
569
+ #if HAS_SPAN
564
570
arr = ByteSquasher ( arr , 5 , 8 ) ;
571
+ #else
572
+ arr = ByteSquasher ( arr , 0 , arr . Length , 5 , 8 ) ;
573
+ #endif
565
574
if ( arr is null )
566
575
throw new FormatException ( "Invalid squashed bech32" ) ;
567
576
}
@@ -570,15 +579,18 @@ protected virtual byte[] DecodeDataCore(string encoded, out Bech32EncodingType e
570
579
#if HAS_SPAN
571
580
private static byte [ ] ByteSquasher ( ReadOnlySpan < byte > input , int inputWidth , int outputWidth )
572
581
#else
573
- private static byte [ ] ByteSquasher ( byte [ ] input , int inputWidth , int outputWidth )
582
+ private static byte [ ] ByteSquasher ( byte [ ] input , int offset , int count , int inputWidth , int outputWidth )
574
583
#endif
575
584
{
576
585
var bitstash = 0 ;
577
586
var accumulator = 0 ;
578
587
var output = new List < byte > ( ) ;
579
588
var maxOutputValue = ( 1 << outputWidth ) - 1 ;
580
-
589
+ #if HAS_SPAN
581
590
for ( var i = 0 ; i < input . Length ; i ++ )
591
+ #else
592
+ for ( var i = offset ; i < count ; i ++ )
593
+ #endif
582
594
{
583
595
var c = input [ i ] ;
584
596
if ( c >> inputWidth != 0 )
0 commit comments