public static OmniAgreement Create(OmniAgreementAlgorithmType algorithmType) { var creationTime = DateTime.UtcNow; if (algorithmType == OmniAgreementAlgorithmType.EcDh_P521_Sha2_256) { var(publicKey, privateKey) = EcDh_P521_Sha2_256.CreateKeys(); return(new OmniAgreement(Timestamp.FromDateTime(creationTime), algorithmType, publicKey, privateKey)); } throw new NotSupportedException(nameof(algorithmType)); }
public OmniAgreement Deserialize(Omnix.Serialization.RocketPack.RocketPackReader r, int rank) { if (rank > 256) { throw new System.FormatException(); } // Read property count uint propertyCount = r.GetUInt32(); Omnix.Serialization.RocketPack.Timestamp p_creationTime = Omnix.Serialization.RocketPack.Timestamp.Zero; OmniAgreementAlgorithmType p_algorithmType = (OmniAgreementAlgorithmType)0; System.ReadOnlyMemory <byte> p_publicKey = System.ReadOnlyMemory <byte> .Empty; System.ReadOnlyMemory <byte> p_privateKey = System.ReadOnlyMemory <byte> .Empty; for (; propertyCount > 0; propertyCount--) { uint id = r.GetUInt32(); switch (id) { case 0: // CreationTime { p_creationTime = r.GetTimestamp(); break; } case 1: // AlgorithmType { p_algorithmType = (OmniAgreementAlgorithmType)r.GetUInt64(); break; } case 2: // PublicKey { p_publicKey = r.GetMemory(8192); break; } case 3: // PrivateKey { p_privateKey = r.GetMemory(8192); break; } } } return(new OmniAgreement(p_creationTime, p_algorithmType, p_publicKey, p_privateKey)); }
public OmniAgreement(Omnix.Serialization.RocketPack.Timestamp creationTime, OmniAgreementAlgorithmType algorithmType, System.ReadOnlyMemory <byte> publicKey, System.ReadOnlyMemory <byte> privateKey) { if (publicKey.Length > 8192) { throw new System.ArgumentOutOfRangeException("publicKey"); } if (privateKey.Length > 8192) { throw new System.ArgumentOutOfRangeException("privateKey"); } this.CreationTime = creationTime; this.AlgorithmType = algorithmType; this.PublicKey = publicKey; this.PrivateKey = privateKey; { var __h = new System.HashCode(); if (this.CreationTime != default) { __h.Add(this.CreationTime.GetHashCode()); } if (this.AlgorithmType != default) { __h.Add(this.AlgorithmType.GetHashCode()); } if (!this.PublicKey.IsEmpty) { __h.Add(Omnix.Base.Helpers.ObjectHelper.GetHashCode(this.PublicKey.Span)); } if (!this.PrivateKey.IsEmpty) { __h.Add(Omnix.Base.Helpers.ObjectHelper.GetHashCode(this.PrivateKey.Span)); } __hashCode = __h.ToHashCode(); } }