Skip to content

Commit cc44d43

Browse files
Convert System.Net.* over to GeneratedDllImport (#61765)
1 parent bd63cfc commit cc44d43

33 files changed

+183
-152
lines changed

src/libraries/Common/src/Interop/Android/System.Security.Cryptography.Native.Android/Interop.Ssl.ProtocolSupport.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ internal static partial class Interop
88
{
99
internal static partial class AndroidCrypto
1010
{
11-
[DllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLGetSupportedProtocols")]
12-
internal static extern SslProtocols SSLGetSupportedProtocols();
11+
[GeneratedDllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLGetSupportedProtocols")]
12+
internal static partial SslProtocols SSLGetSupportedProtocols();
1313

14-
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLSupportsApplicationProtocolsConfiguration")]
14+
[GeneratedDllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLSupportsApplicationProtocolsConfiguration")]
1515
[return:MarshalAs(UnmanagedType.U1)]
16-
internal static extern bool SSLSupportsApplicationProtocolsConfiguration();
16+
internal static partial bool SSLSupportsApplicationProtocolsConfiguration();
1717
}
1818
}

src/libraries/Common/src/Interop/Android/System.Security.Cryptography.Native.Android/Interop.Ssl.cs

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ internal enum PAL_SSLStreamStatus
3131
Closed = 4,
3232
};
3333

34-
[DllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamCreate")]
35-
internal static extern SafeSslHandle SSLStreamCreate();
34+
[GeneratedDllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamCreate")]
35+
internal static partial SafeSslHandle SSLStreamCreate();
3636

37-
[DllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamCreateWithCertificates")]
38-
private static extern SafeSslHandle SSLStreamCreateWithCertificates(
37+
[GeneratedDllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamCreateWithCertificates")]
38+
private static partial SafeSslHandle SSLStreamCreateWithCertificates(
3939
ref byte pkcs8PrivateKey,
4040
int pkcs8PrivateKeyLen,
4141
PAL_KeyAlgorithm algorithm,
@@ -51,8 +51,8 @@ ref MemoryMarshal.GetReference(pkcs8PrivateKey),
5151
certificates.Length);
5252
}
5353

54-
[DllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamInitialize")]
55-
private static extern int SSLStreamInitializeImpl(
54+
[GeneratedDllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamInitialize")]
55+
private static partial int SSLStreamInitializeImpl(
5656
SafeSslHandle sslHandle,
5757
[MarshalAs(UnmanagedType.U1)] bool isServer,
5858
SSLReadCallback streamRead,
@@ -70,8 +70,8 @@ internal static void SSLStreamInitialize(
7070
throw new SslException();
7171
}
7272

73-
[DllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamSetTargetHost")]
74-
private static extern int SSLStreamSetTargetHostImpl(
73+
[GeneratedDllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamSetTargetHost")]
74+
private static partial int SSLStreamSetTargetHostImpl(
7575
SafeSslHandle sslHandle,
7676
[MarshalAs(UnmanagedType.LPUTF8Str)] string targetHost);
7777
internal static void SSLStreamSetTargetHost(
@@ -85,8 +85,8 @@ internal static void SSLStreamSetTargetHost(
8585
throw new SslException();
8686
}
8787

88-
[DllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamRequestClientAuthentication")]
89-
internal static extern void SSLStreamRequestClientAuthentication(SafeSslHandle sslHandle);
88+
[GeneratedDllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamRequestClientAuthentication")]
89+
internal static partial void SSLStreamRequestClientAuthentication(SafeSslHandle sslHandle);
9090

9191
[StructLayout(LayoutKind.Sequential)]
9292
private unsafe struct ApplicationProtocolData
@@ -95,8 +95,8 @@ private unsafe struct ApplicationProtocolData
9595
public int Length;
9696
}
9797

98-
[DllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamSetApplicationProtocols")]
99-
private static unsafe extern int SSLStreamSetApplicationProtocols(SafeSslHandle sslHandle, ApplicationProtocolData[] protocolData, int count);
98+
[GeneratedDllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamSetApplicationProtocols")]
99+
private static unsafe partial int SSLStreamSetApplicationProtocols(SafeSslHandle sslHandle, ApplicationProtocolData[] protocolData, int count);
100100
internal static unsafe void SSLStreamSetApplicationProtocols(SafeSslHandle sslHandle, List<SslApplicationProtocol> protocols)
101101
{
102102
int count = protocols.Count;
@@ -129,20 +129,20 @@ internal static unsafe void SSLStreamSetApplicationProtocols(SafeSslHandle sslHa
129129
}
130130
}
131131

132-
[DllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamSetEnabledProtocols")]
133-
private static extern int SSLStreamSetEnabledProtocols(SafeSslHandle sslHandle, ref SslProtocols protocols, int length);
132+
[GeneratedDllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamSetEnabledProtocols")]
133+
private static partial int SSLStreamSetEnabledProtocols(SafeSslHandle sslHandle, ref SslProtocols protocols, int length);
134134
internal static void SSLStreamSetEnabledProtocols(SafeSslHandle sslHandle, ReadOnlySpan<SslProtocols> protocols)
135135
{
136136
int ret = SSLStreamSetEnabledProtocols(sslHandle, ref MemoryMarshal.GetReference(protocols), protocols.Length);
137137
if (ret != SUCCESS)
138138
throw new SslException();
139139
}
140140

141-
[DllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamHandshake")]
142-
internal static extern PAL_SSLStreamStatus SSLStreamHandshake(SafeSslHandle sslHandle);
141+
[GeneratedDllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamHandshake")]
142+
internal static partial PAL_SSLStreamStatus SSLStreamHandshake(SafeSslHandle sslHandle);
143143

144-
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamGetApplicationProtocol")]
145-
private static extern int SSLStreamGetApplicationProtocol(SafeSslHandle ssl, [Out] byte[]? buf, ref int len);
144+
[GeneratedDllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamGetApplicationProtocol")]
145+
private static partial int SSLStreamGetApplicationProtocol(SafeSslHandle ssl, byte[]? buf, ref int len);
146146
internal static byte[]? SSLStreamGetApplicationProtocol(SafeSslHandle ssl)
147147
{
148148
int len = 0;
@@ -158,8 +158,8 @@ internal static void SSLStreamSetEnabledProtocols(SafeSslHandle sslHandle, ReadO
158158
return bytes;
159159
}
160160

161-
[DllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamRead")]
162-
private static unsafe extern PAL_SSLStreamStatus SSLStreamRead(
161+
[GeneratedDllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamRead")]
162+
private static unsafe partial PAL_SSLStreamStatus SSLStreamRead(
163163
SafeSslHandle sslHandle,
164164
byte* buffer,
165165
int length,
@@ -175,8 +175,8 @@ internal static unsafe PAL_SSLStreamStatus SSLStreamRead(
175175
}
176176
}
177177

178-
[DllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamWrite")]
179-
private static unsafe extern PAL_SSLStreamStatus SSLStreamWrite(
178+
[GeneratedDllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamWrite")]
179+
private static unsafe partial PAL_SSLStreamStatus SSLStreamWrite(
180180
SafeSslHandle sslHandle,
181181
byte* buffer,
182182
int length);
@@ -190,8 +190,8 @@ internal static unsafe PAL_SSLStreamStatus SSLStreamWrite(
190190
}
191191
}
192192

193-
[DllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamRelease")]
194-
internal static extern void SSLStreamRelease(IntPtr ptr);
193+
[GeneratedDllImport(Interop.Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamRelease")]
194+
internal static partial void SSLStreamRelease(IntPtr ptr);
195195

196196
internal sealed class SslException : Exception
197197
{
@@ -205,8 +205,8 @@ internal SslException(int errorCode)
205205
}
206206
}
207207

208-
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamGetProtocol")]
209-
private static extern int SSLStreamGetProtocol(SafeSslHandle ssl, out IntPtr protocol);
208+
[GeneratedDllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamGetProtocol")]
209+
private static partial int SSLStreamGetProtocol(SafeSslHandle ssl, out IntPtr protocol);
210210
internal static string SSLStreamGetProtocol(SafeSslHandle ssl)
211211
{
212212
IntPtr protocolPtr;
@@ -222,11 +222,11 @@ internal static string SSLStreamGetProtocol(SafeSslHandle ssl)
222222
return protocol;
223223
}
224224

225-
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamGetPeerCertificate")]
226-
internal static extern SafeX509Handle SSLStreamGetPeerCertificate(SafeSslHandle ssl);
225+
[GeneratedDllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamGetPeerCertificate")]
226+
internal static partial SafeX509Handle SSLStreamGetPeerCertificate(SafeSslHandle ssl);
227227

228-
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamGetPeerCertificates")]
229-
private static extern void SSLStreamGetPeerCertificates(
228+
[GeneratedDllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamGetPeerCertificates")]
229+
private static partial void SSLStreamGetPeerCertificates(
230230
SafeSslHandle ssl,
231231
[MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] out IntPtr[] certs,
232232
out int count);
@@ -238,8 +238,8 @@ private static extern void SSLStreamGetPeerCertificates(
238238
return ptrs;
239239
}
240240

241-
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamGetCipherSuite")]
242-
private static extern int SSLStreamGetCipherSuite(SafeSslHandle ssl, out IntPtr cipherSuite);
241+
[GeneratedDllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamGetCipherSuite")]
242+
private static partial int SSLStreamGetCipherSuite(SafeSslHandle ssl, out IntPtr cipherSuite);
243243
internal static string SSLStreamGetCipherSuite(SafeSslHandle ssl)
244244
{
245245
IntPtr cipherSuitePtr;
@@ -255,13 +255,13 @@ internal static string SSLStreamGetCipherSuite(SafeSslHandle ssl)
255255
return cipherSuite;
256256
}
257257

258-
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamShutdown")]
258+
[GeneratedDllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamShutdown")]
259259
[return: MarshalAs(UnmanagedType.U1)]
260-
internal static extern bool SSLStreamShutdown(SafeSslHandle ssl);
260+
internal static partial bool SSLStreamShutdown(SafeSslHandle ssl);
261261

262-
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamVerifyHostname")]
262+
[GeneratedDllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_SSLStreamVerifyHostname")]
263263
[return: MarshalAs(UnmanagedType.U1)]
264-
internal static extern bool SSLStreamVerifyHostname(
264+
internal static partial bool SSLStreamVerifyHostname(
265265
SafeSslHandle ssl,
266266
[MarshalAs(UnmanagedType.LPUTF8Str)] string hostname);
267267
}

src/libraries/Common/src/Interop/Android/System.Security.Cryptography.Native.Android/Interop.X509.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ internal static partial class AndroidCrypto
1313
private const int INSUFFICIENT_BUFFER = -1;
1414
private const int SUCCESS = 1;
1515

16-
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_X509Decode")]
17-
internal static extern SafeX509Handle X509Decode(ref byte buf, int len);
16+
[GeneratedDllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_X509Decode")]
17+
internal static partial SafeX509Handle X509Decode(ref byte buf, int len);
1818

19-
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_X509Encode")]
20-
private static extern int X509Encode(SafeX509Handle x, [Out] byte[]? buf, ref int len);
19+
[GeneratedDllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_X509Encode")]
20+
private static partial int X509Encode(SafeX509Handle x, byte[]? buf, ref int len);
2121
internal static byte[] X509Encode(SafeX509Handle x)
2222
{
2323
int len = 0;
@@ -33,8 +33,8 @@ internal static byte[] X509Encode(SafeX509Handle x)
3333
return encoded;
3434
}
3535

36-
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_X509DecodeCollection")]
37-
private static extern int X509DecodeCollection(ref byte buf, int bufLen, IntPtr[]? ptrs, ref int handlesLen);
36+
[GeneratedDllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_X509DecodeCollection")]
37+
private static partial int X509DecodeCollection(ref byte buf, int bufLen, IntPtr[]? ptrs, ref int handlesLen);
3838
internal static SafeX509Handle[] X509DecodeCollection(ReadOnlySpan<byte> data)
3939
{
4040
ref byte buf = ref MemoryMarshal.GetReference(data);
@@ -60,8 +60,8 @@ internal static SafeX509Handle[] X509DecodeCollection(ReadOnlySpan<byte> data)
6060
return handles;
6161
}
6262

63-
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_X509ExportPkcs7")]
64-
private static extern int X509ExportPkcs7(IntPtr[] certs, int certsLen, [Out] byte[]? buf, ref int len);
63+
[GeneratedDllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_X509ExportPkcs7")]
64+
private static partial int X509ExportPkcs7(IntPtr[] certs, int certsLen, byte[]? buf, ref int len);
6565
internal static byte[] X509ExportPkcs7(IntPtr[] certHandles)
6666
{
6767
int len = 0;
@@ -77,8 +77,8 @@ internal static byte[] X509ExportPkcs7(IntPtr[] certHandles)
7777
return encoded;
7878
}
7979

80-
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_X509GetContentType")]
81-
private static extern X509ContentType X509GetContentType(ref byte buf, int len);
80+
[GeneratedDllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_X509GetContentType")]
81+
private static partial X509ContentType X509GetContentType(ref byte buf, int len);
8282
internal static X509ContentType X509GetContentType(ReadOnlySpan<byte> data)
8383
{
8484
return X509GetContentType(ref MemoryMarshal.GetReference(data), data.Length);
@@ -92,8 +92,8 @@ internal enum PAL_KeyAlgorithm
9292
UnknownAlgorithm = -1,
9393
}
9494

95-
[DllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_X509PublicKey")]
96-
internal static extern IntPtr X509GetPublicKey(SafeX509Handle x, PAL_KeyAlgorithm algorithm);
95+
[GeneratedDllImport(Libraries.AndroidCryptoNative, EntryPoint = "AndroidCryptoNative_X509PublicKey")]
96+
internal static partial IntPtr X509GetPublicKey(SafeX509Handle x, PAL_KeyAlgorithm algorithm);
9797
}
9898
}
9999

src/libraries/Common/src/Interop/BSD/System.Native/Interop.ProtocolStatistics.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public readonly struct TcpGlobalStatistics
3333
private readonly int __padding;
3434
}
3535

36-
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetTcpGlobalStatistics")]
37-
public static unsafe extern int GetTcpGlobalStatistics(TcpGlobalStatistics* statistics);
36+
[GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetTcpGlobalStatistics")]
37+
public static unsafe partial int GetTcpGlobalStatistics(TcpGlobalStatistics* statistics);
3838

3939
[StructLayoutAttribute(LayoutKind.Sequential)]
4040
public readonly struct IPv4GlobalStatistics
@@ -55,8 +55,8 @@ public readonly struct IPv4GlobalStatistics
5555
public readonly int Forwarding;
5656
}
5757

58-
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetIPv4GlobalStatistics")]
59-
public static unsafe extern int GetIPv4GlobalStatistics(IPv4GlobalStatistics* statistics);
58+
[GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetIPv4GlobalStatistics")]
59+
public static unsafe partial int GetIPv4GlobalStatistics(IPv4GlobalStatistics* statistics);
6060

6161
[StructLayoutAttribute(LayoutKind.Sequential)]
6262
public readonly struct UdpGlobalStatistics
@@ -68,8 +68,8 @@ public readonly struct UdpGlobalStatistics
6868
public readonly ulong UdpListeners;
6969
}
7070

71-
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetUdpGlobalStatistics")]
72-
public static unsafe extern int GetUdpGlobalStatistics(UdpGlobalStatistics* statistics);
71+
[GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetUdpGlobalStatistics")]
72+
public static unsafe partial int GetUdpGlobalStatistics(UdpGlobalStatistics* statistics);
7373

7474
[StructLayoutAttribute(LayoutKind.Sequential)]
7575
public readonly struct Icmpv4GlobalStatistics
@@ -98,8 +98,8 @@ public readonly struct Icmpv4GlobalStatistics
9898
public readonly ulong TimestampRequestsSent;
9999
}
100100

101-
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetIcmpv4GlobalStatistics")]
102-
public static unsafe extern int GetIcmpv4GlobalStatistics(Icmpv4GlobalStatistics* statistics);
101+
[GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetIcmpv4GlobalStatistics")]
102+
public static unsafe partial int GetIcmpv4GlobalStatistics(Icmpv4GlobalStatistics* statistics);
103103

104104
[StructLayoutAttribute(LayoutKind.Sequential)]
105105
public readonly struct Icmpv6GlobalStatistics
@@ -134,8 +134,8 @@ public readonly struct Icmpv6GlobalStatistics
134134
public readonly ulong TimeExceededMessagesSent;
135135
}
136136

137-
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetIcmpv6GlobalStatistics")]
138-
public static unsafe extern int GetIcmpv6GlobalStatistics(Icmpv6GlobalStatistics* statistics);
137+
[GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetIcmpv6GlobalStatistics")]
138+
public static unsafe partial int GetIcmpv6GlobalStatistics(Icmpv6GlobalStatistics* statistics);
139139

140140
public readonly struct NativeIPInterfaceStatistics
141141
{
@@ -158,7 +158,7 @@ public readonly struct NativeIPInterfaceStatistics
158158
[GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetNativeIPInterfaceStatistics", CharSet = CharSet.Ansi)]
159159
public static partial int GetNativeIPInterfaceStatistics(string name, out NativeIPInterfaceStatistics stats);
160160

161-
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetNumRoutes")]
162-
public static extern int GetNumRoutes();
161+
[GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetNumRoutes")]
162+
public static partial int GetNumRoutes();
163163
}
164164
}

0 commit comments

Comments
 (0)