Skip to content

Commit 71a330c

Browse files
committed
Better HashTool documentation
1 parent ad8d119 commit 71a330c

File tree

1 file changed

+43
-4
lines changed

1 file changed

+43
-4
lines changed

SabreTools.Hashing/HashTool.cs

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ public static class HashTool
1616
/// Get CRC-32, MD5, and SHA-1 hashes from an input file path
1717
/// </summary>
1818
/// <param name="filename">Path to the input file</param>
19+
/// <param name="size">Calculated file size on success, -1 on error</param>
20+
/// <param name="crc32">CRC-32 for the input file</param>
21+
/// <param name="md5">MD5 for the input file</param>
22+
/// <param name="sha1">SHA-1 for the input file</param>
1923
/// <returns>True if hashing was successful, false otherwise</returns>
2024
public static bool GetStandardHashes(string filename, out long size, out string? crc32, out string? md5, out string? sha1)
2125
{
@@ -39,6 +43,10 @@ public static bool GetStandardHashes(string filename, out long size, out string?
3943
/// Get CRC-32, MD5, and SHA-1 hashes from an input stream
4044
/// </summary>
4145
/// <param name="stream">Input stream</param>
46+
/// <param name="size">Calculated file size on success, -1 on error</param>
47+
/// <param name="crc32">CRC-32 for the input file</param>
48+
/// <param name="md5">MD5 for the input file</param>
49+
/// <param name="sha1">SHA-1 for the input file</param>
4250
/// <returns>True if hashing was successful, false otherwise</returns>
4351
public static bool GetStandardHashes(Stream stream, out long size, out string? crc32, out string? md5, out string? sha1)
4452
{
@@ -120,6 +128,7 @@ public static bool GetStandardHashes(Stream stream, out long size, out string? c
120128
/// Get hashes and size from an input file path
121129
/// </summary>
122130
/// <param name="filename">Path to the input file</param>
131+
/// <param name="size">Amount of bytes read during hashing</param>
123132
/// <returns>Dictionary containing hashes on success, null on error</returns>
124133
public static Dictionary<HashType, string?>? GetFileHashesAndSize(string filename, out long size)
125134
{
@@ -134,6 +143,7 @@ public static bool GetStandardHashes(Stream stream, out long size, out string? c
134143
/// Get hashes and size from an input file path
135144
/// </summary>
136145
/// <param name="filename">Path to the input file</param>
146+
/// <param name="size">Amount of bytes read during hashing</param>
137147
/// <returns>Dictionary containing hashes on success, null on error</returns>
138148
public static Dictionary<HashType, byte[]?>? GetFileHashArraysAndSize(string filename, out long size)
139149
{
@@ -149,6 +159,7 @@ public static bool GetStandardHashes(Stream stream, out long size, out string? c
149159
/// </summary>
150160
/// <param name="filename">Path to the input file</param>
151161
/// <param name="hashType">Hash type to get from the file</param>
162+
/// <param name="size">Amount of bytes read during hashing</param>
152163
/// <returns>Hash and size on success, null on error</returns>
153164
public static string? GetFileHashAndSize(string filename, HashType hashType, out long size)
154165
{
@@ -161,6 +172,7 @@ public static bool GetStandardHashes(Stream stream, out long size, out string? c
161172
/// </summary>
162173
/// <param name="filename">Path to the input file</param>
163174
/// <param name="hashType">Hash type to get from the file</param>
175+
/// <param name="size">Amount of bytes read during hashing</param>
164176
/// <returns>Hash and size on success, null on error</returns>
165177
public static byte[]? GetFileHashArrayAndSize(string filename, HashType hashType, out long size)
166178
{
@@ -173,6 +185,7 @@ public static bool GetStandardHashes(Stream stream, out long size, out string? c
173185
/// </summary>
174186
/// <param name="filename">Path to the input file</param>
175187
/// <param name="hashTypes">Array of hash types to get from the file</param>
188+
/// <param name="size">Amount of bytes read during hashing</param>
176189
/// <returns>Dictionary containing hashes on success, null on error</returns>
177190
public static Dictionary<HashType, string?>? GetFileHashesAndSize(string filename, HashType[] hashTypes, out long size)
178191
{
@@ -195,6 +208,7 @@ public static bool GetStandardHashes(Stream stream, out long size, out string? c
195208
/// </summary>
196209
/// <param name="filename">Path to the input file</param>
197210
/// <param name="hashTypes">Array of hash types to get from the file</param>
211+
/// <param name="size">Amount of bytes read during hashing</param>
198212
/// <returns>Dictionary containing hashes on success, null on error</returns>
199213
public static Dictionary<HashType, byte[]?>? GetFileHashArraysAndSize(string filename, HashType[] hashTypes, out long size)
200214
{
@@ -294,6 +308,7 @@ public static bool GetStandardHashes(Stream stream, out long size, out string? c
294308
/// Get hashes from an input Stream
295309
/// </summary>
296310
/// <param name="input">Stream to hash</param>
311+
/// <param name="leaveOpen">Indicates if the source stream should be left open after hashing</param>
297312
/// <returns>Dictionary containing hashes on success, null on error</returns>
298313
public static Dictionary<HashType, string?>? GetStreamHashes(Stream input, bool leaveOpen = false)
299314
=> GetStreamHashesAndSize(input, leaveOpen, out _);
@@ -302,6 +317,7 @@ public static bool GetStandardHashes(Stream stream, out long size, out string? c
302317
/// Get hashes from an input Stream
303318
/// </summary>
304319
/// <param name="input">Stream to hash</param>
320+
/// <param name="leaveOpen">Indicates if the source stream should be left open after hashing</param>
305321
/// <returns>Dictionary containing hashes on success, null on error</returns>
306322
public static Dictionary<HashType, byte[]?>? GetStreamHashArrays(Stream input, bool leaveOpen = false)
307323
=> GetStreamHashArraysAndSize(input, leaveOpen, out _);
@@ -311,6 +327,7 @@ public static bool GetStandardHashes(Stream stream, out long size, out string? c
311327
/// </summary>
312328
/// <param name="input">Stream to hash</param>
313329
/// <param name="hashType">Hash type to get from the file</param>
330+
/// <param name="leaveOpen">Indicates if the source stream should be left open after hashing</param>
314331
/// <returns>Hash on success, null on error</returns>
315332
public static string? GetStreamHash(Stream input, HashType hashType, bool leaveOpen = false)
316333
=> GetStreamHashAndSize(input, hashType, leaveOpen, out _);
@@ -320,6 +337,7 @@ public static bool GetStandardHashes(Stream stream, out long size, out string? c
320337
/// </summary>
321338
/// <param name="input">Stream to hash</param>
322339
/// <param name="hashType">Hash type to get from the file</param>
340+
/// <param name="leaveOpen">Indicates if the source stream should be left open after hashing</param>
323341
/// <returns>Hash on success, null on error</returns>
324342
public static byte[]? GetStreamHashArray(Stream input, HashType hashType, bool leaveOpen = false)
325343
=> GetStreamHashArrayAndSize(input, hashType, leaveOpen, out _);
@@ -329,6 +347,7 @@ public static bool GetStandardHashes(Stream stream, out long size, out string? c
329347
/// </summary>
330348
/// <param name="input">Stream to hash</param>
331349
/// <param name="hashTypes">Array of hash types to get from the file</param>
350+
/// <param name="leaveOpen">Indicates if the source stream should be left open after hashing</param>
332351
/// <returns>Dictionary containing hashes on success, null on error</returns>
333352
public static Dictionary<HashType, string?>? GetStreamHashes(Stream input, HashType[] hashTypes, bool leaveOpen = false)
334353
=> GetStreamHashesAndSize(input, hashTypes, leaveOpen, out _);
@@ -338,6 +357,7 @@ public static bool GetStandardHashes(Stream stream, out long size, out string? c
338357
/// </summary>
339358
/// <param name="input">Stream to hash</param>
340359
/// <param name="hashTypes">Array of hash types to get from the file</param>
360+
/// <param name="leaveOpen">Indicates if the source stream should be left open after hashing</param>
341361
/// <returns>Dictionary containing hashes on success, null on error</returns>
342362
public static Dictionary<HashType, byte[]?>? GetStreamHashArrays(Stream input, HashType[] hashTypes, bool leaveOpen = false)
343363
=> GetStreamHashArraysAndSize(input, hashTypes, leaveOpen, out _);
@@ -350,6 +370,7 @@ public static bool GetStandardHashes(Stream stream, out long size, out string? c
350370
/// Get hashes and size from an input Stream
351371
/// </summary>
352372
/// <param name="input">Stream to hash</param>
373+
/// <param name="size">Amount of bytes read during hashing</param>
353374
/// <returns>Dictionary containing hashes on success, null on error</returns>
354375
public static Dictionary<HashType, string?>? GetStreamHashesAndSize(Stream input, out long size)
355376
=> GetStreamHashesAndSize(input, leaveOpen: false, out size);
@@ -358,6 +379,8 @@ public static bool GetStandardHashes(Stream stream, out long size, out string? c
358379
/// Get hashes and size from an input Stream
359380
/// </summary>
360381
/// <param name="input">Stream to hash</param>
382+
/// <param name="leaveOpen">Indicates if the source stream should be left open after hashing</param>
383+
/// <param name="size">Amount of bytes read during hashing</param>
361384
/// <returns>Dictionary containing hashes on success, null on error</returns>
362385
public static Dictionary<HashType, string?>? GetStreamHashesAndSize(Stream input, bool leaveOpen, out long size)
363386
{
@@ -372,6 +395,7 @@ public static bool GetStandardHashes(Stream stream, out long size, out string? c
372395
/// Get hashes and size from an input Stream
373396
/// </summary>
374397
/// <param name="input">Stream to hash</param>
398+
/// <param name="size">Amount of bytes read during hashing</param>
375399
/// <returns>Dictionary containing hashes on success, null on error</returns>
376400
public static Dictionary<HashType, byte[]?>? GetStreamHashArraysAndSize(Stream input, out long size)
377401
=> GetStreamHashArraysAndSize(input, leaveOpen: false, out size);
@@ -380,6 +404,8 @@ public static bool GetStandardHashes(Stream stream, out long size, out string? c
380404
/// Get hashes and size from an input Stream
381405
/// </summary>
382406
/// <param name="input">Stream to hash</param>
407+
/// <param name="leaveOpen">Indicates if the source stream should be left open after hashing</param>
408+
/// <param name="size">Amount of bytes read during hashing</param>
383409
/// <returns>Dictionary containing hashes on success, null on error</returns>
384410
public static Dictionary<HashType, byte[]?>? GetStreamHashArraysAndSize(Stream input, bool leaveOpen, out long size)
385411
{
@@ -395,6 +421,7 @@ public static bool GetStandardHashes(Stream stream, out long size, out string? c
395421
/// </summary>
396422
/// <param name="input">Stream to hash</param>
397423
/// <param name="hashType">Hash type to get from the file</param>
424+
/// <param name="size">Amount of bytes read during hashing</param>
398425
/// <returns>Hash on success, null on error</returns>
399426
public static string? GetStreamHashAndSize(Stream input, HashType hashType, out long size)
400427
=> GetStreamHashAndSize(input, hashType, leaveOpen: false, out size);
@@ -404,6 +431,8 @@ public static bool GetStandardHashes(Stream stream, out long size, out string? c
404431
/// </summary>
405432
/// <param name="input">Stream to hash</param>
406433
/// <param name="hashType">Hash type to get from the file</param>
434+
/// <param name="leaveOpen">Indicates if the source stream should be left open after hashing</param>
435+
/// <param name="size">Amount of bytes read during hashing</param>
407436
/// <returns>Hash on success, null on error</returns>
408437
public static string? GetStreamHashAndSize(Stream input, HashType hashType, bool leaveOpen, out long size)
409438
{
@@ -416,6 +445,7 @@ public static bool GetStandardHashes(Stream stream, out long size, out string? c
416445
/// </summary>
417446
/// <param name="input">Stream to hash</param>
418447
/// <param name="hashType">Hash type to get from the file</param>
448+
/// <param name="size">Amount of bytes read during hashing</param>
419449
/// <returns>Hash on success, null on error</returns>
420450
public static byte[]? GetStreamHashArrayAndSize(Stream input, HashType hashType, out long size)
421451
=> GetStreamHashArrayAndSize(input, hashType, leaveOpen: false, out size);
@@ -425,6 +455,8 @@ public static bool GetStandardHashes(Stream stream, out long size, out string? c
425455
/// </summary>
426456
/// <param name="input">Stream to hash</param>
427457
/// <param name="hashType">Hash type to get from the file</param>
458+
/// <param name="leaveOpen">Indicates if the source stream should be left open after hashing</param>
459+
/// <param name="size">Amount of bytes read during hashing</param>
428460
/// <returns>Hash on success, null on error</returns>
429461
public static byte[]? GetStreamHashArrayAndSize(Stream input, HashType hashType, bool leaveOpen, out long size)
430462
{
@@ -437,6 +469,7 @@ public static bool GetStandardHashes(Stream stream, out long size, out string? c
437469
/// </summary>
438470
/// <param name="input">Stream to hash</param>
439471
/// <param name="hashTypes">Array of hash types to get from the file</param>
472+
/// <param name="size">Amount of bytes read during hashing</param>
440473
/// <returns>Dictionary containing hashes on success, null on error</returns>
441474
public static Dictionary<HashType, string?>? GetStreamHashesAndSize(Stream input, HashType[] hashTypes, out long size)
442475
=> GetStreamHashesAndSize(input, hashTypes, leaveOpen: false, out size);
@@ -446,6 +479,8 @@ public static bool GetStandardHashes(Stream stream, out long size, out string? c
446479
/// </summary>
447480
/// <param name="input">Stream to hash</param>
448481
/// <param name="hashTypes">Array of hash types to get from the file</param>
482+
/// <param name="leaveOpen">Indicates if the source stream should be left open after hashing</param>
483+
/// <param name="size">Amount of bytes read during hashing</param>
449484
/// <returns>Dictionary containing hashes on success, null on error</returns>
450485
public static Dictionary<HashType, string?>? GetStreamHashesAndSize(Stream input, HashType[] hashTypes, bool leaveOpen, out long size)
451486
{
@@ -493,6 +528,7 @@ public static bool GetStandardHashes(Stream stream, out long size, out string? c
493528
/// </summary>
494529
/// <param name="input">Stream to hash</param>
495530
/// <param name="hashTypes">Array of hash types to get from the file</param>
531+
/// <param name="size">Amount of bytes read during hashing</param>
496532
/// <returns>Dictionary containing hashes on success, null on error</returns>
497533
public static Dictionary<HashType, byte[]?>? GetStreamHashArraysAndSize(Stream input, HashType[] hashTypes, out long size)
498534
=> GetStreamHashArraysAndSize(input, hashTypes, leaveOpen: false, out size);
@@ -502,6 +538,8 @@ public static bool GetStandardHashes(Stream stream, out long size, out string? c
502538
/// </summary>
503539
/// <param name="input">Stream to hash</param>
504540
/// <param name="hashTypes">Array of hash types to get from the file</param>
541+
/// <param name="leaveOpen">Indicates if the source stream should be left open after hashing</param>
542+
/// <param name="size">Amount of bytes read during hashing</param>
505543
/// <returns>Dictionary containing hashes on success, null on error</returns>
506544
public static Dictionary<HashType, byte[]?>? GetStreamHashArraysAndSize(Stream input, HashType[] hashTypes, bool leaveOpen, out long size)
507545
{
@@ -545,11 +583,12 @@ public static bool GetStandardHashes(Stream stream, out long size, out string? c
545583
}
546584

547585
/// <summary>
548-
/// Get hashes from an input stream
586+
/// Get hashes and size from an input Stream
549587
/// </summary>
550-
/// <param name="input"></param>
551-
/// <param name="hashTypes"></param>
552-
/// <param name="leaveOpen"></param>
588+
/// <param name="input">Stream to hash</param>
589+
/// <param name="hashTypes">Array of hash types to get from the file</param>
590+
/// <param name="leaveOpen">Indicates if the source stream should be left open after hashing</param>
591+
/// <param name="size">Amount of bytes read during hashing</param>
553592
/// <returns></returns>
554593
private static Dictionary<HashType, HashWrapper>? GetStreamHashesInternal(Stream input, HashType[] hashTypes, bool leaveOpen, out long size)
555594
{

0 commit comments

Comments
 (0)