Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
SHA1.cs
Go to the documentation of this file.
3
5
6public abstract class SHA1 : HashAlgorithm
7{
8 private sealed class Implementation : SHA1
9 {
10 private readonly HashProvider _hashProvider;
11
13 {
15 HashSizeValue = _hashProvider.HashSizeInBytes * 8;
16 }
17
18 protected sealed override void HashCore(byte[] array, int ibStart, int cbSize)
19 {
20 _hashProvider.AppendHashData(array, ibStart, cbSize);
21 }
22
23 protected sealed override void HashCore(ReadOnlySpan<byte> source)
24 {
26 }
27
28 protected sealed override byte[] HashFinal()
29 {
31 }
32
33 protected sealed override bool TryHashFinal(Span<byte> destination, out int bytesWritten)
34 {
35 return _hashProvider.TryFinalizeHashAndReset(destination, out bytesWritten);
36 }
37
38 public sealed override void Initialize()
39 {
41 }
42
43 protected sealed override void Dispose(bool disposing)
44 {
45 _hashProvider.Dispose(disposing);
46 base.Dispose(disposing);
47 }
48 }
49
50 protected SHA1()
51 {
52 HashSizeValue = 160;
53 }
54
55 public new static SHA1 Create()
56 {
57 return new Implementation();
58 }
59
60 [RequiresUnreferencedCode("The default algorithm implementations might be removed, use strong type references like 'RSA.Create()' instead.")]
61 public new static SHA1? Create(string hashName)
62 {
63 return (SHA1)CryptoConfig.CreateFromName(hashName);
64 }
65
66 public static byte[] HashData(byte[] source)
67 {
68 if (source == null)
69 {
70 throw new ArgumentNullException("source");
71 }
73 }
74
75 public static byte[] HashData(ReadOnlySpan<byte> source)
76 {
77 byte[] array = GC.AllocateUninitializedArray<byte>(20);
78 int num = HashData(source, array.AsSpan());
79 return array;
80 }
81
83 {
84 if (!TryHashData(source, destination, out var bytesWritten))
85 {
87 }
88 return bytesWritten;
89 }
90
91 public static bool TryHashData(ReadOnlySpan<byte> source, Span<byte> destination, out int bytesWritten)
92 {
93 if (destination.Length < 20)
94 {
95 bytesWritten = 0;
96 return false;
97 }
99 return true;
100 }
101}
static int HashData(string hashAlgorithmId, ReadOnlySpan< byte > source, Span< byte > destination)
static HashProvider CreateHashProvider(string hashAlgorithmId)
void AppendHashData(byte[] data, int offset, int count)
bool TryFinalizeHashAndReset(Span< byte > destination, out int bytesWritten)
int FinalizeHashAndReset(Span< byte > destination)
Definition GC.cs:8
static string Argument_DestinationTooShort
Definition SR.cs:14
Definition SR.cs:7
static ? object CreateFromName(string name, params object?[]? args)
override void HashCore(ReadOnlySpan< byte > source)
Definition SHA1.cs:23
override bool TryHashFinal(Span< byte > destination, out int bytesWritten)
Definition SHA1.cs:33
override void Dispose(bool disposing)
Definition SHA1.cs:43
override void HashCore(byte[] array, int ibStart, int cbSize)
Definition SHA1.cs:18
static new? SHA1 Create(string hashName)
Definition SHA1.cs:61
static int HashData(ReadOnlySpan< byte > source, Span< byte > destination)
Definition SHA1.cs:82
static byte[] HashData(byte[] source)
Definition SHA1.cs:66
static new SHA1 Create()
Definition SHA1.cs:55
static byte[] HashData(ReadOnlySpan< byte > source)
Definition SHA1.cs:75
static bool TryHashData(ReadOnlySpan< byte > source, Span< byte > destination, out int bytesWritten)
Definition SHA1.cs:91