1 //
2 // Copyright (c) 2010-2018 Antmicro
3 // Copyright (c) 2011-2015 Realtime Embedded
4 //
5 // This file is licensed under the MIT License.
6 // Full license text is available in 'licenses/MIT.txt'.
7 //
8 using System;
9 using System.Security.Cryptography;
10 using System.IO;
11 using System.Linq;
12 
13 namespace Antmicro.Renode.Core
14 {
15     public sealed class BinaryFingerprint
16     {
BinaryFingerprint(string file)17         public BinaryFingerprint(string file)
18         {
19             using(var md5 = MD5.Create())
20             using(var stream = File.OpenRead(file))
21             {
22                 md5.ComputeHash(stream);
23                 hash = md5.Hash;
24             }
25             FileName = Path.GetFullPath(file);
26         }
27 
28         public string FileName { get; private set; }
29 
30         public string Hash
31         {
32             get
33             {
34                 return hash.Select(x => x.ToString("x2")).Aggregate((x, y) => x + y);
35             }
36         }
37 
ToString()38         public override string ToString()
39         {
40             return string.Format("Binary {0}: {1}", FileName, Hash);
41         }
42 
43         private readonly byte[] hash;
44     }
45 }
46 
47