Overwrite
Complete Overwrite of the Folder with the free shard. ServUO 57.3 has been added.
This commit is contained in:
@@ -0,0 +1,167 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Security.Cryptography;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.Crypto
|
||||
{
|
||||
/// <summary>
|
||||
/// Jenkins Lookup 3 non-cryptographic HashAlgorithm implementation.
|
||||
/// Reference: https://en.wikipedia.org/wiki/Jenkins_hash_function
|
||||
/// </summary>
|
||||
[ComVisible(true)]
|
||||
public abstract class Jenkins3 : HashAlgorithm
|
||||
{
|
||||
private static readonly string[] _Names = { "J3", "Jenkins3", "Jenkins-3", "VitaNex.Crypto.Jenkins3" };
|
||||
|
||||
static Jenkins3()
|
||||
{
|
||||
CryptoConfig.AddAlgorithm(typeof(Jenkins3CryptoServiceProvider), _Names);
|
||||
}
|
||||
|
||||
[SecuritySafeCritical]
|
||||
public static new Jenkins3 Create()
|
||||
{
|
||||
return Create("VitaNex.Crypto.Jenkins3");
|
||||
}
|
||||
|
||||
[SecuritySafeCritical]
|
||||
public static new Jenkins3 Create(string algName)
|
||||
{
|
||||
return (Jenkins3)CryptoConfig.CreateFromName(algName);
|
||||
}
|
||||
|
||||
protected Jenkins3()
|
||||
{
|
||||
HashSizeValue = 64;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Jenkins Lookup 3 non-cryptographic HashAlgorithm implementation.
|
||||
/// Reference: https://en.wikipedia.org/wiki/Jenkins_hash_function
|
||||
/// </summary>
|
||||
public sealed class Jenkins3CryptoServiceProvider : Jenkins3
|
||||
{
|
||||
public const uint DeadBeef = 0xDEADBEEF;
|
||||
|
||||
private string _Seed;
|
||||
private uint _X0, _X1, _X2, _X3, _X4, _X5;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
_Seed = String.Empty;
|
||||
_X0 = _X1 = _X2 = _X3 = _X4 = _X5 = 0;
|
||||
}
|
||||
|
||||
protected override void HashCore(byte[] array, int ibStart, int cbSize)
|
||||
{
|
||||
if (ibStart == 0 && cbSize == array.Length)
|
||||
{
|
||||
_Seed += BitConverter.ToString(array);
|
||||
}
|
||||
else
|
||||
{
|
||||
_Seed += BitConverter.ToString(array, ibStart, cbSize);
|
||||
}
|
||||
}
|
||||
|
||||
protected override byte[] HashFinal()
|
||||
{
|
||||
_X0 = _X1 = _X2 = DeadBeef + (uint)_Seed.Length;
|
||||
_X3 = _X4 = 0;
|
||||
|
||||
int pos;
|
||||
|
||||
for (pos = 0; pos + 12 < _Seed.Length; pos += 12)
|
||||
{
|
||||
_X1 = (uint)((_Seed[pos + 7] << 24) | (_Seed[pos + 6] << 16) | (_Seed[pos + 5] << 8) | _Seed[pos + 4]) + _X1;
|
||||
_X2 = (uint)((_Seed[pos + 11] << 24) | (_Seed[pos + 10] << 16) | (_Seed[pos + 9] << 8) | _Seed[pos + 8]) + _X2;
|
||||
_X3 = (uint)((_Seed[pos + 3] << 24) | (_Seed[pos + 2] << 16) | (_Seed[pos + 1] << 8) | _Seed[pos]) - _X2;
|
||||
|
||||
_X3 = (_X3 + _X0) ^ (_X2 >> 28) ^ (_X2 << 4);
|
||||
_X2 += _X1;
|
||||
_X1 = (_X1 - _X3) ^ (_X3 >> 26) ^ (_X3 << 6);
|
||||
_X3 += _X2;
|
||||
_X2 = (_X2 - _X1) ^ (_X1 >> 24) ^ (_X1 << 8);
|
||||
_X1 += _X3;
|
||||
_X0 = (_X3 - _X2) ^ (_X2 >> 16) ^ (_X2 << 16);
|
||||
_X2 += _X1;
|
||||
_X1 = (_X1 - _X0) ^ (_X0 >> 13) ^ (_X0 << 19);
|
||||
_X0 += _X2;
|
||||
_X2 = (_X2 - _X1) ^ (_X1 >> 28) ^ (_X1 << 4);
|
||||
_X1 += _X0;
|
||||
}
|
||||
|
||||
var rem = _Seed.Length - pos;
|
||||
|
||||
if (rem <= 0)
|
||||
{
|
||||
return BitConverter.GetBytes(((ulong)_X2 << 32) | _X4);
|
||||
}
|
||||
|
||||
switch (rem)
|
||||
{
|
||||
case 12:
|
||||
_X2 += (uint)_Seed[pos + 11] << 24;
|
||||
goto case 11;
|
||||
case 11:
|
||||
_X2 += (uint)_Seed[pos + 10] << 16;
|
||||
goto case 10;
|
||||
case 10:
|
||||
_X2 += (uint)_Seed[pos + 9] << 8;
|
||||
goto case 9;
|
||||
case 9:
|
||||
_X2 += _Seed[pos + 8];
|
||||
goto case 8;
|
||||
case 8:
|
||||
_X1 += (uint)_Seed[pos + 7] << 24;
|
||||
goto case 7;
|
||||
case 7:
|
||||
_X1 += (uint)_Seed[pos + 6] << 16;
|
||||
goto case 6;
|
||||
case 6:
|
||||
_X1 += (uint)_Seed[pos + 5] << 8;
|
||||
goto case 5;
|
||||
case 5:
|
||||
_X1 += _Seed[pos + 4];
|
||||
goto case 4;
|
||||
case 4:
|
||||
_X0 += (uint)_Seed[pos + 3] << 24;
|
||||
goto case 3;
|
||||
case 3:
|
||||
_X0 += (uint)_Seed[pos + 2] << 16;
|
||||
goto case 2;
|
||||
case 2:
|
||||
_X0 += (uint)_Seed[pos + 1] << 8;
|
||||
goto case 1;
|
||||
case 1:
|
||||
_X0 += _Seed[pos];
|
||||
break;
|
||||
}
|
||||
|
||||
_X2 = (_X2 ^ _X1) - ((_X1 >> 18) ^ (_X1 << 14));
|
||||
_X5 = (_X2 ^ _X0) - ((_X2 >> 21) ^ (_X2 << 11));
|
||||
_X1 = (_X1 ^ _X5) - ((_X5 >> 7) ^ (_X5 << 25));
|
||||
_X2 = (_X2 ^ _X1) - ((_X1 >> 16) ^ (_X1 << 16));
|
||||
_X3 = (_X2 ^ _X5) - ((_X2 >> 28) ^ (_X2 << 4));
|
||||
_X1 = (_X1 ^ _X3) - ((_X3 >> 18) ^ (_X3 << 14));
|
||||
_X4 = (_X2 ^ _X1) - ((_X1 >> 8) ^ (_X1 << 24));
|
||||
|
||||
return BitConverter.GetBytes(((ulong)_X1 << 32) | _X4);
|
||||
}
|
||||
}
|
||||
}
|
||||
52
Scripts/SubSystem/VitaNex/Core/Services/Crypto/Crypto.cs
Normal file
52
Scripts/SubSystem/VitaNex/Core/Services/Crypto/Crypto.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.Crypto
|
||||
{
|
||||
public static partial class CryptoService
|
||||
{
|
||||
public static CryptoHashType[] HashTypes { get; private set; }
|
||||
|
||||
public static Dictionary<int, CryptoHashCodeProvider> Providers { get; private set; }
|
||||
|
||||
public static void RegisterProvider(CryptoHashType type, HashAlgorithm hal)
|
||||
{
|
||||
Providers[(int)type] = new CryptoHashCodeProvider((int)type, hal);
|
||||
}
|
||||
|
||||
public static void RegisterProvider(int type, HashAlgorithm hal)
|
||||
{
|
||||
Providers[type] = new CryptoHashCodeProvider(type, hal);
|
||||
}
|
||||
|
||||
public static CryptoHashCodeProvider GetProvider(CryptoHashType type)
|
||||
{
|
||||
return Providers.GetValue((int)type);
|
||||
}
|
||||
|
||||
public static CryptoHashCodeProvider GetProvider(int type)
|
||||
{
|
||||
return Providers.GetValue(type);
|
||||
}
|
||||
|
||||
public static bool IsExtended(int type)
|
||||
{
|
||||
return HashTypes.Cast<int>().All(t => t != type);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.Crypto
|
||||
{
|
||||
[CoreService("Crypto", "3.0.0.1", TaskPriority.Highest)]
|
||||
public static partial class CryptoService
|
||||
{
|
||||
static CryptoService()
|
||||
{
|
||||
HashTypes = ((CryptoHashType)0).GetValues<CryptoHashType>();
|
||||
|
||||
Providers = HashTypes.Select(h => new CryptoHashCodeProvider((int)h, HashAlgorithm.Create(h.ToString())))
|
||||
.Where(p => p.Provider != null)
|
||||
.ToDictionary(p => p.ProviderID, p => p);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.Crypto
|
||||
{
|
||||
public interface ICryptoProvider : IDisposable
|
||||
{
|
||||
bool IsDisposed { get; }
|
||||
|
||||
int ProviderID { get; }
|
||||
HashAlgorithm Provider { get; }
|
||||
|
||||
string Seed { get; }
|
||||
byte[] Buffer { get; }
|
||||
|
||||
string Generate(string seed);
|
||||
}
|
||||
|
||||
public interface ICryptoMutator : ICryptoProvider
|
||||
{
|
||||
string Transform(string seed);
|
||||
string Mutate(string code);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.Crypto
|
||||
{
|
||||
public static class CryptoGenerator
|
||||
{
|
||||
public static string GenString(CryptoHashType type, string seed)
|
||||
{
|
||||
var p = CryptoService.GetProvider(type);
|
||||
|
||||
return p != null ? p.Generate(seed) : String.Empty;
|
||||
}
|
||||
|
||||
public static string GenString(int type, string seed)
|
||||
{
|
||||
var p = CryptoService.GetProvider(type);
|
||||
|
||||
return p != null ? p.Generate(seed) : String.Empty;
|
||||
}
|
||||
|
||||
public static CryptoHashCode GenHashCode(CryptoHashType type, string seed)
|
||||
{
|
||||
return new CryptoHashCode((int)type, seed);
|
||||
}
|
||||
|
||||
public static CryptoHashCode GenHashCode(int type, string seed)
|
||||
{
|
||||
return new CryptoHashCode(type, seed);
|
||||
}
|
||||
|
||||
public static CryptoHashCodeTable GenTable(string seed)
|
||||
{
|
||||
return new CryptoHashCodeTable(seed);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Server;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.Crypto
|
||||
{
|
||||
public class CryptoHashCode : IEquatable<CryptoHashCode>, IComparable<CryptoHashCode>, IEnumerable<char>, IDisposable
|
||||
{
|
||||
private int _ValueHash = -1;
|
||||
|
||||
public int ValueHash => GetValueHash();
|
||||
|
||||
public bool IsDisposed { get; private set; }
|
||||
|
||||
public bool IsExtended => CryptoService.IsExtended(ProviderID);
|
||||
|
||||
public int ProviderID { get; protected set; }
|
||||
|
||||
public virtual string Value { get; private set; }
|
||||
|
||||
public int Length => Value.Length;
|
||||
|
||||
public char this[int index] => Value[index];
|
||||
|
||||
public CryptoHashCode(CryptoHashType type, string seed)
|
||||
: this((int)type, seed)
|
||||
{ }
|
||||
|
||||
public CryptoHashCode(int providerID, string seed)
|
||||
{
|
||||
ProviderID = providerID;
|
||||
|
||||
Value = CryptoGenerator.GenString(ProviderID, seed ?? String.Empty);
|
||||
}
|
||||
|
||||
public CryptoHashCode(GenericReader reader)
|
||||
{
|
||||
Deserialize(reader);
|
||||
}
|
||||
|
||||
~CryptoHashCode()
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Value;
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
public IEnumerator<char> GetEnumerator()
|
||||
{
|
||||
return Value.GetEnumerator();
|
||||
}
|
||||
|
||||
public virtual int CompareTo(CryptoHashCode code)
|
||||
{
|
||||
return !ReferenceEquals(code, null) ? Insensitive.Compare(Value, code.Value) : -1;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is CryptoHashCode && Equals((CryptoHashCode)obj);
|
||||
}
|
||||
|
||||
public bool Equals(CryptoHashCode other)
|
||||
{
|
||||
return !ReferenceEquals(other, null) && ValueHash == other.ValueHash;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return unchecked(((ProviderID + 1) * 397) ^ ValueHash);
|
||||
}
|
||||
|
||||
public int GetValueHash()
|
||||
{
|
||||
if (_ValueHash > -1)
|
||||
{
|
||||
return _ValueHash;
|
||||
}
|
||||
|
||||
var hash = Value.Aggregate(Value.Length, (h, c) => unchecked((h * 397) ^ c));
|
||||
|
||||
// It may be negative, so ensure it is positive, normally this wouldn't be the case but negative integers for
|
||||
// almost unique id's should be positive for things like database keys.
|
||||
// Note this increases chance of unique collisions by 50%, though still extremely unlikely;
|
||||
// 1 : 2,147,483,647
|
||||
return _ValueHash = Math.Abs(hash);
|
||||
}
|
||||
|
||||
public virtual void Dispose()
|
||||
{
|
||||
if (IsDisposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
IsDisposed = true;
|
||||
|
||||
GC.SuppressFinalize(this);
|
||||
|
||||
Value = null;
|
||||
}
|
||||
|
||||
public virtual void Serialize(GenericWriter writer)
|
||||
{
|
||||
var version = writer.SetVersion(2);
|
||||
|
||||
writer.Write(ProviderID);
|
||||
|
||||
switch (version)
|
||||
{
|
||||
case 2:
|
||||
{
|
||||
writer.Write(Value);
|
||||
writer.Write(_ValueHash);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
case 0:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Deserialize(GenericReader reader)
|
||||
{
|
||||
var version = reader.GetVersion();
|
||||
|
||||
ProviderID = reader.ReadInt();
|
||||
|
||||
switch (version)
|
||||
{
|
||||
case 2:
|
||||
{
|
||||
Value = reader.ReadString();
|
||||
_ValueHash = reader.ReadInt();
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
{
|
||||
var seed = reader.ReadBool()
|
||||
? StringCompression.Unpack(reader.ReadBytes())
|
||||
: Encoding.UTF32.GetString(reader.ReadBytes());
|
||||
|
||||
Value = CryptoGenerator.GenString(ProviderID, seed ?? String.Empty);
|
||||
}
|
||||
break;
|
||||
case 0:
|
||||
{
|
||||
var seed = reader.ReadString();
|
||||
|
||||
Value = CryptoGenerator.GenString(ProviderID, seed ?? String.Empty);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool operator ==(CryptoHashCode l, CryptoHashCode r)
|
||||
{
|
||||
return ReferenceEquals(l, null) ? ReferenceEquals(r, null) : l.Equals(r);
|
||||
}
|
||||
|
||||
public static bool operator !=(CryptoHashCode l, CryptoHashCode r)
|
||||
{
|
||||
return ReferenceEquals(l, null) ? !ReferenceEquals(r, null) : !l.Equals(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.Crypto
|
||||
{
|
||||
public sealed class CryptoHashCodeProvider : ICryptoProvider
|
||||
{
|
||||
public bool IsDisposed { get; private set; }
|
||||
|
||||
public int ProviderID { get; private set; }
|
||||
public HashAlgorithm Provider { get; private set; }
|
||||
|
||||
public string Seed { get; private set; }
|
||||
public byte[] Buffer { get; private set; }
|
||||
|
||||
public CryptoHashCodeProvider(int id, HashAlgorithm hal)
|
||||
{
|
||||
ProviderID = id;
|
||||
Provider = hal;
|
||||
}
|
||||
|
||||
~CryptoHashCodeProvider()
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return ProviderID;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is CryptoHashCodeProvider && Equals((CryptoHashCodeProvider)obj);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("{0}:{1}", ProviderID, Provider != null ? Provider.GetType().FullName : "NULL");
|
||||
}
|
||||
|
||||
public string Generate(string seed)
|
||||
{
|
||||
seed = seed ?? String.Empty;
|
||||
|
||||
if (Buffer == null || Seed != seed)
|
||||
{
|
||||
Seed = seed;
|
||||
|
||||
Buffer = Encoding.UTF32.GetBytes(Seed);
|
||||
Buffer = Provider.ComputeHash(Buffer);
|
||||
}
|
||||
|
||||
return BitConverter.ToString(Buffer);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (IsDisposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
IsDisposed = true;
|
||||
|
||||
GC.SuppressFinalize(this);
|
||||
|
||||
if (Provider != null)
|
||||
{
|
||||
VitaNexCore.TryCatch(Provider.Clear);
|
||||
}
|
||||
|
||||
Provider = null;
|
||||
Seed = null;
|
||||
Buffer = null;
|
||||
}
|
||||
|
||||
public static bool operator ==(CryptoHashCodeProvider l, CryptoHashCodeProvider r)
|
||||
{
|
||||
return ReferenceEquals(l, null) ? ReferenceEquals(r, null) : l.Equals(r);
|
||||
}
|
||||
|
||||
public static bool operator !=(CryptoHashCodeProvider l, CryptoHashCodeProvider r)
|
||||
{
|
||||
return ReferenceEquals(l, null) ? !ReferenceEquals(r, null) : !l.Equals(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.Crypto
|
||||
{
|
||||
public class CryptoHashCodeTable : List<CryptoHashCode>, IEquatable<CryptoHashCodeTable>, IDisposable
|
||||
{
|
||||
public bool IsDisposed { get; private set; }
|
||||
|
||||
public CryptoHashCodeTable(string seed)
|
||||
{
|
||||
AddRange(CryptoService.Providers.Keys.Select(type => CryptoGenerator.GenHashCode(type, seed)));
|
||||
}
|
||||
|
||||
~CryptoHashCodeTable()
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
|
||||
public virtual void Dispose()
|
||||
{
|
||||
if (IsDisposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
IsDisposed = true;
|
||||
|
||||
GC.SuppressFinalize(this);
|
||||
|
||||
this.Free(true);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return this.GetContentsHashCode();
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is CryptoHashCodeTable && Equals((CryptoHashCodeTable)obj);
|
||||
}
|
||||
|
||||
public virtual bool Equals(CryptoHashCodeTable table)
|
||||
{
|
||||
return !ReferenceEquals(table, null) && (ReferenceEquals(table, this) || this.ContentsEqual(table));
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Join("+", this);
|
||||
}
|
||||
|
||||
public static bool operator ==(CryptoHashCodeTable l, CryptoHashCodeTable r)
|
||||
{
|
||||
return ReferenceEquals(l, null) ? ReferenceEquals(r, null) : l.Equals(r);
|
||||
}
|
||||
|
||||
public static bool operator !=(CryptoHashCodeTable l, CryptoHashCodeTable r)
|
||||
{
|
||||
return ReferenceEquals(l, null) ? !ReferenceEquals(r, null) : !l.Equals(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.Crypto
|
||||
{
|
||||
public enum CryptoHashType
|
||||
{
|
||||
MD5 = 0,
|
||||
SHA1 = 1,
|
||||
SHA256 = 2,
|
||||
SHA384 = 3,
|
||||
SHA512 = 4,
|
||||
RIPEMD160 = 5,
|
||||
Jenkins3 = 6
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user