btcpayserver/BTCPayServer/Validation/PubKeyValidator.cs
2020-06-28 17:55:27 +09:00

29 lines
731 B
C#

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;
using NBitcoin;
namespace BTCPayServer.Validation
{
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);
}
}
}
}