Use List wrapper instead of Enumerator
[NovacoinLibrary.git] / Novacoin / Hash256.cs
1 \feffusing System;
2 using System.Text;
3 using System.Linq;
4 using System.Collections.Generic;
5
6
7 namespace Novacoin
8 {
9         /// <summary>
10         /// Representation of SHA-256 hash
11         /// </summary>
12     public class Hash256
13     {
14         // 32 bytes
15         const int hashSize = 32;
16
17         /// <summary>
18         /// Array of digest bytes.
19         /// </summary>
20         private byte[] hashBytes = new byte[hashSize];
21
22         /// <summary>
23         /// Initializes an empty instance of the Hash256 class.
24         /// </summary>
25         public Hash256()
26         {
27             hashBytes = Enumerable.Repeat<byte>(0, hashSize).ToArray();
28         }
29
30         /// <summary>
31         /// Initializes a new instance of Hash256 class with first 32 bytes from supplied list
32         /// </summary>
33         /// <param name="bytesList">List of bytes</param>
34         public Hash256(List<byte> bytesList)
35         {
36             hashBytes = bytesList.Take<byte>(hashSize).ToArray<byte>();
37         }
38
39         public Hash256(byte[] bytesArray)
40         {
41             hashBytes = bytesArray;
42         }
43
44         public override string ToString()
45         {
46             StringBuilder sb = new StringBuilder(hashSize * 2);
47             foreach (byte b in hashBytes)
48             {
49                 sb.AppendFormat("{0:x2}", b);
50             }
51             return sb.ToString();
52         }
53
54     }
55 }
56