From c9c5c0514012e615a392b1775f7624376fc6eddb Mon Sep 17 00:00:00 2001 From: Lex Li Date: Wed, 9 Oct 2024 21:25:34 -0400 Subject: [PATCH] Removed xamarin related. Revised .NET SDK detection. --- SharpSnmpLib/Helper.cs | 37 ------------------- SharpSnmpLib/Messaging/Discoverer.cs | 4 +- SharpSnmpLib/Messaging/Discovery.cs | 4 +- SharpSnmpLib/Messaging/Messenger.cs | 30 +++++++-------- SharpSnmpLib/Messaging/Net6Discoverer.cs | 2 +- SharpSnmpLib/Messaging/Net6Discovery.cs | 6 +-- SharpSnmpLib/Messaging/Net6Messenger.cs | 2 +- .../Messaging/Net6SnmpMessageExtension.cs | 12 +----- .../Messaging/SnmpMessageExtension.cs | 28 ++++++-------- .../Security/AESPrivacyProviderBase.cs | 15 +++----- SharpSnmpLib/Security/DESPrivacyProvider.cs | 14 +++---- .../Security/TripleDESPrivacyProvider.cs | 10 ++--- SharpSnmpLib/SharpSnmpLib.csproj | 26 ++++++------- Tests/CSharpCore/Tests.NetStandard.csproj | 22 ++++++----- .../Unit/Net6MessengerTestFixture.cs | 4 +- .../AES192PrivacyProviderTestFixture.cs | 2 +- .../AES256PrivacyProviderTestFixture.cs | 2 +- .../Security/AESPrivacyProviderTestFixture.cs | 8 +--- .../Security/DESPrivacyProviderTestFixture.cs | 14 +++---- .../TripleDESPrivacyProviderTestFixture.cs | 4 +- release.ps1 | 19 +--------- 21 files changed, 91 insertions(+), 174 deletions(-) diff --git a/SharpSnmpLib/Helper.cs b/SharpSnmpLib/Helper.cs index 254d040a..1ff38e4c 100644 --- a/SharpSnmpLib/Helper.cs +++ b/SharpSnmpLib/Helper.cs @@ -37,42 +37,5 @@ public static PhysicalAddress ToPhysicalAddress(this OctetString address) return new PhysicalAddress(raw); } - - private static bool? _desSupported; - - internal static bool DESSupported - { - get - { - if (_desSupported != null) - { - return _desSupported.Value; - } - - _desSupported = RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework") - || RuntimeInformation.FrameworkDescription.StartsWith(".NET 6.") - || RuntimeInformation.FrameworkDescription.StartsWith(".NET 5.") - || RuntimeInformation.FrameworkDescription.StartsWith(".NET Core 3.1."); - return _desSupported.Value; - } - } - - private static bool? _aesSupported; - - internal static bool AESSupported - { - get - { - if (_aesSupported != null) - { - return _aesSupported.Value; - } - - _aesSupported = RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework") - || RuntimeInformation.FrameworkDescription.StartsWith(".NET 6.") - || RuntimeInformation.FrameworkDescription.StartsWith(".NET 5."); - return _aesSupported.Value; - } - } } } diff --git a/SharpSnmpLib/Messaging/Discoverer.cs b/SharpSnmpLib/Messaging/Discoverer.cs index 263685e8..3a202d23 100644 --- a/SharpSnmpLib/Messaging/Discoverer.cs +++ b/SharpSnmpLib/Messaging/Discoverer.cs @@ -327,7 +327,7 @@ public async Task DiscoverAsync(VersionCode version, IPEndPoint broadcastAddress } _bufferSize = udp.ReceiveBufferSize; -#if NET6_0 +#if NET6_0_OR_GREATER var source = new CancellationTokenSource(); source.CancelAfter(interval); try @@ -354,7 +354,7 @@ await Task.WhenAny( // However, the shutdown call is necessary to release the socket binding. } } -#if !NET6_0 +#if !NET6_0_OR_GREATER private async Task ReceiveAsync(Socket socket) { while (true) diff --git a/SharpSnmpLib/Messaging/Discovery.cs b/SharpSnmpLib/Messaging/Discovery.cs index 6677c834..ab4abbdf 100644 --- a/SharpSnmpLib/Messaging/Discovery.cs +++ b/SharpSnmpLib/Messaging/Discovery.cs @@ -186,7 +186,7 @@ public Discovery(int messageId, int requestId, int maxMessageSize, SnmpType type /// The time-out value, in milliseconds. The default value is 0, which indicates an infinite time-out period. Specifying -1 also indicates an infinite time-out period. /// The receiver. /// -#if NET6_0 || NET5_0 +#if NET6_0_OR_GREATER [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("GetResponse is incompatible with trimming.")] #endif public ReportMessage GetResponse(int timeout, IPEndPoint receiver) @@ -205,7 +205,7 @@ public ReportMessage GetResponse(int timeout, IPEndPoint receiver) /// /// The receiver. /// -#if NET6_0 || NET5_0 +#if NET6_0_OR_GREATER [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("GetResponseAsync is incompatible with trimming.")] #endif public async Task GetResponseAsync(IPEndPoint receiver) diff --git a/SharpSnmpLib/Messaging/Messenger.cs b/SharpSnmpLib/Messaging/Messenger.cs index 2bc9c2f6..18912916 100644 --- a/SharpSnmpLib/Messaging/Messenger.cs +++ b/SharpSnmpLib/Messaging/Messenger.cs @@ -98,7 +98,7 @@ public static NumberGenerator RequestCounter /// Community name. /// Variable binds. /// -#if NET6_0 || NET5_0 +#if NET6_0_OR_GREATER [RequiresUnreferencedCode("GetAsync is incompatible with trimming.")] #endif public static async Task> GetAsync(VersionCode version, IPEndPoint endpoint, OctetString community, IList variables) @@ -145,7 +145,7 @@ public static async Task> GetAsync(VersionCode version, IPEndPoi /// Community name. /// Variable binds. /// -#if NET6_0 || NET5_0 +#if NET6_0_OR_GREATER [RequiresUnreferencedCode("SetAsync is incompatible with trimming.")] #endif public static async Task> SetAsync(VersionCode version, IPEndPoint endpoint, OctetString community, IList variables) @@ -197,7 +197,7 @@ public static async Task> SetAsync(VersionCode version, IPEndPoi /// Returns row count if the OID is a table. Otherwise this value is meaningless. /// /// This method only supports SNMP v1 and v2c. -#if NET6_0 || NET5_0 +#if NET6_0_OR_GREATER [RequiresUnreferencedCode("WalkAsync is incompatible with trimming.")] #endif public static async Task WalkAsync(VersionCode version, IPEndPoint endpoint, OctetString community, ObjectIdentifier table, IList list, WalkMode mode) @@ -257,7 +257,7 @@ public static async Task WalkAsync(VersionCode version, IPEndPoint endpoint /// true if the specified seed has next item; otherwise, false. /// /// This method only supports SNMP v1 and v2c. -#if NET6_0 || NET5_0 +#if NET6_0_OR_GREATER [RequiresUnreferencedCode("HasNextAsync is incompatible with trimming.")] #endif private static async Task> HasNextAsync(VersionCode version, IPEndPoint endpoint, OctetString community, Variable seed) @@ -295,7 +295,7 @@ public static async Task WalkAsync(VersionCode version, IPEndPoint endpoint /// The report. /// Returns row count if the OID is a table. Otherwise this value is meaningless. /// This method only supports SNMP v2c and v3. -#if NET6_0 || NET5_0 +#if NET6_0_OR_GREATER [RequiresUnreferencedCode("BulkWalkAsync is incompatible with trimming.")] #endif public static async Task BulkWalkAsync(VersionCode version, IPEndPoint endpoint, OctetString community, OctetString contextName, ObjectIdentifier table, IList list, int maxRepetitions, WalkMode mode, IPrivacyProvider privacy, ISnmpMessage report) @@ -404,7 +404,7 @@ public static async Task SendTrapV2Async(int requestId, VersionCode version, End /// The report. /// This method supports SNMP v2c and v3. [CLSCompliant(false)] -#if NET6_0 || NET5_0 +#if NET6_0_OR_GREATER [RequiresUnreferencedCode("SendInformAsync is incompatible with trimming.")] #endif public static async Task SendInformAsync(int requestId, VersionCode version, IPEndPoint receiver, OctetString community, OctetString contextName, ObjectIdentifier enterprise, uint timestamp, IList variables, IPrivacyProvider privacy, ISnmpMessage report) @@ -495,7 +495,7 @@ public static async Task SendInformAsync(int requestId, VersionCode version, IPE /// true if the specified seed has next item; otherwise, false. /// /// This method supports SNMP v2c and v3. -#if NET6_0 || NET5_0 +#if NET6_0_OR_GREATER [RequiresUnreferencedCode("BulkHasNextAsync is incompatible with trimming.")] #endif private static async Task, ISnmpMessage>> BulkHasNextAsync(VersionCode version, IPEndPoint receiver, OctetString community, OctetString contextName, Variable seed, int maxRepetitions, IPrivacyProvider privacy, ISnmpMessage report) @@ -582,7 +582,7 @@ private static async Task, ISnmpMessage>> BulkHasNex /// The time-out value, in milliseconds. The default value is 0, which indicates an infinite time-out period. Specifying -1 also indicates an infinite time-out period. /// /// This method supports SNMP v1 and v2c. -#if NET6_0 || NET5_0 +#if NET6_0_OR_GREATER [RequiresUnreferencedCode("Get is incompatible with trimming.")] #endif public static IList Get(VersionCode version, IPEndPoint endpoint, OctetString community, IList variables, int timeout) @@ -631,7 +631,7 @@ public static IList Get(VersionCode version, IPEndPoint endpoint, Octe /// The time-out value, in milliseconds. The default value is 0, which indicates an infinite time-out period. Specifying -1 also indicates an infinite time-out period. /// /// This method supports SNMP v1 and v2c. -#if NET6_0 || NET5_0 +#if NET6_0_OR_GREATER [RequiresUnreferencedCode("Set is incompatible with trimming.")] #endif public static IList Set(VersionCode version, IPEndPoint endpoint, OctetString community, IList variables, int timeout) @@ -684,7 +684,7 @@ public static IList Set(VersionCode version, IPEndPoint endpoint, Octe /// Returns row count if the OID is a table. Otherwise this value is meaningless. /// /// This method supports SNMP v1 and v2c. -#if NET6_0 || NET5_0 +#if NET6_0_OR_GREATER [RequiresUnreferencedCode("Walk is incompatible with trimming.")] #endif public static int Walk(VersionCode version, IPEndPoint endpoint, OctetString community, ObjectIdentifier table, IList list, int timeout, WalkMode mode) @@ -742,7 +742,7 @@ public static int Walk(VersionCode version, IPEndPoint endpoint, OctetString com /// true if the specified seed has next item; otherwise, false. /// /// This method supports SNMP v1 and v2c. -#if NET6_0 || NET5_0 +#if NET6_0_OR_GREATER [RequiresUnreferencedCode("HasNext is incompatible with trimming.")] #endif private static bool HasNext(VersionCode version, IPEndPoint endpoint, OctetString community, Variable seed, int timeout, out Variable? next) @@ -782,7 +782,7 @@ private static bool HasNext(VersionCode version, IPEndPoint endpoint, OctetStrin /// The report. /// Returns row count if the OID is a table. Otherwise this value is meaningless. /// This method supports SNMP v2c and v3. -#if NET6_0 || NET5_0 +#if NET6_0_OR_GREATER [RequiresUnreferencedCode("BulkWalk is incompatible with trimming.")] #endif public static int BulkWalk(VersionCode version, IPEndPoint endpoint, OctetString community, OctetString contextName, ObjectIdentifier table, IList list, int timeout, int maxRepetitions, WalkMode mode, IPrivacyProvider? privacy, ISnmpMessage? report) @@ -891,7 +891,7 @@ public static void SendTrapV2(int requestId, VersionCode version, EndPoint recei /// The report. /// This method supports SNMP v2c and v3. [CLSCompliant(false)] -#if NET6_0 || NET5_0 +#if NET6_0_OR_GREATER [RequiresUnreferencedCode("SendInform is incompatible with trimming.")] #endif public static void SendInform(int requestId, VersionCode version, IPEndPoint receiver, OctetString community, OctetString contextName, ObjectIdentifier enterprise, uint timestamp, IList variables, int timeout, IPrivacyProvider privacy, ISnmpMessage report) @@ -984,7 +984,7 @@ public static void SendInform(int requestId, VersionCode version, IPEndPoint rec /// true if the specified seed has next item; otherwise, false. /// /// This method supports SNMP v2c and v3. -#if NET6_0 || NET5_0 +#if NET6_0_OR_GREATER [RequiresUnreferencedCode("BulkHasNext is incompatible with trimming.")] #endif private static bool BulkHasNext(VersionCode version, IPEndPoint receiver, OctetString community, OctetString contextName, Variable seed, int timeout, int maxRepetitions, out IList next, IPrivacyProvider? privacy, ref ISnmpMessage? report) @@ -1072,7 +1072,7 @@ private static bool BulkHasNext(VersionCode version, IPEndPoint receiver, OctetS /// /// This method supports SNMP v2c and v3. [CLSCompliant(false)] -#if NET6_0 || NET5_0 +#if NET6_0_OR_GREATER [RequiresUnreferencedCode("GetTable is incompatible with trimming.")] #endif [Obsolete("This method only works for a few scenarios. Might be replaced by new methods in the future. If it does not work for you, parse WALK result on your own.")] diff --git a/SharpSnmpLib/Messaging/Net6Discoverer.cs b/SharpSnmpLib/Messaging/Net6Discoverer.cs index 6c58592f..913aeebb 100644 --- a/SharpSnmpLib/Messaging/Net6Discoverer.cs +++ b/SharpSnmpLib/Messaging/Net6Discoverer.cs @@ -25,7 +25,7 @@ namespace Lextm.SharpSnmpLib.Messaging { -#if NET6_0 +#if NET6_0_OR_GREATER /// /// Discoverer class to discover SNMP agents in the same network. /// diff --git a/SharpSnmpLib/Messaging/Net6Discovery.cs b/SharpSnmpLib/Messaging/Net6Discovery.cs index c5fe0f76..70b08bdb 100644 --- a/SharpSnmpLib/Messaging/Net6Discovery.cs +++ b/SharpSnmpLib/Messaging/Net6Discovery.cs @@ -38,16 +38,14 @@ namespace Lextm.SharpSnmpLib.Messaging /// public sealed partial class Discovery { -#if NET6_0 +#if NET6_0_OR_GREATER /// /// Gets the response. /// /// The receiver. /// The cancellation token. /// - #if NET6_0 [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("GetResponseAsync is incompatible with trimming.")] - #endif public async Task GetResponseAsync(IPEndPoint receiver, CancellationToken token) { if (receiver == null) @@ -58,6 +56,6 @@ public async Task GetResponseAsync(IPEndPoint receiver, Cancellat using var socket = receiver.GetSocket(); return (ReportMessage)await _discovery.GetResponseAsync(receiver, Empty, socket, token).ConfigureAwait(false); } - #endif +#endif } } diff --git a/SharpSnmpLib/Messaging/Net6Messenger.cs b/SharpSnmpLib/Messaging/Net6Messenger.cs index a2c0df8a..30f21910 100644 --- a/SharpSnmpLib/Messaging/Net6Messenger.cs +++ b/SharpSnmpLib/Messaging/Net6Messenger.cs @@ -25,7 +25,7 @@ * * To change this template use Tools | Options | Coding | Edit Standard Headers. */ -#if NET6_0 +#if NET6_0_OR_GREATER using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; diff --git a/SharpSnmpLib/Messaging/Net6SnmpMessageExtension.cs b/SharpSnmpLib/Messaging/Net6SnmpMessageExtension.cs index 2a96a4d3..768e62a5 100644 --- a/SharpSnmpLib/Messaging/Net6SnmpMessageExtension.cs +++ b/SharpSnmpLib/Messaging/Net6SnmpMessageExtension.cs @@ -17,15 +17,13 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -#if NET6_0 +#if NET6_0_OR_GREATER using System; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Net; using System.Net.Sockets; -#if NETSTANDARD2_0 using System.Runtime.InteropServices; -#endif using System.Threading; using System.Threading.Tasks; using Lextm.SharpSnmpLib.Security; @@ -115,9 +113,7 @@ public static async Task SendAsync(this ISnmpMessage message, EndPoint manager, /// User registry. /// The cancellation token. /// -#if NET6_0 || NET5_0 [RequiresUnreferencedCode("GetResponseAsync is incompatible with trimming.")] -#endif public static async Task GetResponseAsync(this ISnmpMessage request, IPEndPoint receiver, UserRegistry registry, CancellationToken token) { // TODO: make more usage of UserRegistry. @@ -148,9 +144,7 @@ public static async Task GetResponseAsync(this ISnmpMessage reques /// Port number. /// The cancellation token. /// -#if NET6_0 || NET5_0 [RequiresUnreferencedCode("GetResponseAsync is incompatible with trimming.")] -#endif public static async Task GetResponseAsync(this ISnmpMessage request, IPEndPoint receiver, CancellationToken token) { if (request == null) @@ -181,9 +175,7 @@ public static async Task GetResponseAsync(this ISnmpMessage reques /// The UDP to use to send/receive. /// The cancellation token. /// -#if NET6_0 || NET5_0 [RequiresUnreferencedCode("GetResponseAsync is incompatible with trimming.")] -#endif public static async Task GetResponseAsync(this ISnmpMessage request, IPEndPoint receiver, Socket udpSocket, CancellationToken token) { if (request == null) @@ -219,9 +211,7 @@ public static async Task GetResponseAsync(this ISnmpMessage reques /// The user registry. /// The cancellation token. /// -#if NET6_0 || NET5_0 [RequiresUnreferencedCode("GetResponseAsync is incompatible with trimming.")] -#endif public static async Task GetResponseAsync(this ISnmpMessage request, IPEndPoint receiver, UserRegistry registry, Socket udpSocket, CancellationToken token) { if (request == null) diff --git a/SharpSnmpLib/Messaging/SnmpMessageExtension.cs b/SharpSnmpLib/Messaging/SnmpMessageExtension.cs index 577ff07c..0220f304 100644 --- a/SharpSnmpLib/Messaging/SnmpMessageExtension.cs +++ b/SharpSnmpLib/Messaging/SnmpMessageExtension.cs @@ -23,9 +23,7 @@ using System.Globalization; using System.Net; using System.Net.Sockets; -#if NETSTANDARD2_0 using System.Runtime.InteropServices; -#endif using System.Threading.Tasks; using Lextm.SharpSnmpLib.Security; @@ -200,7 +198,7 @@ public static void Send(this ISnmpMessage message, EndPoint manager, Socket sock /// Port number. /// User registry. /// -#if NET6_0 || NET5_0 +#if NET6_0_OR_GREATER [RequiresUnreferencedCode("GetResponse is incompatible with trimming.")] #endif public static ISnmpMessage GetResponse(this ISnmpMessage request, int timeout, IPEndPoint receiver, UserRegistry registry) @@ -233,7 +231,7 @@ public static ISnmpMessage GetResponse(this ISnmpMessage request, int timeout, I /// The time-out value, in milliseconds. The default value is 0, which indicates an infinite time-out period. Specifying -1 also indicates an infinite time-out period. /// Port number. /// -#if NET6_0 || NET5_0 +#if NET6_0_OR_GREATER [RequiresUnreferencedCode("GetResponse is incompatible with trimming.")] #endif public static ISnmpMessage GetResponse(this ISnmpMessage request, int timeout, IPEndPoint receiver) @@ -266,7 +264,7 @@ public static ISnmpMessage GetResponse(this ISnmpMessage request, int timeout, I /// Agent. /// The UDP to use to send/receive. /// -#if NET6_0 || NET5_0 +#if NET6_0_OR_GREATER [RequiresUnreferencedCode("GetResponse is incompatible with trimming.")] #endif public static ISnmpMessage GetResponse(this ISnmpMessage request, int timeout, IPEndPoint receiver, Socket udpSocket) @@ -304,7 +302,7 @@ public static ISnmpMessage GetResponse(this ISnmpMessage request, int timeout, I /// The UDP to use to send/receive. /// The user registry. /// -#if NET6_0 || NET5_0 +#if NET6_0_OR_GREATER [RequiresUnreferencedCode("GetResponse is incompatible with trimming.")] #endif public static ISnmpMessage GetResponse(this ISnmpMessage request, int timeout, IPEndPoint receiver, UserRegistry registry, Socket udpSocket) @@ -459,7 +457,7 @@ public static async Task SendAsync(this ISnmpMessage message, EndPoint manager, /// Port number. /// User registry. /// -#if NET6_0 || NET5_0 +#if NET6_0_OR_GREATER [RequiresUnreferencedCode("GetResponseAsync is incompatible with trimming.")] #endif public static async Task GetResponseAsync(this ISnmpMessage request, IPEndPoint receiver, UserRegistry registry) @@ -491,7 +489,7 @@ public static async Task GetResponseAsync(this ISnmpMessage reques /// The . /// Port number. /// -#if NET6_0 || NET5_0 +#if NET6_0_OR_GREATER [RequiresUnreferencedCode("GetResponseAsync is incompatible with trimming.")] #endif public static async Task GetResponseAsync(this ISnmpMessage request, IPEndPoint receiver) @@ -523,7 +521,7 @@ public static async Task GetResponseAsync(this ISnmpMessage reques /// Agent. /// The UDP to use to send/receive. /// -#if NET6_0 || NET5_0 +#if NET6_0_OR_GREATER [RequiresUnreferencedCode("GetResponseAsync is incompatible with trimming.")] #endif public static async Task GetResponseAsync(this ISnmpMessage request, IPEndPoint receiver, Socket udpSocket) @@ -560,7 +558,7 @@ public static async Task GetResponseAsync(this ISnmpMessage reques /// The UDP to use to send/receive. /// The user registry. /// -#if NET6_0 || NET5_0 +#if NET6_0_OR_GREATER [RequiresUnreferencedCode("GetResponseAsync is incompatible with trimming.")] #endif public static async Task GetResponseAsync(this ISnmpMessage request, IPEndPoint receiver, UserRegistry registry, Socket udpSocket) @@ -645,7 +643,7 @@ public static async Task GetResponseAsync(this ISnmpMessage reques /// Tests if running on Mono. /// /// -#if NET6_0 || NET5_0 +#if NET6_0_OR_GREATER [RequiresUnreferencedCode("IsRunningOnMono is incompatible with trimming.")] #endif @@ -665,7 +663,7 @@ public static bool IsRunningOnWindows { #if NET471 return !IsRunningOnMono(); -#elif NETSTANDARD2_0 +#elif NET6_0_OR_GREATER return RuntimeInformation.IsOSPlatform(OSPlatform.Windows); #else return false; @@ -683,7 +681,7 @@ public static bool IsRunningOnMac { #if NET471 return IsRunningOnMono(); -#elif NETSTANDARD2_0 +#elif NET6_0_OR_GREATER return RuntimeInformation.IsOSPlatform(OSPlatform.OSX); #else return false; @@ -702,10 +700,8 @@ public static bool IsRunningOnIOS { #if NET471 return false; -#elif NETSTANDARD2_0 +#elif NET6_0_OR_GREATER return RuntimeInformation.IsOSPlatform(OSPlatform.OSX); -#elif XAMARINIOS1_0 - return true; #else return false; #endif diff --git a/SharpSnmpLib/Security/AESPrivacyProviderBase.cs b/SharpSnmpLib/Security/AESPrivacyProviderBase.cs index f213a23e..a764947d 100644 --- a/SharpSnmpLib/Security/AESPrivacyProviderBase.cs +++ b/SharpSnmpLib/Security/AESPrivacyProviderBase.cs @@ -28,7 +28,6 @@ using System; using System.Collections.Generic; -using System.IO; using System.Security.Cryptography; namespace Lextm.SharpSnmpLib.Security @@ -52,15 +51,11 @@ public static bool IsSupported { get { -#if NETSTANDARD2_0 - return Helper.AESSupported; -#else return true; -#endif } } -#if NET6_0 +#if NET6_0_OR_GREATER /// /// Flag to force using legacy encryption/decryption code on .NET 6. /// @@ -145,14 +140,14 @@ internal byte[] Encrypt(byte[] unencryptedData, byte[] key, int engineBoots, int var iv = GetIV(engineBoots, engineTime, privacyParameters); var pkey = GetKey(key); -#if NET6_0 +#if NET6_0_OR_GREATER return UseLegacy ? LegacyEncrypt(pkey, iv, unencryptedData) : Net6Encrypt(pkey, iv, unencryptedData); #else return LegacyEncrypt(pkey, iv, unencryptedData); #endif } -#if NET6_0 +#if NET6_0_OR_GREATER internal static byte[] Net6Encrypt(byte[] key, byte[] iv, byte[] unencryptedData) { using Aes aes = Aes.Create(); @@ -245,14 +240,14 @@ internal byte[] Decrypt(byte[] encryptedData, byte[] key, int engineBoots, int e var iv = GetIV(engineBoots, engineTime, privacyParameters); var finalKey = GetKey(key); -#if NET6_0 +#if NET6_0_OR_GREATER return UseLegacy ? LegacyDecrypt(finalKey, iv, encryptedData) : Net6Decrypt(finalKey, iv, encryptedData); #else return LegacyDecrypt(finalKey, iv, encryptedData); #endif } -#if NET6_0 +#if NET6_0_OR_GREATER internal static byte[] Net6Decrypt(byte[] key, byte[] iv, byte[] encryptedData) { using Aes aes = Aes.Create(); diff --git a/SharpSnmpLib/Security/DESPrivacyProvider.cs b/SharpSnmpLib/Security/DESPrivacyProvider.cs index f679e195..89620fd8 100644 --- a/SharpSnmpLib/Security/DESPrivacyProvider.cs +++ b/SharpSnmpLib/Security/DESPrivacyProvider.cs @@ -41,15 +41,11 @@ public static bool IsSupported { get { -#if NETSTANDARD2_0 - return Helper.DESSupported; -#else return true; -#endif } } -#if NET6_0 +#if NET6_0_OR_GREATER /// /// Flag to force using legacy encryption/decryption code on .NET 6. /// @@ -146,14 +142,14 @@ public static byte[] Encrypt(byte[] unencryptedData, byte[] key, byte[] privacyP Buffer.BlockCopy(unencryptedData, 0, tmpBuffer, 0, unencryptedData.Length); unencryptedData = tmpBuffer; } -#if NET6_0 +#if NET6_0_OR_GREATER return UseLegacy ? LegacyEncrypt(outKey, iv, unencryptedData) : Net6Encrypt(outKey, iv, unencryptedData); #else return LegacyEncrypt(outKey, iv, unencryptedData); #endif } -#if NET6_0 +#if NET6_0_OR_GREATER internal static byte[] Net6Encrypt(byte[] key, byte[] iv, byte[] unencryptedData) { using DES des = DES.Create(); @@ -276,14 +272,14 @@ public static byte[] Decrypt(byte[] encryptedData, byte[] key, byte[] privacyPar // .NET implementation only takes an 8 byte key var outKey = new byte[8]; Buffer.BlockCopy(key, 0, outKey, 0, 8); -#if NET6_0 +#if NET6_0_OR_GREATER return Net6Decrypt(outKey, iv, encryptedData); #else return LegacyDecrypt(outKey, iv, encryptedData); #endif } -#if NET6_0 +#if NET6_0_OR_GREATER internal static byte[] Net6Decrypt(byte[] key, byte[] iv, byte[] encryptedData) { using DES des = DES.Create(); diff --git a/SharpSnmpLib/Security/TripleDESPrivacyProvider.cs b/SharpSnmpLib/Security/TripleDESPrivacyProvider.cs index d477a449..c9fc273d 100644 --- a/SharpSnmpLib/Security/TripleDESPrivacyProvider.cs +++ b/SharpSnmpLib/Security/TripleDESPrivacyProvider.cs @@ -34,7 +34,7 @@ namespace Lextm.SharpSnmpLib.Security [Obsolete("3DES is no longer secure. Please use a more secure provider.")] public sealed class TripleDESPrivacyProvider : IPrivacyProvider { -#if NET6_0 +#if NET6_0_OR_GREATER /// /// Flag to force using legacy encryption/decryption code on .NET 6. /// @@ -121,14 +121,14 @@ public static byte[] Encrypt(byte[] unencryptedData, byte[] key, byte[] privacyP Buffer.BlockCopy(unencryptedData, 0, tmpBuffer, 0, unencryptedData.Length); unencryptedData = tmpBuffer; } -#if NET6_0 +#if NET6_0_OR_GREATER return UseLegacy ? LegacyEncrypt(outKey, iv, unencryptedData) : Net6Encrypt(outKey, iv, unencryptedData); #else return LegacyEncrypt(outKey, iv, unencryptedData); #endif } -#if NET6_0 +#if NET6_0_OR_GREATER internal static byte[] Net6Encrypt(byte[] key, byte[] iv, byte[] unencryptedData) { using TripleDES des = TripleDES.Create(); @@ -197,14 +197,14 @@ public static byte[] Decrypt(byte[] encryptedData, byte[] key, byte[] privacyPar var iv = GetIV(key, privacyParameters); var outKey = GetKey(key); -#if NET6_0 +#if NET6_0_OR_GREATER return UseLegacy ? LegacyDecrypt(outKey, iv, encryptedData) : Net6Decrypt(outKey, iv, encryptedData); #else return LegacyDecrypt(outKey, iv, encryptedData); #endif } -#if NET6_0 +#if NET6_0_OR_GREATER internal static byte[] Net6Decrypt(byte[] key, byte[] iv, byte[] encryptedData) { using TripleDES des = TripleDES.Create(); diff --git a/SharpSnmpLib/SharpSnmpLib.csproj b/SharpSnmpLib/SharpSnmpLib.csproj index bd61a8d1..6252981b 100644 --- a/SharpSnmpLib/SharpSnmpLib.csproj +++ b/SharpSnmpLib/SharpSnmpLib.csproj @@ -4,14 +4,17 @@ Lextm.SharpSnmpLib false false - net6.0;netstandard2.0;net471 - netstandard2.0;net471 + + true + + net6.0;net471 + net471 Lextm.SharpSnmpLib #SNMP Library en-US Malcolm Crowe,Lex Li,and other contributors. - #SNMP (SharpSNMP) Library is an open source library for developers who target Microsoft .NET/Xamarin/Mono platforms. It's developed in C# and can be used for F#, VB.NET, Oxygene, and more. - #SNMP (SharpSNMP) Library is an open source library for developers who target Microsoft .NET/Xamarin/Mono platforms. It's developed in C# and can be used for F#, VB.NET, Oxygene, and more. It supports .NET Framework 4.7.1 and above, as well as .NET Standard 2.0 and above. + #SNMP (SharpSNMP) Library is an open source library for developers who target Microsoft .NET platforms. It's developed in C# and can be used for F#, VB.NET, Oxygene, and more. + #SNMP (SharpSNMP) Library is an open source library for developers who target Microsoft .NET platforms. It's developed in C# and can be used for F#, VB.NET, Oxygene, and more. It supports .NET Framework 4.7.1 and above, as well as .NET 6 and above. true https://docs.sharpsnmp.com/ https://github.com/lextudio/sharpsnmplib.git @@ -20,7 +23,7 @@ true $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb https://github.com/lextudio/sharpsnmplib/releases - Copyright (c) 2008-2022 Malcolm Crowe, Lex Li, and other contributors. + Copyright (c) 2008-2024 Malcolm Crowe, Lex Li, and other contributors. smi snmp mib true sharpsnmplib.snk @@ -35,21 +38,22 @@ true portable snupkg + net6.0 S5547;S907;S1133;S101;S1135 - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all @@ -57,12 +61,6 @@ - - - - - - diff --git a/Tests/CSharpCore/Tests.NetStandard.csproj b/Tests/CSharpCore/Tests.NetStandard.csproj index 184c641f..97b56775 100644 --- a/Tests/CSharpCore/Tests.NetStandard.csproj +++ b/Tests/CSharpCore/Tests.NetStandard.csproj @@ -4,13 +4,18 @@ True sharpsnmplib.tests.snk SharpSnmpLib.Tests.NetStandard + $(NoWarn);SYSLIB0011 Exe - net6.0;net8.0;net471 - net6.0;net471 - net6.0;net8.0 - net6.0 + + true + true + + net6.0;net8.0;net471 + net6.0;net471 + net6.0;net8.0 + net6.0 @@ -27,14 +32,13 @@ - - - + + + all runtime; build; native; contentfiles; analyzers - - + diff --git a/Tests/CSharpCore/Unit/Net6MessengerTestFixture.cs b/Tests/CSharpCore/Unit/Net6MessengerTestFixture.cs index fb2c8b47..d0b99dbe 100644 --- a/Tests/CSharpCore/Unit/Net6MessengerTestFixture.cs +++ b/Tests/CSharpCore/Unit/Net6MessengerTestFixture.cs @@ -12,7 +12,7 @@ namespace Lextm.SharpSnmpLib.Unit { public class Net6MessengerTestFixture { - #if NET6_0 +#if NET6_0_OR_GREATER [Fact] public async Task TestGetAsyncCanBeCancelled() { @@ -72,7 +72,7 @@ public async Task TestBulkWalkAsyncCanBeCancelled() } } } - #endif +#endif } } #pragma warning restore 1591 diff --git a/Tests/CSharpCore/Unit/Security/AES192PrivacyProviderTestFixture.cs b/Tests/CSharpCore/Unit/Security/AES192PrivacyProviderTestFixture.cs index 95f65d74..f70fae20 100644 --- a/Tests/CSharpCore/Unit/Security/AES192PrivacyProviderTestFixture.cs +++ b/Tests/CSharpCore/Unit/Security/AES192PrivacyProviderTestFixture.cs @@ -75,7 +75,7 @@ public void TestEncrypt2() Assert.Equal(ByteTool.Convert(original.ToBytes()), ByteTool.Convert(decrypted.ToBytes())); } -#if NET6_0 +#if NET6_0_OR_GREATER [Theory] [MemberData(nameof(Data))] public void CompatibilityTest(int length) diff --git a/Tests/CSharpCore/Unit/Security/AES256PrivacyProviderTestFixture.cs b/Tests/CSharpCore/Unit/Security/AES256PrivacyProviderTestFixture.cs index 0e89b848..5ae52b8c 100644 --- a/Tests/CSharpCore/Unit/Security/AES256PrivacyProviderTestFixture.cs +++ b/Tests/CSharpCore/Unit/Security/AES256PrivacyProviderTestFixture.cs @@ -75,7 +75,7 @@ public void TestEncrypt2() Assert.Equal(ByteTool.Convert(original.ToBytes()), ByteTool.Convert(decrypted.ToBytes())); } -#if NET6_0 +#if NET6_0_OR_GREATER [Theory] [MemberData(nameof(Data))] public void CompatibilityTest(int length) diff --git a/Tests/CSharpCore/Unit/Security/AESPrivacyProviderTestFixture.cs b/Tests/CSharpCore/Unit/Security/AESPrivacyProviderTestFixture.cs index b2f1b9e9..9a41ff60 100644 --- a/Tests/CSharpCore/Unit/Security/AESPrivacyProviderTestFixture.cs +++ b/Tests/CSharpCore/Unit/Security/AESPrivacyProviderTestFixture.cs @@ -45,12 +45,8 @@ public void TestException() [Fact] public void TestIsSupported() { -#if NET6_0 +#if NET6_0_OR_GREATER Assert.True(AESPrivacyProviderBase.IsSupported); -#elif NET5_0 - Assert.True(AESPrivacyProviderBase.IsSupported); -#elif NETCOREAPP3_1 - Assert.False(AESPrivacyProviderBase.IsSupported); #elif NET471 Assert.True(AESPrivacyProviderBase.IsSupported); #endif @@ -149,7 +145,7 @@ public void TestEncrypt3() Assert.Equal(recovered_received, recovered_encrypted); } -#if NET6_0 +#if NET6_0_OR_GREATER [Theory] [MemberData(nameof(Data))] public void CompatibilityTest(int length) diff --git a/Tests/CSharpCore/Unit/Security/DESPrivacyProviderTestFixture.cs b/Tests/CSharpCore/Unit/Security/DESPrivacyProviderTestFixture.cs index 0daadf18..8519444b 100644 --- a/Tests/CSharpCore/Unit/Security/DESPrivacyProviderTestFixture.cs +++ b/Tests/CSharpCore/Unit/Security/DESPrivacyProviderTestFixture.cs @@ -41,15 +41,11 @@ public void TestException() [Fact] public void TestIsSupported() { - #if NET6_0 +#if NET6_0_OR_GREATER + Assert.True(DESPrivacyProvider.IsSupported); +#elif NET471 Assert.True(DESPrivacyProvider.IsSupported); - #elif NET5_0 - Assert.True(DESPrivacyProvider.IsSupported); - #elif NETCOREAPP3_1 - Assert.True(DESPrivacyProvider.IsSupported); - #elif NET471 - Assert.True(DESPrivacyProvider.IsSupported); - #endif +#endif } [Fact] @@ -147,7 +143,7 @@ public void TestEncrypt2() Assert.Equal(ByteTool.Convert(expected), ByteTool.Convert(data.ToBytes())); } -#if NET6_0 +#if NET6_0_OR_GREATER [Theory] [MemberData(nameof(Data))] public void CompatibilityTest(int length) diff --git a/Tests/CSharpCore/Unit/Security/TripleDESPrivacyProviderTestFixture.cs b/Tests/CSharpCore/Unit/Security/TripleDESPrivacyProviderTestFixture.cs index 37f1d24c..d69f4773 100644 --- a/Tests/CSharpCore/Unit/Security/TripleDESPrivacyProviderTestFixture.cs +++ b/Tests/CSharpCore/Unit/Security/TripleDESPrivacyProviderTestFixture.cs @@ -54,7 +54,7 @@ public void TestEncrypt2() new MD5AuthenticationProvider(new OctetString("testpass"))); Scope scope = new Scope(engineId, OctetString.Empty, new GetRequestPdu(0x3A25, - new List {new Variable(new ObjectIdentifier("1.3.6.1.2.1.1.3.0"))})); + new List { new Variable(new ObjectIdentifier("1.3.6.1.2.1.1.3.0")) })); SecurityParameters parameters = new SecurityParameters(engineId, new Integer32(0x14), new Integer32(0x35), new OctetString("lexmark"), new OctetString(new byte[12]), new OctetString(ByteTool.Convert("00 00 00 01 44 2C A3 B5"))); @@ -67,7 +67,7 @@ public void TestEncrypt2() Assert.Equal(ByteTool.Convert(original.ToBytes()), ByteTool.Convert(decrypted.ToBytes())); } -#if NET6_0 +#if NET6_0_OR_GREATER [Theory] [MemberData(nameof(Data))] public void CompatibilityTest(int length) diff --git a/release.ps1 b/release.ps1 index 1b71f867..35b80369 100644 --- a/release.ps1 +++ b/release.ps1 @@ -4,31 +4,16 @@ param( [string] $Configuration = 'Release' ) -$msBuild = "msbuild" try { - & $msBuild /version - Write-Host "Likely on Linux/macOS." & dotnet restore & dotnet clean -c $Configuration & dotnet build -c $Configuration } catch { - Write-Host "MSBuild doesn't exist. Use VSSetup instead." - - $msbuild = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe -products * -nologo | select-object -first 1 - if (![System.IO.File]::Exists($msBuild)) - { - Write-Host "MSBuild doesn't exist. Exit." - exit 1 - } - - Write-Host "MSBuild found. Compile the projects." - - & $msBuild /m /p:Configuration=$Configuration /t:restore - & $msBuild /m /p:Configuration=$Configuration /t:clean - & $msBuild /m /p:Configuration=$Configuration + Write-Host ".NET SDK doesn't exist. Exit." + exit 1 } if ($LASTEXITCODE -ne 0)