From 725a14b8347e5ee63915f1f7a7aefc1fae7b70c3 Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Thu, 16 Jan 2025 23:09:01 +0900 Subject: [PATCH] Fix netstandard2.0 and framework --- NBitcoin/DataEncoders/Bech32Encoder.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/NBitcoin/DataEncoders/Bech32Encoder.cs b/NBitcoin/DataEncoders/Bech32Encoder.cs index 0df0b513b..656c850b9 100644 --- a/NBitcoin/DataEncoders/Bech32Encoder.cs +++ b/NBitcoin/DataEncoders/Bech32Encoder.cs @@ -423,7 +423,8 @@ public virtual string EncodeData(ReadOnlySpan 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 @@ -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"); } @@ -570,15 +575,18 @@ protected virtual byte[] DecodeDataCore(string encoded, out Bech32EncodingType e #if HAS_SPAN private static byte[] ByteSquasher(ReadOnlySpan 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(); 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)