Skip to content

Commit fe1c74f

Browse files
authored
fix: Removed sync ICertificateStuff (#30)
1 parent 5fc37bf commit fe1c74f

File tree

3 files changed

+74
-94
lines changed

3 files changed

+74
-94
lines changed

src/Titanium.Web.Proxy/Certificates/Cache/DefaultCertificateDiskCache.cs

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,6 @@ public void Clear ()
4747
}
4848
}
4949

50-
/// <summary>
51-
/// Loads a certificate from the specified subject name.
52-
/// </summary>
53-
/// <param name="subjectName">The subject name of the certificate to load.</param>
54-
/// <param name="storageFlags">The storage flags for the certificate.</param>
55-
/// <returns>The loaded certificate, or null if not found.</returns>
56-
[Obsolete("Use LoadCertificateAsync instead")]
57-
public X509Certificate2? LoadCertificate ( string subjectName, X509KeyStorageFlags storageFlags )
58-
{
59-
logger?.LogTrace("LoadCertificate called");
60-
61-
return LoadCertificateAsync(subjectName, storageFlags, CancellationToken.None).GetAwaiter().GetResult();
62-
}
63-
6450
/// <inheritdoc/>
6551
public async Task<X509Certificate2?> LoadCertificateAsync ( string subjectName, X509KeyStorageFlags storageFlags, CancellationToken cancellationToken )
6652
{
@@ -70,20 +56,6 @@ public void Clear ()
7056
return await LoadCertificateAsync(filePath, string.Empty, storageFlags, cancellationToken);
7157
}
7258

73-
/// <summary>
74-
/// Loads the root certificate from the specified path or name.
75-
/// </summary>
76-
/// <param name="pathOrName">The path or name of the root certificate.</param>
77-
/// <param name="password">The password for the root certificate.</param>
78-
/// <param name="storageFlags">The storage flags for the root certificate.</param>
79-
/// <returns>The loaded root certificate, or null if not found.</returns>
80-
[Obsolete("Use LoadRootCertificateAsync instead")]
81-
public X509Certificate2? LoadRootCertificate ( string pathOrName, string? password, X509KeyStorageFlags storageFlags )
82-
{
83-
logger?.LogTrace("LoadRootCertificate called");
84-
return LoadRootCertificateAsync(pathOrName, password, storageFlags, CancellationToken.None).GetAwaiter().GetResult();
85-
}
86-
8759
/// <inheritdoc/>
8860
public async Task<X509Certificate2?> LoadRootCertificateAsync ( string pathOrName, string? password, X509KeyStorageFlags storageFlags, CancellationToken cancellationToken )
8961
{
@@ -92,19 +64,6 @@ public void Clear ()
9264
return await LoadCertificateAsync(path, password, storageFlags, cancellationToken);
9365
}
9466

