-
Notifications
You must be signed in to change notification settings - Fork 274
/
Copy pathSslStreamTests.Protocols.cs
66 lines (57 loc) · 2.53 KB
/
SslStreamTests.Protocols.cs
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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using System.Security.Authentication;
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Extensions;
using MicroBenchmarks;
namespace System.Net.Security.Tests
{
public partial class SslStreamTests
{
private static Lazy<bool> s_supportsTls13 = new Lazy<bool>(GetTls13Support);
public static bool SupportsTls13 => s_supportsTls13.Value;
public static IEnumerable<object[]> TlsProtocols()
{
yield return new object[] { SslProtocols.Tls12 };
if (SupportsTls13)
{
yield return new object[] { SslProtocols.Tls13 };
}
}
[Benchmark]
[BenchmarkCategory(Categories.NoAOT)]
[ArgumentsSource(nameof(TlsProtocols))]
public Task HandshakeContosoAsync(SslProtocols protocol) => SslStreamTests.HandshakeAsync(SslStreamTests._cert, protocol);
[Benchmark]
[ArgumentsSource(nameof(TlsProtocols))]
[BenchmarkCategory(Categories.NoAOT)]
public Task HandshakeECDSA256CertAsync(SslProtocols protocol) => SslStreamTests.HandshakeAsync(SslStreamTests._ec256Cert, protocol);
[Benchmark]
[ArgumentsSource(nameof(TlsProtocols))]
[BenchmarkCategory(Categories.NoAOT)]
[OperatingSystemsFilter(allowed: true, platforms: OS.Linux)] // Not supported on Windows at the moment.
public Task HandshakeECDSA512CertAsync(SslProtocols protocol) => SslStreamTests.HandshakeAsync(SslStreamTests._ec512Cert, protocol);
[Benchmark]
[ArgumentsSource(nameof(TlsProtocols))]
[BenchmarkCategory(Categories.NoAOT)]
public Task HandshakeRSA2048CertAsync(SslProtocols protocol) => SslStreamTests.HandshakeAsync(SslStreamTests._rsa2048Cert, protocol);
[Benchmark]
[ArgumentsSource(nameof(TlsProtocols))]
public Task HandshakeRSA4096CertAsync(SslProtocols protocol) => SslStreamTests.HandshakeAsync(SslStreamTests._rsa4096Cert, protocol);
private static bool GetTls13Support()
{
try
{
SslStreamTests.HandshakeAsync(SslStreamTests._rsa2048Cert, SslProtocols.Tls13).GetAwaiter().GetResult();
return true;
}
catch
{
return false;
}
}
}
}