Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
 public int GetHashCode(byte[] key)
 {
     return(ByteArrayPrimitives.GetHashCode(key));
 }
Exemplo n.º 3
0
 public bool Equals(byte[] left, byte[] right)
 {
     return(ByteArrayPrimitives.Equals(left, right));
 }
Exemplo n.º 4
0
 public int GetHashCode(byte[] key)
 {
     return(ByteArrayPrimitives.ReadFirstWord(key));
 }