95-
/// <summary>
96-
/// Saves a certificate with the specified subject name.
97-
/// </summary>
98-
/// <param name="subjectName">The subject name of the certificate to save.</param>
99-
/// <param name="certificate">The certificate to save.</param>
100-
[Obsolete("Use SaveCertificateAsync instead")]
101-
public void SaveCertificate ( string subjectName, X509Certificate2 certificate )
102-
{
103-
logger?.LogTrace("SaveCertificate called");
104-
105-
SaveCertificateAsync(subjectName, certificate, CancellationToken.None).GetAwaiter().GetResult();
106-
}
107-
10867
/// <inheritdoc/>
10968
public async Task SaveCertificateAsync ( string subjectName, X509Certificate2 certificate, CancellationToken cancellationToken )
11069
{
@@ -116,19 +75,6 @@ public async Task SaveCertificateAsync ( string subjectName, X509Certificate2 ce
11675
Log_SaveCertificateAsyncFinished();
11776
}
11877

119-
/// <summary>
120-
/// Saves the root certificate to the specified path or name.
121-
/// </summary>
122-
/// <param name="pathOrName">The path or name where the root certificate will be saved.</param>
123-
/// <param name="password">The password for the root certificate.</param>
124-
/// <param name="certificate">The root certificate to save.</param>
125-
public void SaveRootCertificate ( string pathOrName, string password, X509Certificate2 certificate )
126-
{
127-
logger?.LogTrace("SaveRootCertificate called");
128-
129-
SaveRootCertificateAsync(pathOrName, password, certificate, CancellationToken.None).GetAwaiter().GetResult();
130-
}
131-
13278
/// <inheritdoc/>
13379
public async Task SaveRootCertificateAsync ( string pathOrName, string password, X509Certificate2 certificate, CancellationToken cancellationToken )
13480
{

src/Titanium.Web.Proxy/Certificates/Cache/ICertificateCache.cs

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,6 @@ namespace Titanium.Web.Proxy.Certificates.Cache;
1111
/// </summary>
1212
public interface ICertificateCache
1313
{
14-
/// <summary>
15-
/// Loads the root certificate from the storage.
16-
/// </summary>
17-
/// <param name="pathOrName">The path or name of the root certificate.</param>
18-
/// <param name="password">The password for the root certificate.</param>
19-
/// <param name="storageFlags">The storage flags for the root certificate.</param>
20-
/// <returns>The loaded root certificate, or null if not found.</returns>
21-
[Obsolete("Use LoadRootCertificateAsync instead")]
22-
[EditorBrowsable(EditorBrowsableState.Never)]
23-
X509Certificate2? LoadRootCertificate ( string pathOrName, string password, X509KeyStorageFlags storageFlags );
24-
2514
/// <summary>
2615
/// Loads the root certificate from the storage.
2716
/// </summary>
@@ -32,16 +21,6 @@ public interface ICertificateCache
3221
/// <returns>The loaded root certificate, or null if not found.</returns>
3322
Task<X509Certificate2?> LoadRootCertificateAsync ( string pathOrName, string password, X509KeyStorageFlags storageFlags, CancellationToken cancellationToken );
3423

35-
/// <summary>
36-
/// Saves the root certificate to the storage.
37-
/// </summary>
38-
/// <param name="pathOrName">The path or name where the root certificate will be saved.</param>
39-
/// <param name="password">The password for the root certificate.</param>
40-
/// <param name="certificate">The root certificate to save.</param>
41-
[Obsolete("Use SaveRootCertificateAsync instead")]
42-
[EditorBrowsable(EditorBrowsableState.Never)]
43-
void SaveRootCertificate ( string pathOrName, string password, X509Certificate2 certificate );
44-
4524
/// <summary>
4625
/// Saves the root certificate to the storage.
4726
/// </summary>
@@ -51,16 +30,6 @@ public interface ICertificateCache
5130
/// <param name="cancellationToken"></param>
5231
Task SaveRootCertificateAsync ( string pathOrName, string password, X509Certificate2 certificate, CancellationToken cancellationToken );
5332

54-
/// <summary>
55-
/// Loads a certificate from the storage.
56-
/// </summary>
57-
/// <param name="subjectName">The subject name of the certificate to load.</param>
58-
/// <param name="storageFlags">The storage flags for the certificate.</param>
59-
/// <returns>The loaded certificate, or null if not found.</returns>
60-
[Obsolete("Use LoadCertificateAsync instead")]
61-
[EditorBrowsable(EditorBrowsableState.Never)]
62-
X509Certificate2? LoadCertificate ( string subjectName, X509KeyStorageFlags storageFlags );
63-
6433
/// <summary>
6534
/// Loads a certificate from the storage.
6635
/// </summary>
@@ -70,15 +39,6 @@ public interface ICertificateCache
7039
/// <returns>The loaded certificate, or null if not found.</returns>
7140
Task<X509Certificate2?> LoadCertificateAsync ( string subjectName, X509KeyStorageFlags storageFlags, CancellationToken cancellationToken );
7241

73-
/// <summary>
74-
/// Saves a certificate to the storage.
75-
/// </summary>
76-
/// <param name="subjectName">The subject name of the certificate to save.</param>
77-
/// <param name="certificate">The certificate to save.</param>
78-
[Obsolete("Use SaveCertificateAsync instead")]
79-
[EditorBrowsable(EditorBrowsableState.Never)]
80-
void SaveCertificate ( string subjectName, X509Certificate2 certificate );
81-
8242
/// <summary>
8343
/// Saves a certificate to the storage.
8444
/// </summary>
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Linq;
5+
using System.Security.Cryptography.X509Certificates;
6+
using System.Text;
7+
using System.Threading;
8+
using System.Threading.Tasks;
9+
10+
namespace Titanium.Web.Proxy.Certificates.Cache;
11+
12+
/// <summary>
13+
/// Compatibility extension methods for the <see cref="ICertificateCache"/> interface.
14+
/// </summary>
15+
[Obsolete("Use the async methods directly instead.")]
16+
[EditorBrowsable(EditorBrowsableState.Never)]
17+
public static class ICertificateCacheExtensions
18+
{
19+
/// <summary>
20+
/// Loads a certificate from the storage.
21+
/// </summary>
22+
/// <param name="cache"></param>
23+
/// <param name="subjectName">The subject name of the certificate to load.</param>
24+
/// <param name="storageFlags">The storage flags for the certificate.</param>
25+
/// <returns>The loaded certificate, or null if not found.</returns>
26+
[Obsolete("Use LoadCertificateAsync instead")]
27+
[EditorBrowsable(EditorBrowsableState.Never)]
28+
public static X509Certificate2? LoadCertificate ( this ICertificateCache cache, string subjectName, X509KeyStorageFlags storageFlags )
29+
{
30+
return cache.LoadCertificateAsync(subjectName, storageFlags, CancellationToken.None).GetAwaiter().GetResult();
31+
}
32+
33+
/// <summary>
34+
/// Loads the root certificate from the storage.
35+
/// </summary>
36+
/// <param name="cache"></param>
37+
/// <param name="pathOrName">The path or name of the root certificate.</param>
38+
/// <param name="password">The password for the root certificate.</param>
39+
/// <param name="storageFlags">The storage flags for the root certificate.</param>
40+
/// <returns>The loaded root certificate, or null if not found.</returns>
41+
[Obsolete("Use LoadRootCertificateAsync instead")]
42+
[EditorBrowsable(EditorBrowsableState.Never)]
43+
public static X509Certificate2? LoadRootCertificate ( this ICertificateCache cache, string pathOrName, string password, X509KeyStorageFlags storageFlags )
44+
{
45+
return cache.LoadRootCertificateAsync(pathOrName, password, storageFlags, CancellationToken.None).GetAwaiter().GetResult();
46+
}
47+
48+
/// <summary>
49+
/// Saves a certificate to the storage.
50+
/// </summary>
51+
/// <param name="cache"></param>
52+
/// <param name="subjectName">The subject name of the certificate to save.</param>
53+
/// <param name="certificate">The certificate to save.</param>
54+
[Obsolete("Use SaveCertificateAsync instead")]
55+
[EditorBrowsable(EditorBrowsableState.Never)]
56+
public static void SaveCertificate ( this ICertificateCache cache, string subjectName, X509Certificate2 certificate )
57+
{
58+
cache.SaveCertificateAsync(subjectName, certificate, CancellationToken.None).GetAwaiter().GetResult();
59+
}
60+
61+
/// <summary>
62+
/// Saves the root certificate to the storage.
63+
/// </summary>
64+
/// <param name="cache"></param>
65+
/// <param name="pathOrName">The path or name where the root certificate will be saved.</param>
66+
/// <param name="password">The password for the root certificate.</param>
67+
/// <param name="certificate">The root certificate to save.</param>
68+
[Obsolete("Use SaveRootCertificateAsync instead")]
69+
[EditorBrowsable(EditorBrowsableState.Never)]
70+
public static void SaveRootCertificate ( this ICertificateCache cache, string pathOrName, string password, X509Certificate2 certificate )
71+
{
72+
cache.SaveRootCertificateAsync(pathOrName, password, certificate, CancellationToken.None).GetAwaiter().GetResult();
73+
}
74+
}

0 commit comments

Comments
 (0)