/// <summary> /// Verifies that both aggregated envelops contain the same message and merges signatures to the source envelope. /// </summary> /// <param name="envelope">Source envelope</param> /// <param name="anotherEnvelope">Envelope to aggregate</param> public static void AggregateEnvelop(this MessageEnvelope envelope, MessageEnvelope anotherEnvelope) { if (envelope == null) { throw new ArgumentNullException(nameof(envelope)); } if (anotherEnvelope == null) { throw new ArgumentNullException(nameof(anotherEnvelope)); } //TODO: cache hashes to improve performance var hash = envelope.ComputeMessageHash(); var anotherHash = anotherEnvelope.ComputeMessageHash(); if (!ByteArrayPrimitives.Equals(anotherHash, hash)) { #if DEBUG var envelopeJson = Newtonsoft.Json.JsonConvert.SerializeObject(envelope); Debug.Print("envelope:\n" + envelopeJson); envelopeJson = Newtonsoft.Json.JsonConvert.SerializeObject(anotherEnvelope); Debug.Print("anotherEnvelope:\n" + envelopeJson); #endif throw new InvalidOperationException($"Invalid message envelope hash. {hash} != {anotherHash}"); } envelope.AggregateEnvelopUnsafe(anotherEnvelope); }
public int GetHashCode(byte[] key) { return(ByteArrayPrimitives.GetHashCode(key)); }
public bool Equals(byte[] left, byte[] right) { return(ByteArrayPrimitives.Equals(left, right)); }
public int GetHashCode(byte[] key) { return(ByteArrayPrimitives.ReadFirstWord(key)); }