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 bbcaf18
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions NBitcoin/DataEncoders/Bech32Encoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,12 @@ 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);
count = data.Length;
offset = 0;
}
#endif

#if HAS_SPAN
Expand Down Expand Up @@ -561,7 +566,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 +579,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 bbcaf18

Please sign in to comment.