Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
HMACCommon.cs
Go to the documentation of this file.
1using System;
3
5
6internal sealed class HMACCommon
7{
8 private readonly string _hashAlgorithmId;
9
11
13
14 private readonly int _blockSize;
15
16 public int HashSizeInBits => _hMacProvider.HashSizeInBytes * 8;
17
19
20 public byte[] ActualKey { get; private set; }
21
22 public HMACCommon(string hashAlgorithmId, byte[] key, int blockSize)
23 : this(hashAlgorithmId, (ReadOnlySpan<byte>)key, blockSize)
24 {
25 if (ActualKey == null)
26 {
27 byte[] array2 = (ActualKey = key);
28 }
29 }
30
31 internal HMACCommon(string hashAlgorithmId, ReadOnlySpan<byte> key, int blockSize)
32 {
33 _hashAlgorithmId = hashAlgorithmId;
34 _blockSize = blockSize;
36 }
37
38 public void ChangeKey(byte[] key)
39 {
41 }
42
43 [MemberNotNull("_hMacProvider")]
45 {
46 byte[] result = null;
47 if (key.Length > _blockSize && _blockSize > 0)
48 {
49 if (_lazyHashProvider == null)
50 {
52 }
55 }
56 HashProvider hMacProvider = _hMacProvider;
57 _hMacProvider = null;
58 hMacProvider?.Dispose(disposing: true);
60 return result;
61 }
62
63 public void AppendHashData(byte[] data, int offset, int count)
64 {
66 }
67
72
73 public byte[] FinalizeHashAndReset()
74 {
76 }
77
82
83 public bool TryFinalizeHashAndReset(Span<byte> destination, out int bytesWritten)
84 {
85 return _hMacProvider.TryFinalizeHashAndReset(destination, out bytesWritten);
86 }
87
92
93 public void Reset()
94 {
96 }
97
98 public void Dispose(bool disposing)
99 {
100 if (disposing)
101 {
102 _hMacProvider?.Dispose(disposing: true);
103 _hMacProvider = null;
104 _lazyHashProvider?.Dispose(disposing: true);
105 _lazyHashProvider = null;
106 }
107 }
108}
readonly string _hashAlgorithmId
Definition HMACCommon.cs:8
int FinalizeHashAndReset(Span< byte > destination)
Definition HMACCommon.cs:78
volatile HashProvider _lazyHashProvider
Definition HMACCommon.cs:12
void Dispose(bool disposing)
Definition HMACCommon.cs:98
int GetCurrentHash(Span< byte > destination)
Definition HMACCommon.cs:88
HMACCommon(string hashAlgorithmId, ReadOnlySpan< byte > key, int blockSize)
Definition HMACCommon.cs:31
bool TryFinalizeHashAndReset(Span< byte > destination, out int bytesWritten)
Definition HMACCommon.cs:83
void AppendHashData(byte[] data, int offset, int count)
Definition HMACCommon.cs:63
HMACCommon(string hashAlgorithmId, byte[] key, int blockSize)
Definition HMACCommon.cs:22
byte[] ChangeKeyImpl(ReadOnlySpan< byte > key)
Definition HMACCommon.cs:44
void AppendHashData(ReadOnlySpan< byte > source)
Definition HMACCommon.cs:68
static HashProvider CreateMacProvider(string hashAlgorithmId, ReadOnlySpan< byte > key)
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)
int GetCurrentHash(Span< byte > destination)