Skip to content

Commit

Permalink
Fix netstandard2.0 and framework
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasDorier committed Jan 16, 2025
1 parent 54702d2 commit 725a14b
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions NBitcoin/DataEncoders/Bech32Encoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,8 @@ public virtual string EncodeData(ReadOnlySpan<byte> data, Bech32EncodingType enc
if (SquashBytes)
data = ByteSquasher(data, 8, 5).AsSpan();
#else
data = ByteSquasher(data, 8, 5);
if (SquashBytes)
data = ByteSquasher(data, offset, count, 8, 5);
#endif

#if HAS_SPAN
Expand Down Expand Up @@ -561,7 +562,11 @@ protected virtual byte[] DecodeDataCore(string encoded, out Bech32EncodingType e
#endif
if (SquashBytes)
{
#if HAS_SPAN
arr = ByteSquasher(arr, 5, 8);
#else
arr = ByteSquasher(arr, 0, arr.Length, 5, 8);
#endif
if (arr is null)
throw new FormatException("Invalid squashed bech32");
}
Expand All @@ -570,15 +575,18 @@ protected virtual byte[] DecodeDataCore(string encoded, out Bech32EncodingType e
#if HAS_SPAN
private static byte[] ByteSquasher(ReadOnlySpan<byte> input, int inputWidth, int outputWidth)
#else
private static byte[] ByteSquasher(byte[] input, int inputWidth, int outputWidth)
private static byte[] ByteSquasher(byte[] input, int offset, int count, int inputWidth, int outputWidth)
#endif
{
var bitstash = 0;
var accumulator = 0;
var output = new List<byte>();
var maxOutputValue = (1 << outputWidth) - 1;

#if HAS_SPAN
for (var i = 0; i < input.Length; i++)
#else
for (var i = offset; i < count; i++)
#endif
{
var c = input[i];
if (c >> inputWidth != 0)
Expand Down

0 comments on commit 725a14b

Please sign in to comment.