blob: a5fd057e15250558e8db4219349bd28c43e7c2e8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
using ACMESharp.Authorizations;
using PKISharp.WACS.Plugins.Interfaces;
using System;
using System.Threading.Tasks;
namespace PKISharp.WACS.Plugins.ValidationPlugins
{
/// <summary>
/// Base implementation for all validation plugins
/// </summary>
public abstract class Validation<TChallenge> : IValidationPlugin where TChallenge : IChallengeValidationDetails
{
protected TChallenge _challenge;
/// <summary>
/// Handle the challenge
/// </summary>
/// <param name="challenge"></param>
public async Task PrepareChallenge(IChallengeValidationDetails challenge)
{
if (challenge.GetType() != typeof(TChallenge))
{
throw new InvalidOperationException("Unexpected challenge type");
}
else
{
_challenge = (TChallenge)challenge;
await PrepareChallenge();
}
}
/// <summary>
/// Handle the challenge
/// </summary>
/// <param name="challenge"></param>
public abstract Task PrepareChallenge();
/// <summary>
/// Clean up after validation
/// </summary>
public abstract Task CleanUp();
public virtual bool Disabled => false;
#region IDisposable
private bool disposedValue = false; // To detect redundant calls
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
CleanUp();
}
disposedValue = true;
}
}
public void Dispose() => Dispose(true);
#endregion
}
}
|