@@ -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 ;
0 commit comments