2019-05-12 17:13:55 +02:00
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
using NBitcoin;
|
|
|
|
using NBitcoin.DataEncoders;
|
|
|
|
|
|
|
|
namespace BTCPayServer.Validation
|
|
|
|
{
|
|
|
|
public class HDFingerPrintValidator : ValidationAttribute
|
|
|
|
{
|
|
|
|
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
|
|
|
|
{
|
|
|
|
var str = value as string;
|
|
|
|
if (string.IsNullOrWhiteSpace(str))
|
|
|
|
{
|
|
|
|
return ValidationResult.Success;
|
|
|
|
}
|
2020-06-28 10:55:27 +02:00
|
|
|
|
2019-05-12 17:13:55 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
new HDFingerprint(Encoders.Hex.DecodeData(str));
|
|
|
|
return ValidationResult.Success;
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
return new ValidationResult("Invalid fingerprint");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|