2014-04-28 06:34:29 +00:00
|
|
|
|
using System;
|
|
|
|
|
using NzbDrone.Common.Disk;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Update
|
|
|
|
|
{
|
|
|
|
|
public interface IVerifyUpdates
|
|
|
|
|
{
|
2015-10-03 17:45:26 +00:00
|
|
|
|
bool Verify(UpdatePackage updatePackage, string packagePath);
|
2014-04-28 06:34:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class UpdateVerification : IVerifyUpdates
|
|
|
|
|
{
|
|
|
|
|
private readonly IDiskProvider _diskProvider;
|
|
|
|
|
|
|
|
|
|
public UpdateVerification(IDiskProvider diskProvider)
|
|
|
|
|
{
|
|
|
|
|
_diskProvider = diskProvider;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-03 17:45:26 +00:00
|
|
|
|
public bool Verify(UpdatePackage updatePackage, string packagePath)
|
2014-04-28 06:34:29 +00:00
|
|
|
|
{
|
2015-01-22 22:12:35 +00:00
|
|
|
|
using (var fileStream = _diskProvider.OpenReadStream(packagePath))
|
2014-04-28 06:34:29 +00:00
|
|
|
|
{
|
|
|
|
|
var hash = fileStream.SHA256Hash();
|
|
|
|
|
|
|
|
|
|
return hash.Equals(updatePackage.Hash, StringComparison.CurrentCultureIgnoreCase);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|