Skip to content

Commit bbcaf18

Browse files
committed
Fix netstandard2.0 and framework
1 parent 54702d2 commit bbcaf18

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

NBitcoin/DataEncoders/Bech32Encoder.cs

+15-3
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,12 @@ 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+
{
428+
data = ByteSquasher(data, offset, count, 8, 5);
429+
count = data.Length;
430+
offset = 0;
431+
}
427432
#endif
428433

429434
#if HAS_SPAN
@@ -561,7 +566,11 @@ protected virtual byte[] DecodeDataCore(string encoded, out Bech32EncodingType e
561566
#endif
562567
if (SquashBytes)
563568
{
569+
#if HAS_SPAN
564570
arr = ByteSquasher(arr, 5, 8);
571+
#else
572+
arr = ByteSquasher(arr, 0, arr.Length, 5, 8);
573+
#endif
565574
if (arr is null)
566575
throw new FormatException("Invalid squashed bech32");
567576
}
@@ -570,15 +579,18 @@ protected virtual byte[] DecodeDataCore(string encoded, out Bech32EncodingType e
570579
#if HAS_SPAN
571580
private static byte[] ByteSquasher(ReadOnlySpan<byte> input, int inputWidth, int outputWidth)
572581
#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)
574583
#endif
575584
{
576585
var bitstash = 0;
577586
var accumulator = 0;
578587
var output = new List<byte>();
579588
var maxOutputValue = (1 << outputWidth) - 1;
580-
589+
#if HAS_SPAN
581590
for (var i = 0; i < input.Length; i++)
591+
#else
592+
for (var i = offset; i < count; i++)
593+
#endif
582594
{
583595
var c = input[i];
584596
if (c >> inputWidth != 0)

0 commit comments

Comments
 (0)