1- // *
1+ // *
22// *****************************************************************************
33// *
44// * Copyright (c) 2025 Deskasoft International
@@ -41,35 +41,38 @@ namespace HashifyNet.Algorithms.Argon2id
4141 public static class Argon2idDecoder
4242 {
4343 /// <summary>
44- /// Decodes the specified segment of a byte array into its original form .
44+ /// Decodes the specified byte array and returns the resulting data .
4545 /// </summary>
46- /// <param name="data">The segment of the byte array to decode. The segment must not be empty .</param>
47- /// <returns>A byte array containing the decoded data .</returns>
48- public static byte [ ] Decode ( ArraySegment < byte > data )
46+ /// <param name="data">The byte array to decode. Cannot be <see langword="null"/> .</param>
47+ /// <returns>The decoded byte array, or <see langword="null"/> if decoding fails .</returns>
48+ public static byte [ ] Decode ( byte [ ] data )
4949 {
5050 Argon2Config config = new Argon2Config ( ) ;
51- if ( ! DecodeExtension . DecodeString ( config , Argon2idSerializer . Deserialize ( data . Array ) , out var buffer ) )
51+ if ( ! DecodeExtension . DecodeString ( config , Argon2idSerializer . Deserialize ( data ) , out var buffer ) )
5252 {
5353 return null ;
5454 }
5555
5656 return buffer . Buffer ;
5757 }
5858
59+ #if NET8_0_OR_GREATER
5960 /// <summary>
60- /// Decodes the specified byte array and returns the resulting data.
61+ /// Decodes the specified read-only span of bytes and returns the resulting data.
6162 /// </summary>
62- /// <param name="data">The byte array to decode. Cannot be null .</param>
63- /// <returns>A byte array containing the decoded data .</returns>
64- public static byte [ ] Decode ( byte [ ] data )
63+ /// <param name="data">The read-only span of bytes to decode .</param>
64+ /// <returns>The decoded byte array, or <see langword="null"/> if decoding fails .</returns>
65+ public static byte [ ] Decode ( ReadOnlySpan < byte > data )
6566 {
66- if ( data == null )
67+ Argon2Config config = new Argon2Config ( ) ;
68+ if ( ! DecodeExtension . DecodeString ( config , Argon2idSerializer . Deserialize ( data ) , out var buffer ) )
6769 {
68- throw new ArgumentNullException ( nameof ( data ) ) ;
70+ return null ;
6971 }
7072
71- return Decode ( new ArraySegment < byte > ( data ) ) ;
73+ return buffer . Buffer ;
7274 }
75+ #endif
7376
7477 /// <summary>
7578 /// Decodes the hash value of an Argon2id hash into its raw byte representation.
@@ -88,4 +91,3 @@ public static byte[] DecodeArgon2id(this IHashValue val)
8891 }
8992 }
9093}
91-
0 commit comments