Skip to content

Commit 9f9f1f7

Browse files
committed
remove WIP Base32 EncodeCheck
1 parent d5326c5 commit 9f9f1f7

3 files changed

Lines changed: 1 addition & 274 deletions

File tree

src/Base32.cs

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -421,59 +421,6 @@ public bool TryDecode(ReadOnlySpan<char> input, Span<byte> output, out int bytes
421421
return internalDecode(input[..inputLen], output, out bytesWritten) == DecodeResult.Success;
422422
}
423423

424-
/// <summary>
425-
/// Perform Base32 with Digest and checksum encoding (Stacks Crockford Base32).
426-
/// </summary>
427-
/// <param name="input">Input buffer.</param>
428-
/// <param name="version">Version byte.</param>
429-
/// <returns>Encoded address with checksum.</returns>
430-
public string EncodeCheck(ReadOnlySpan<byte> input, byte version)
431-
{
432-
int bufferSize = 1 + input.Length + Sha256.DigestBytes;
433-
byte[] output = new byte[bufferSize];
434-
output[0] = version;
435-
input.CopyTo(output.AsSpan(1));
436-
Sha256.ComputeDigestTwice(output.AsSpan(0, input.Length + 1), output.AsSpan(input.Length + 1));
437-
return Encode(output);
438-
}
439-
440-
/// <summary>
441-
/// Try decoding a Base32 encoded address with checksum.
442-
/// </summary>
443-
/// <param name="input">Encoded string.</param>
444-
/// <param name="decodedAddress">Buffer for the decoded address.</param>
445-
/// <param name="version">Version number extracted from <paramref name="input"/>.</param>
446-
/// <param name="addressLength">Written number of bytes to <paramref name="decodedAddress"/>.</param>
447-
/// <returns>
448-
/// <see langword="true"/> if address is decoded successfully and checksum matches,
449-
/// <see langword="false"/> otherwise.
450-
/// </returns>
451-
public bool TryDecodeCheck(ReadOnlySpan<char> input, Span<byte> decodedAddress, out byte version, out int addressLength)
452-
{
453-
int bufferSize = GetSafeByteCountForDecoding(input);
454-
var buffer = bufferSize < Bits.SafeStackMaxAllocSize ? stackalloc byte[bufferSize] : new byte[bufferSize];
455-
version = 0;
456-
addressLength = 0;
457-
if (!TryDecode(input, buffer, out int outputLength)
458-
|| outputLength < Sha256.DigestBytes + 2
459-
|| decodedAddress.Length < outputLength - Sha256.DigestBytes - 1)
460-
{
461-
return false;
462-
}
463-
464-
Span<byte> digest = stackalloc byte[Sha256.DigestBytes];
465-
Sha256.ComputeDigestTwice(buffer[..^Sha256.DigestBytes], digest);
466-
if (!digest.SequenceEqual(buffer[^Sha256.DigestBytes..]))
467-
{
468-
return false;
469-
}
470-
471-
buffer[1..^Sha256.DigestBytes].CopyTo(decodedAddress);
472-
addressLength = outputLength - Sha256.DigestBytes - 1;
473-
version = buffer[0];
474-
return true;
475-
}
476-
477424
static int getAllocationByteCountForDecoding(int textLenWithoutPadding)
478425
{
479426
return textLenWithoutPadding * bitsPerChar / bitsPerByte;

src/PublicAPI.Unshipped.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
SimpleBase.Base58.EncodeCheck(System.ReadOnlySpan<byte> payload, System.ReadOnlySpan<byte> prefix) -> string!
22
SimpleBase.Base58.EncodeCheckSkipZeroes(System.ReadOnlySpan<byte> payload, System.ReadOnlySpan<byte> prefix) -> string!
3-
SimpleBase.Base58.TryDecodeCheck(System.ReadOnlySpan<char> address, System.Span<byte> payload, System.Span<byte> prefix, out int payloadBytesWritten) -> bool
4-
SimpleBase.Base32.EncodeCheck(System.ReadOnlySpan<byte> input, byte version) -> string!
5-
SimpleBase.Base32.TryDecodeCheck(System.ReadOnlySpan<char> input, System.Span<byte> decodedAddress, out byte version, out int addressLength) -> bool
3+
SimpleBase.Base58.TryDecodeCheck(System.ReadOnlySpan<char> address, System.Span<byte> payload, System.Span<byte> prefix, out int payloadBytesWritten) -> bool

test/Base32/CrockfordEncodeCheckTest.cs

Lines changed: 0 additions & 218 deletions
This file was deleted.

0 commit comments

Comments
 (0)