Revision 34bdb91d trunk/Pithos.Network/Signature.cs

b/trunk/Pithos.Network/Signature.cs
5 5
using System.IO;
6 6
using System.Runtime.Remoting.Metadata.W3cXsd2001;
7 7
using System.Security.Cryptography;
8
using System.Text;
9 8
using System.Threading.Tasks;
10 9
using System.Linq;
11 10

  
......
210 209
                        newHashes[step] = finalHash;
211 210
                    }
212 211
                });
213
/*
214
            Parallel.For(0, leafs/2,
215
                () => HashAlgorithm.Create(algorithm),
216
                (step, state, hasher) =>
217
                {
218
                                 
219
                    var i = step*2;
220
                    var block1 = i <= hashCount - 1 ? hashMap[i]: empty;
221
                    var block2 = i <= hashCount - 2 ? hashMap[i + 1] : empty;
222

  
223
                    hasher.TransformBlock(block1, 0, block1.Length, null, 0);
224
                    hasher.TransformFinalBlock(block2, 0, block2.Length);
225
                    
226
                    var finalHash = hasher.Hash;
227
                    //Store the final value in its proper place
228
                    newHashes[step] = finalHash;
229
                                        
230
                    return hasher;
231
                },
232
                hasher => hasher.Dispose());
233
*/
212

  
234 213
            //Extract the hashes to a list ordered by their step 
235 214
            var hashes = newHashes.OrderBy(pair => pair.Key).Select(pair => pair.Value).ToList();
236 215
            return CalculateTopHash(hashes, algorithm);                   
237
        }
238

  
239
        
240

  
241
      /*  public static string CalculateTopHash(string hashString, string algorithm)
242
        {
243
            if (String.IsNullOrWhiteSpace(algorithm))
244
                throw new ArgumentNullException("algorithm");
245
            Contract.EndContractBlock();
246
            if (String.IsNullOrWhiteSpace(hashString))
247
                return String.Empty;
248

  
249
            using (var hasher = HashAlgorithm.Create(algorithm))
250
            {
251
                var bytes=Encoding.ASCII.GetBytes(hashString.ToLower());
252
                var hash=hasher.ComputeHash(bytes);
253
                return hash.ToHashString();
254
            }
255
        }*/
256

  
257

  
216
        }        
258 217
    
259 218

  
260 219
        public static byte[] CalculateHash(byte[] buffer,string algorithm)

Also available in: Unified diff