public OmniHashcash Deserialize(Omnix.Serialization.RocketPack.RocketPackReader r, int rank) { if (rank > 256) { throw new System.FormatException(); } // Read property count uint propertyCount = r.GetUInt32(); OmniHashcashAlgorithmType p_algorithmType = (OmniHashcashAlgorithmType)0; System.ReadOnlyMemory <byte> p_key = System.ReadOnlyMemory <byte> .Empty; for (; propertyCount > 0; propertyCount--) { uint id = r.GetUInt32(); switch (id) { case 0: // AlgorithmType { p_algorithmType = (OmniHashcashAlgorithmType)r.GetUInt64(); break; } case 1: // Key { p_key = r.GetMemory(32); break; } } } return(new OmniHashcash(p_algorithmType, p_key)); }
public OmniHashcash(OmniHashcashAlgorithmType algorithmType, System.ReadOnlyMemory <byte> key) { if (key.Length > 32) { throw new System.ArgumentOutOfRangeException("key"); } this.AlgorithmType = algorithmType; this.Key = key; { var __h = new System.HashCode(); if (this.AlgorithmType != default) { __h.Add(this.AlgorithmType.GetHashCode()); } if (!this.Key.IsEmpty) { __h.Add(Omnix.Base.Helpers.ObjectHelper.GetHashCode(this.Key.Span)); } __hashCode = __h.ToHashCode(); } }
public static async ValueTask <OmniHashcash> Create(ReadOnlySequence <byte> sequence, ReadOnlyMemory <byte> key, OmniHashcashAlgorithmType hashcashAlgorithmType, int limit, TimeSpan timeout, CancellationToken cancellationToken) { if (!EnumHelper.IsValid(hashcashAlgorithmType)) { throw new ArgumentException(nameof(OmniHashcashAlgorithmType)); } await Task.Delay(1, cancellationToken).ConfigureAwait(false); if (hashcashAlgorithmType == OmniHashcashAlgorithmType.Sha2_256) { var target = Hmac_Sha2_256.ComputeHash(sequence, key.Span); var hashcashKey = MinerHelper.Compute_Simple_Sha2_256(target, limit, timeout, cancellationToken); return(new OmniHashcash(OmniHashcashAlgorithmType.Sha2_256, hashcashKey)); } throw new NotSupportedException(nameof(hashcashAlgorithmType)); }