Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
HashAlgorithmName.cs
Go to the documentation of this file.
2
4
5public readonly struct HashAlgorithmName : IEquatable<HashAlgorithmName>
6{
7 private readonly string _name;
8
9 public static HashAlgorithmName MD5 => new HashAlgorithmName("MD5");
10
11 public static HashAlgorithmName SHA1 => new HashAlgorithmName("SHA1");
12
13 public static HashAlgorithmName SHA256 => new HashAlgorithmName("SHA256");
14
15 public static HashAlgorithmName SHA384 => new HashAlgorithmName("SHA384");
16
17 public static HashAlgorithmName SHA512 => new HashAlgorithmName("SHA512");
18
19 public string? Name => _name;
20
21 public HashAlgorithmName(string? name)
22 {
23 _name = name;
24 }
25
26 public override string ToString()
27 {
28 return _name ?? string.Empty;
29 }
30
31 public override bool Equals([NotNullWhen(true)] object? obj)
32 {
34 {
36 }
37 return false;
38 }
39
41 {
42 return _name == other._name;
43 }
44
45 public override int GetHashCode()
46 {
47 if (_name != null)
48 {
49 return _name.GetHashCode();
50 }
51 return 0;
52 }
53
54 public static bool operator ==(HashAlgorithmName left, HashAlgorithmName right)
55 {
56 return left.Equals(right);
57 }
58
59 public static bool operator !=(HashAlgorithmName left, HashAlgorithmName right)
60 {
61 return !(left == right);
62 }
63
64 public static bool TryFromOid(string oidValue, out HashAlgorithmName value)
65 {
66 if (oidValue == null)
67 {
68 throw new ArgumentNullException("oidValue");
69 }
70 switch (oidValue)
71 {
72 case "1.2.840.113549.2.5":
73 value = MD5;
74 return true;
75 case "1.3.14.3.2.26":
76 value = SHA1;
77 return true;
78 case "2.16.840.1.101.3.4.2.1":
79 value = SHA256;
80 return true;
81 case "2.16.840.1.101.3.4.2.2":
82 value = SHA384;
83 return true;
84 case "2.16.840.1.101.3.4.2.3":
85 value = SHA512;
86 return true;
87 default:
88 value = default(HashAlgorithmName);
89 return false;
90 }
91 }
92
93 public static HashAlgorithmName FromOid(string oidValue)
94 {
95 if (TryFromOid(oidValue, out var value))
96 {
97 return value;
98 }
100 }
101}
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string Cryptography_InvalidHashAlgorithmOid
Definition SR.cs:50
Definition SR.cs:7
override bool Equals([NotNullWhen(true)] object? obj)
static bool operator==(HashAlgorithmName left, HashAlgorithmName right)
static bool TryFromOid(string oidValue, out HashAlgorithmName value)
static HashAlgorithmName FromOid(string oidValue)
static bool operator!=(HashAlgorithmName left, HashAlgorithmName right)