From bbcaf18c06e492d4323d7b8a8ae63f70d1b15833 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 | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/NBitcoin/DataEncoders/Bech32Encoder.cs b/NBitcoin/DataEncoders/Bech32Encoder.cs index 0df0b513b..63cf054c7 100644 --- a/NBitcoin/DataEncoders/Bech32Encoder.cs +++ b/NBitcoin/DataEncoders/Bech32Encoder.cs @@ -423,7 +423,12 @@ 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); + count = data.Length; + offset = 0; + } #endif #if HAS_SPAN @@ -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"); } @@ -570,15 +579,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)