-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
StorageCrc64HashAlgorithm.cs
48 lines (41 loc) · 1.27 KB
/
StorageCrc64HashAlgorithm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.IO.Hashing;
namespace Azure.Storage
{
/// <summary>
/// Azure Storage CRC-64 implementation.
/// </summary>
public class StorageCrc64HashAlgorithm : NonCryptographicHashAlgorithm
{
private ulong _uCRC;
private const int _hashSizeBytes = 8;
private StorageCrc64HashAlgorithm(ulong uCrc)
: base(_hashSizeBytes)
{
_uCRC = uCrc;
}
/// <summary>
/// Creates a new instance of <see cref="StorageCrc64HashAlgorithm"/>.
/// </summary>
/// <returns></returns>
public static StorageCrc64HashAlgorithm Create()
{
return new StorageCrc64HashAlgorithm(0UL);
}
/// <inheritdoc/>
public override void Reset()
{
_uCRC = 0;
}
/// <inheritdoc/>
public override void Append(ReadOnlySpan<byte> source)
{
_uCRC = StorageCrc64Calculator.ComputeSlicedSafe(source, _uCRC);
}
/// <inheritdoc/>
protected override void GetCurrentHashCore(Span<byte> destination)
=> BitConverter.GetBytes(_uCRC).CopyTo(destination);
}
}