btcpayserver/BTCPayServer/Validation/PubKeyValidator.cs

27 lines
675 B
C#
Raw Normal View History

2020-06-28 21:44:35 -05:00
using System;
2017-09-13 15:47:34 +09:00
using System.ComponentModel.DataAnnotations;
2020-06-28 17:55:27 +09:00
using NBitcoin;
2017-09-13 15:47:34 +09:00
2018-11-06 15:38:07 +09:00
namespace BTCPayServer.Validation
2017-09-13 15:47:34 +09:00
{
public class PubKeyValidatorAttribute : ValidationAttribute
{
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
if (value == null)
{
return ValidationResult.Success;
}
try
{
new PubKey((string)value);
return ValidationResult.Success;
}
catch (Exception ex)
{
return new ValidationResult(ex.Message);
}
}
}
2017-09-13 15:47:34 +09:00
}