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