From 9a434b860c155567028408d7352de54c6b9d7369 Mon Sep 17 00:00:00 2001 From: Martin Regen <7962757+mregen@users.noreply.github.com> Date: Fri, 13 Dec 2024 17:41:14 +0100 Subject: [PATCH] Fix misc. build issues and warnings (#2908) - Fix errors and warnings on stricter build systems. - Some Linux distri do not support brainpool, detect if tests can be run. --- .editorconfig | 1 + .../AlarmHolders/AlarmConditionTypeHolder.cs | 4 +-- .../Alarms/AlarmHolders/DiscreteHolder.cs | 4 +-- .../MemoryBuffer/MemoryBufferNodeManager.cs | 3 +- .../Opc.Ua.Client.ComplexTypes.csproj | 2 +- Libraries/Opc.Ua.Client/Opc.Ua.Client.csproj | 2 +- .../Opc.Ua.Client/Session/TraceableSession.cs | 13 ++++--- .../Opc.Ua.Configuration.csproj | 2 +- .../Opc.Ua.Gds.Client.Common.csproj | 2 +- .../Opc.Ua.Gds.Server.Common.csproj | 2 +- Libraries/Opc.Ua.PubSub/Opc.Ua.PubSub.csproj | 2 +- .../Opc.Ua.Security.Certificates.csproj | 2 +- Libraries/Opc.Ua.Server/Opc.Ua.Server.csproj | 2 +- .../Opc.Ua.Bindings.Https.csproj | 2 +- Stack/Opc.Ua.Core/Opc.Ua.Core.csproj | 2 +- .../Certificates/CertificateValidator.cs | 1 + .../SecurityConfigurationManager.cs | 10 ++++-- .../Stack/Tcp/TcpTransportListener.cs | 3 +- .../ContinuationPointInBatchTest.cs | 2 +- .../Stack/Buffers/ArraySegmentStreamTests.cs | 7 ++-- .../Types/Utils/UtilsIsEqualTests.cs | 4 +-- .../Encoding/MessagesHelper.cs | 15 ++++---- .../Transport/MqttPubSubConnectionTests.cs | 8 ++--- .../CertificateTestsForECDsa.cs | 36 ++++++++++++++----- common.props | 1 + 25 files changed, 83 insertions(+), 49 deletions(-) diff --git a/.editorconfig b/.editorconfig index 5b57ac1d05..6b60a276e8 100644 --- a/.editorconfig +++ b/.editorconfig @@ -12,6 +12,7 @@ root = true # All files [*] indent_style = space +tab_width = 4 # Code files [*.{cs,csx,vb,vbx}] diff --git a/Applications/Quickstarts.Servers/Alarms/AlarmHolders/AlarmConditionTypeHolder.cs b/Applications/Quickstarts.Servers/Alarms/AlarmHolders/AlarmConditionTypeHolder.cs index 616c60ba48..b4254168af 100644 --- a/Applications/Quickstarts.Servers/Alarms/AlarmHolders/AlarmConditionTypeHolder.cs +++ b/Applications/Quickstarts.Servers/Alarms/AlarmHolders/AlarmConditionTypeHolder.cs @@ -28,7 +28,7 @@ * ======================================================================*/ using System; - +using System.Globalization; using Opc.Ua; #pragma warning disable CS1591 @@ -272,7 +272,7 @@ private ServiceResult OnShelve( } else { - dueTo = " due to TimedShelve of " + shelvingTime.ToString(); + dueTo = " due to TimedShelve of " + shelvingTime.ToString(CultureInfo.InvariantCulture); } } else diff --git a/Applications/Quickstarts.Servers/Alarms/AlarmHolders/DiscreteHolder.cs b/Applications/Quickstarts.Servers/Alarms/AlarmHolders/DiscreteHolder.cs index c40953edd8..2d15d627f7 100644 --- a/Applications/Quickstarts.Servers/Alarms/AlarmHolders/DiscreteHolder.cs +++ b/Applications/Quickstarts.Servers/Alarms/AlarmHolders/DiscreteHolder.cs @@ -28,7 +28,7 @@ * ======================================================================*/ using System; - +using System.Globalization; using Opc.Ua; #pragma warning disable CS0219 @@ -85,7 +85,7 @@ public override void SetValue(string message = "") if (message.Length == 0) { - message = "Discrete Alarm analog value = " + value.ToString() + ", active = " + active.ToString(); + message = "Discrete Alarm analog value = " + value.ToString(CultureInfo.InvariantCulture) + ", active = " + active.ToString(); } base.SetValue(message); diff --git a/Applications/Quickstarts.Servers/MemoryBuffer/MemoryBufferNodeManager.cs b/Applications/Quickstarts.Servers/MemoryBuffer/MemoryBufferNodeManager.cs index 59a5e18904..42d79f1908 100644 --- a/Applications/Quickstarts.Servers/MemoryBuffer/MemoryBufferNodeManager.cs +++ b/Applications/Quickstarts.Servers/MemoryBuffer/MemoryBufferNodeManager.cs @@ -38,6 +38,7 @@ using Opc.Ua.Server; using Opc.Ua.Sample; using System.Reflection; +using System.Globalization; namespace MemoryBuffer { @@ -234,7 +235,7 @@ protected override object GetManagerHandle(ISystemContext context, NodeId nodeId } // check range on offset. - uint offset = Convert.ToUInt32(offsetText); + uint offset = Convert.ToUInt32(offsetText, CultureInfo.InvariantCulture); if (offset >= buffer.SizeInBytes.Value) { diff --git a/Libraries/Opc.Ua.Client.ComplexTypes/Opc.Ua.Client.ComplexTypes.csproj b/Libraries/Opc.Ua.Client.ComplexTypes/Opc.Ua.Client.ComplexTypes.csproj index 6be179a1d4..764c794d21 100644 --- a/Libraries/Opc.Ua.Client.ComplexTypes/Opc.Ua.Client.ComplexTypes.csproj +++ b/Libraries/Opc.Ua.Client.ComplexTypes/Opc.Ua.Client.ComplexTypes.csproj @@ -3,7 +3,7 @@ Opc.Ua.Client.ComplexTypes $(LibxTargetFrameworks) - OPCFoundation.NetStandard.Opc.Ua.Client.ComplexTypes + $(PackagePrefix).Opc.Ua.Client.ComplexTypes Opc.Ua.Client.ComplexTypes OPC UA Complex Types Client Class Library true diff --git a/Libraries/Opc.Ua.Client/Opc.Ua.Client.csproj b/Libraries/Opc.Ua.Client/Opc.Ua.Client.csproj index a808f4a197..c01e640733 100644 --- a/Libraries/Opc.Ua.Client/Opc.Ua.Client.csproj +++ b/Libraries/Opc.Ua.Client/Opc.Ua.Client.csproj @@ -4,7 +4,7 @@ $(DefineConstants);CLIENT_ASYNC Opc.Ua.Client $(LibTargetFrameworks) - OPCFoundation.NetStandard.Opc.Ua.Client + $(PackagePrefix).Opc.Ua.Client Opc.Ua.Client OPC UA Client Class Library true diff --git a/Libraries/Opc.Ua.Client/Session/TraceableSession.cs b/Libraries/Opc.Ua.Client/Session/TraceableSession.cs index 6bd4d2bcef..f2c2620d8a 100644 --- a/Libraries/Opc.Ua.Client/Session/TraceableSession.cs +++ b/Libraries/Opc.Ua.Client/Session/TraceableSession.cs @@ -287,7 +287,7 @@ public int OperationTimeout /// public bool CheckDomain => m_session.CheckDomain; - + /// public ContinuationPointPolicy ContinuationPointPolicy { @@ -661,7 +661,7 @@ public void ReadValues(IList variableIds, IList expectedTypes, out m_session.ReadValues(variableIds, expectedTypes, out values, out errors); } } - + /// public byte[] ReadByteStringInChunks(NodeId nodeId) { @@ -671,8 +671,8 @@ public byte[] ReadByteStringInChunks(NodeId nodeId) } } - /// - public void ReadDisplayName(IList nodeIds, out IList displayNames, out IList errors) + /// + public void ReadDisplayName(IList nodeIds, out IList displayNames, out IList errors) { using (Activity activity = ActivitySource.StartActivity()) { @@ -1289,18 +1289,17 @@ public void ManagedBrowse(RequestHeader requestHeader, ViewDescription view, ILi { m_session.ManagedBrowse(requestHeader, view, nodesToBrowse, maxResultsToReturn, browseDirection, referenceTypeId, includeSubtypes, nodeClassMask, out result, out errors); } - } /// - public async Task<( + public Task<( IList, IList )> ManagedBrowseAsync(RequestHeader requestHeader, ViewDescription view, IList nodesToBrowse, uint maxResultsToReturn, BrowseDirection browseDirection, NodeId referenceTypeId, bool includeSubtypes, uint nodeClassMask, CancellationToken ct = default) { using (Activity activity = ActivitySource.StartActivity()) { - return await m_session.ManagedBrowseAsync(requestHeader, view, nodesToBrowse, maxResultsToReturn, browseDirection, referenceTypeId, includeSubtypes, nodeClassMask, ct); + return m_session.ManagedBrowseAsync(requestHeader, view, nodesToBrowse, maxResultsToReturn, browseDirection, referenceTypeId, includeSubtypes, nodeClassMask, ct); } } diff --git a/Libraries/Opc.Ua.Configuration/Opc.Ua.Configuration.csproj b/Libraries/Opc.Ua.Configuration/Opc.Ua.Configuration.csproj index d1886c4279..be7a06fa49 100644 --- a/Libraries/Opc.Ua.Configuration/Opc.Ua.Configuration.csproj +++ b/Libraries/Opc.Ua.Configuration/Opc.Ua.Configuration.csproj @@ -3,7 +3,7 @@ Opc.Ua.Configuration $(LibTargetFrameworks) - OPCFoundation.NetStandard.Opc.Ua.Configuration + $(PackagePrefix).Opc.Ua.Configuration Opc.Ua.Configuration OPC UA Configuration Class Library true diff --git a/Libraries/Opc.Ua.Gds.Client.Common/Opc.Ua.Gds.Client.Common.csproj b/Libraries/Opc.Ua.Gds.Client.Common/Opc.Ua.Gds.Client.Common.csproj index 077b4be878..c4fefa1ef4 100644 --- a/Libraries/Opc.Ua.Gds.Client.Common/Opc.Ua.Gds.Client.Common.csproj +++ b/Libraries/Opc.Ua.Gds.Client.Common/Opc.Ua.Gds.Client.Common.csproj @@ -3,7 +3,7 @@ Opc.Ua.Gds.Client.Common $(LibTargetFrameworks) - OPCFoundation.NetStandard.Opc.Ua.Gds.Client.Common + $(PackagePrefix).Opc.Ua.Gds.Client.Common Opc.Ua.Gds.Client $(NoWarn);CS1591 OPC UA GDS Client Class Library diff --git a/Libraries/Opc.Ua.Gds.Server.Common/Opc.Ua.Gds.Server.Common.csproj b/Libraries/Opc.Ua.Gds.Server.Common/Opc.Ua.Gds.Server.Common.csproj index d46cc04559..0bb5c0e1f1 100644 --- a/Libraries/Opc.Ua.Gds.Server.Common/Opc.Ua.Gds.Server.Common.csproj +++ b/Libraries/Opc.Ua.Gds.Server.Common/Opc.Ua.Gds.Server.Common.csproj @@ -3,7 +3,7 @@ Opc.Ua.Gds.Server.Common $(LibTargetFrameworks) - OPCFoundation.NetStandard.Opc.Ua.Gds.Server.Common + $(PackagePrefix).Opc.Ua.Gds.Server.Common Opc.Ua.Gds.Server $(NoWarn);CS1591 OPC UA GDS Server Class Library diff --git a/Libraries/Opc.Ua.PubSub/Opc.Ua.PubSub.csproj b/Libraries/Opc.Ua.PubSub/Opc.Ua.PubSub.csproj index 7286c6b3ec..419ac2c276 100644 --- a/Libraries/Opc.Ua.PubSub/Opc.Ua.PubSub.csproj +++ b/Libraries/Opc.Ua.PubSub/Opc.Ua.PubSub.csproj @@ -3,7 +3,7 @@ Opc.Ua.PubSub $(LibxTargetFrameworks) - OPCFoundation.NetStandard.Opc.Ua.PubSub + $(PackagePrefix).Opc.Ua.PubSub Opc.Ua.PubSub OPC UA PubSub Class Library true diff --git a/Libraries/Opc.Ua.Security.Certificates/Opc.Ua.Security.Certificates.csproj b/Libraries/Opc.Ua.Security.Certificates/Opc.Ua.Security.Certificates.csproj index 67aa710321..5fc06442de 100644 --- a/Libraries/Opc.Ua.Security.Certificates/Opc.Ua.Security.Certificates.csproj +++ b/Libraries/Opc.Ua.Security.Certificates/Opc.Ua.Security.Certificates.csproj @@ -3,7 +3,7 @@ Opc.Ua.Security.Certificates $(LibCoreTargetFrameworks) - OPCFoundation.NetStandard.Opc.Ua.Security.Certificates + $(PackagePrefix).Opc.Ua.Security.Certificates Opc.Ua.Security.Certificates OPC UA Security X509 Certificates Class Library true diff --git a/Libraries/Opc.Ua.Server/Opc.Ua.Server.csproj b/Libraries/Opc.Ua.Server/Opc.Ua.Server.csproj index 5eff9082e9..b6e598fe7e 100644 --- a/Libraries/Opc.Ua.Server/Opc.Ua.Server.csproj +++ b/Libraries/Opc.Ua.Server/Opc.Ua.Server.csproj @@ -3,7 +3,7 @@ Opc.Ua.Server $(LibTargetFrameworks) - OPCFoundation.NetStandard.Opc.Ua.Server + $(PackagePrefix).Opc.Ua.Server Opc.Ua.Server OPC UA Server Class Library PackageReference diff --git a/Stack/Opc.Ua.Bindings.Https/Opc.Ua.Bindings.Https.csproj b/Stack/Opc.Ua.Bindings.Https/Opc.Ua.Bindings.Https.csproj index d63a36fd5d..da79450376 100644 --- a/Stack/Opc.Ua.Bindings.Https/Opc.Ua.Bindings.Https.csproj +++ b/Stack/Opc.Ua.Bindings.Https/Opc.Ua.Bindings.Https.csproj @@ -4,7 +4,7 @@ true $(HttpsTargetFrameworks) Opc.Ua.Bindings.Https - OPCFoundation.NetStandard.Opc.Ua.Bindings.Https + $(PackagePrefix).Opc.Ua.Bindings.Https Opc.Ua.Bindings OPC UA Https Binding Library for a Opc.Ua.Server. true diff --git a/Stack/Opc.Ua.Core/Opc.Ua.Core.csproj b/Stack/Opc.Ua.Core/Opc.Ua.Core.csproj index 64ef8e948e..58fa34b887 100644 --- a/Stack/Opc.Ua.Core/Opc.Ua.Core.csproj +++ b/Stack/Opc.Ua.Core/Opc.Ua.Core.csproj @@ -4,7 +4,7 @@ $(DefineConstants);NET_STANDARD;NET_STANDARD_ASYNC $(LibCoreTargetFrameworks) Opc.Ua.Core - OPCFoundation.NetStandard.Opc.Ua.Core + $(PackagePrefix).Opc.Ua.Core Opc.Ua OPC UA Core Class Library true diff --git a/Stack/Opc.Ua.Core/Security/Certificates/CertificateValidator.cs b/Stack/Opc.Ua.Core/Security/Certificates/CertificateValidator.cs index 2c13adf880..6509c0a64b 100644 --- a/Stack/Opc.Ua.Core/Security/Certificates/CertificateValidator.cs +++ b/Stack/Opc.Ua.Core/Security/Certificates/CertificateValidator.cs @@ -1120,6 +1120,7 @@ await GetIssuerNoExceptionAsync(certificate, explicitList, certificateStore, che /// The endpoint for domain validation. /// The cancellation token. /// If certificate[0] cannot be accepted + [System.Diagnostics.CodeAnalysis.SuppressMessage("Roslynanalyzer", "IA5352:Do not set X509RevocationMode.NoCheck", Justification = "Revocation is already checked.")] protected virtual async Task InternalValidateAsync(X509Certificate2Collection certificates, ConfiguredEndpoint endpoint, CancellationToken ct = default) { X509Certificate2 certificate = certificates[0]; diff --git a/Stack/Opc.Ua.Core/Stack/Configuration/SecurityConfigurationManager.cs b/Stack/Opc.Ua.Core/Stack/Configuration/SecurityConfigurationManager.cs index 230791f772..4dbd1ca99f 100644 --- a/Stack/Opc.Ua.Core/Stack/Configuration/SecurityConfigurationManager.cs +++ b/Stack/Opc.Ua.Core/Stack/Configuration/SecurityConfigurationManager.cs @@ -88,11 +88,17 @@ public SecuredApplication ReadConfiguration(string filePath) { FileStream reader = File.Open(configFilePath, FileMode.Open, FileAccess.Read, FileShare.Read); - try { byte[] data = new byte[reader.Length]; - reader.Read(data, 0, (int)reader.Length); + int bytesRead = reader.Read(data, 0, (int)reader.Length); + if (reader.Length != bytesRead) + { + throw ServiceResultException.Create( + StatusCodes.BadNotReadable, + "Cannot read all bytes of the configuration file: {0}<{1}", + bytesRead, reader.Length); + } // find the SecuredApplication element in the file. if (data.ToString().Contains("SecuredApplication")) diff --git a/Stack/Opc.Ua.Core/Stack/Tcp/TcpTransportListener.cs b/Stack/Opc.Ua.Core/Stack/Tcp/TcpTransportListener.cs index 27c51eb717..85392a7ffd 100644 --- a/Stack/Opc.Ua.Core/Stack/Tcp/TcpTransportListener.cs +++ b/Stack/Opc.Ua.Core/Stack/Tcp/TcpTransportListener.cs @@ -14,6 +14,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; +using System.Globalization; using System.Linq; using System.Net; using System.Net.Sockets; @@ -413,7 +414,7 @@ public void UpdateChannelLastActiveTime(string globalChannelId) try { var channelIdString = globalChannelId.Substring(ListenerId.Length + 1); - var channelId = Convert.ToUInt32(channelIdString); + var channelId = Convert.ToUInt32(channelIdString, CultureInfo.InvariantCulture); TcpListenerChannel channel = null; if (channelId > 0 && diff --git a/Tests/Opc.Ua.Client.Tests/ContinuationPointInBatchTest.cs b/Tests/Opc.Ua.Client.Tests/ContinuationPointInBatchTest.cs index a31fd53998..bcfe7dd876 100644 --- a/Tests/Opc.Ua.Client.Tests/ContinuationPointInBatchTest.cs +++ b/Tests/Opc.Ua.Client.Tests/ContinuationPointInBatchTest.cs @@ -1073,7 +1073,7 @@ private void VerifyExpectedResults(List memoryLogPass, // get the part of the error message after the time stamp: string msg = s.Substring(s.IndexOf("ManagedBrowse")); // create error message from expected results - String expectedString = String.Format( + String expectedString = Utils.Format( "ManagedBrowse: in pass {0}, {1} {2} occured with a status code {3}.", pass, expectedResults.ExpectedNumberOfBadNoCPSCs[pass], diff --git a/Tests/Opc.Ua.Core.Tests/Stack/Buffers/ArraySegmentStreamTests.cs b/Tests/Opc.Ua.Core.Tests/Stack/Buffers/ArraySegmentStreamTests.cs index b6bcaca240..cad849eb72 100644 --- a/Tests/Opc.Ua.Core.Tests/Stack/Buffers/ArraySegmentStreamTests.cs +++ b/Tests/Opc.Ua.Core.Tests/Stack/Buffers/ArraySegmentStreamTests.cs @@ -205,6 +205,7 @@ public void ArraySegmentStreamWrite( Assert.That(position, Is.EqualTo(chunkSize * i)); } + int bytesRead; switch (random.Next(3)) { case 0: @@ -215,7 +216,8 @@ public void ArraySegmentStreamWrite( break; default: #if NET5_0_OR_GREATER - writer.Read(buffer.AsSpan(0, chunkSize)); + bytesRead = writer.Read(buffer.AsSpan(0, chunkSize)); + Assert.That(chunkSize, Is.EqualTo(bytesRead)); for (int v = 0; v < chunkSize; v++) { Assert.That(buffer[v], Is.EqualTo((byte)i)); @@ -223,7 +225,8 @@ public void ArraySegmentStreamWrite( break; #endif case 1: - writer.Read(buffer, 0, chunkSize); + bytesRead = writer.Read(buffer, 0, chunkSize); + Assert.That(chunkSize, Is.EqualTo(bytesRead)); for (int v = 0; v < chunkSize; v++) { Assert.That(buffer[v], Is.EqualTo((byte)i)); diff --git a/Tests/Opc.Ua.Core.Tests/Types/Utils/UtilsIsEqualTests.cs b/Tests/Opc.Ua.Core.Tests/Types/Utils/UtilsIsEqualTests.cs index 14339f59e7..5ad041136a 100644 --- a/Tests/Opc.Ua.Core.Tests/Types/Utils/UtilsIsEqualTests.cs +++ b/Tests/Opc.Ua.Core.Tests/Types/Utils/UtilsIsEqualTests.cs @@ -54,7 +54,7 @@ public class UtilsIsEqualTests [Params(32, 128, 1024, 4096, 65536)] public int PayLoadSize { get; set; } = 1024; - private bool _windows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); + private bool m_windows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); /// /// Test IsEqual using the generic IsEqual from previous versions. @@ -134,7 +134,7 @@ public bool ForLoopBinaryCompare() [Benchmark] public bool MemCmpByteArrayCompare() { - if (_windows) + if (m_windows) { // Validate buffers are the same length. // This also ensures that the count does not exceed the length of either buffer. diff --git a/Tests/Opc.Ua.PubSub.Tests/Encoding/MessagesHelper.cs b/Tests/Opc.Ua.PubSub.Tests/Encoding/MessagesHelper.cs index 066206140d..1c24470535 100644 --- a/Tests/Opc.Ua.PubSub.Tests/Encoding/MessagesHelper.cs +++ b/Tests/Opc.Ua.PubSub.Tests/Encoding/MessagesHelper.cs @@ -35,6 +35,7 @@ using System.ComponentModel; using System.Threading; using Opc.Ua.PubSub.PublishedData; +using System.Globalization; namespace Opc.Ua.PubSub.Tests.Encoding { @@ -2841,21 +2842,21 @@ public static void UpdateSnapshotData(UaPubSubApplication pubSubApplication, UIn DataValue boolToggle = pubSubApplication.DataStore.ReadPublishedDataItem(new NodeId("BoolToggle", namespaceIndexAllTypes), Attributes.Value); if (boolToggle.Value is bool) { - bool boolVal = Convert.ToBoolean(boolToggle.Value); + bool boolVal = Convert.ToBoolean(boolToggle.Value, CultureInfo.InvariantCulture); boolToggle.Value = !boolVal; pubSubApplication.DataStore.WritePublishedDataItem(new NodeId("BoolToggle", namespaceIndexAllTypes), Attributes.Value, boolToggle); } DataValue byteValue = pubSubApplication.DataStore.ReadPublishedDataItem(new NodeId("Byte", namespaceIndexAllTypes), Attributes.Value); if (byteValue.Value is byte) { - byte byteVal = Convert.ToByte(byteValue.Value); + byte byteVal = Convert.ToByte(byteValue.Value, CultureInfo.InvariantCulture); byteValue.Value = ++byteVal; pubSubApplication.DataStore.WritePublishedDataItem(new NodeId("Byte", namespaceIndexAllTypes), Attributes.Value, byteValue); } DataValue int16Value = pubSubApplication.DataStore.ReadPublishedDataItem(new NodeId("Int16", namespaceIndexAllTypes), Attributes.Value); if (int16Value.Value is Int16) { - Int16 int16Val = Convert.ToInt16(int16Value.Value); + Int16 int16Val = Convert.ToInt16(int16Value.Value, CultureInfo.InvariantCulture); int intIdentifier = int16Val; Interlocked.CompareExchange(ref intIdentifier, 0, Int16.MaxValue); int16Value.Value = (Int16)Interlocked.Increment(ref intIdentifier); @@ -2864,7 +2865,7 @@ public static void UpdateSnapshotData(UaPubSubApplication pubSubApplication, UIn DataValue int32Value = pubSubApplication.DataStore.ReadPublishedDataItem(new NodeId("Int32", namespaceIndexAllTypes), Attributes.Value); if (int32Value.Value is Int32) { - Int32 int32Val = Convert.ToInt32(int16Value.Value); + Int32 int32Val = Convert.ToInt32(int16Value.Value, CultureInfo.InvariantCulture); int intIdentifier = int32Val; Interlocked.CompareExchange(ref intIdentifier, 0, Int32.MaxValue); int32Value.Value = (Int32)Interlocked.Increment(ref intIdentifier); @@ -2873,7 +2874,7 @@ public static void UpdateSnapshotData(UaPubSubApplication pubSubApplication, UIn DataValue uInt16Value = pubSubApplication.DataStore.ReadPublishedDataItem(new NodeId("UInt16", namespaceIndexAllTypes), Attributes.Value); if (uInt16Value.Value is UInt16) { - UInt16 uInt16Val = Convert.ToUInt16(uInt16Value.Value); + UInt16 uInt16Val = Convert.ToUInt16(uInt16Value.Value, CultureInfo.InvariantCulture); int intIdentifier = uInt16Val; Interlocked.CompareExchange(ref intIdentifier, 0, UInt16.MaxValue); uInt16Value.Value = (UInt16)Interlocked.Increment(ref intIdentifier); @@ -2882,7 +2883,7 @@ public static void UpdateSnapshotData(UaPubSubApplication pubSubApplication, UIn DataValue uInt32Value = pubSubApplication.DataStore.ReadPublishedDataItem(new NodeId("UInt32", namespaceIndexAllTypes), Attributes.Value); if (uInt32Value.Value is UInt32) { - UInt32 uInt32Val = Convert.ToUInt32(uInt32Value.Value); + UInt32 uInt32Val = Convert.ToUInt32(uInt32Value.Value, CultureInfo.InvariantCulture); long longIdentifier = uInt32Val; Interlocked.CompareExchange(ref longIdentifier, 0, UInt32.MaxValue); uInt32Value.Value = (UInt32)Interlocked.Increment(ref longIdentifier); @@ -2891,7 +2892,7 @@ public static void UpdateSnapshotData(UaPubSubApplication pubSubApplication, UIn DataValue doubleValue = pubSubApplication.DataStore.ReadPublishedDataItem(new NodeId("Double", namespaceIndexAllTypes), Attributes.Value); if (doubleValue.Value is double) { - double doubleVal = Convert.ToDouble(doubleValue.Value); + double doubleVal = Convert.ToDouble(doubleValue.Value, CultureInfo.InvariantCulture); Interlocked.CompareExchange(ref doubleVal, 0, double.MaxValue); doubleValue.Value = ++doubleVal; pubSubApplication.DataStore.WritePublishedDataItem(new NodeId("Double", namespaceIndexAllTypes), Attributes.Value, doubleValue); diff --git a/Tests/Opc.Ua.PubSub.Tests/Transport/MqttPubSubConnectionTests.cs b/Tests/Opc.Ua.PubSub.Tests/Transport/MqttPubSubConnectionTests.cs index 8cd5d271ef..7cc541f3f6 100644 --- a/Tests/Opc.Ua.PubSub.Tests/Transport/MqttPubSubConnectionTests.cs +++ b/Tests/Opc.Ua.PubSub.Tests/Transport/MqttPubSubConnectionTests.cs @@ -79,7 +79,7 @@ public void ValidateMqttLocalPubSubConnectionWithUadp( //Arrange UInt16 writerGroupId = 1; - string mqttLocalBrokerUrl = string.Format(MqttUrlFormat, Utils.UriSchemeMqtt, "localhost"); + string mqttLocalBrokerUrl = Utils.Format(MqttUrlFormat, Utils.UriSchemeMqtt, "localhost"); ITransportProtocolConfiguration mqttConfiguration = new MqttClientProtocolConfiguration(version: EnumMqttProtocolVersion.V500); @@ -190,7 +190,7 @@ public void ValidateMqttLocalPubSubConnectionWithDeltaUadp( //Arrange UInt16 writerGroupId = 1; - string mqttLocalBrokerUrl = string.Format(MqttUrlFormat, Utils.UriSchemeMqtt, "localhost"); + string mqttLocalBrokerUrl = Utils.Format(MqttUrlFormat, Utils.UriSchemeMqtt, "localhost"); ITransportProtocolConfiguration mqttConfiguration = new MqttClientProtocolConfiguration(version: EnumMqttProtocolVersion.V500); @@ -326,7 +326,7 @@ public void ValidateMqttLocalPubSubConnectionWithJson( //Arrange UInt16 writerGroupId = 1; - string mqttLocalBrokerUrl = string.Format(MqttUrlFormat, Utils.UriSchemeMqtt, "localhost"); + string mqttLocalBrokerUrl = Utils.Format(MqttUrlFormat, Utils.UriSchemeMqtt, "localhost"); ITransportProtocolConfiguration mqttConfiguration = new MqttClientProtocolConfiguration(version: EnumMqttProtocolVersion.V500); @@ -452,7 +452,7 @@ public void ValidateMqttLocalPubSubConnectionWithDeltaJson( //Arrange UInt16 writerGroupId = 1; - string mqttLocalBrokerUrl = string.Format(MqttUrlFormat, Utils.UriSchemeMqtt, "localhost"); + string mqttLocalBrokerUrl = Utils.Format(MqttUrlFormat, Utils.UriSchemeMqtt, "localhost"); ITransportProtocolConfiguration mqttConfiguration = new MqttClientProtocolConfiguration(version: EnumMqttProtocolVersion.V500); diff --git a/Tests/Opc.Ua.Security.Certificates.Tests/CertificateTestsForECDsa.cs b/Tests/Opc.Ua.Security.Certificates.Tests/CertificateTestsForECDsa.cs index 767f96a233..85071c8de2 100644 --- a/Tests/Opc.Ua.Security.Certificates.Tests/CertificateTestsForECDsa.cs +++ b/Tests/Opc.Ua.Security.Certificates.Tests/CertificateTestsForECDsa.cs @@ -34,7 +34,7 @@ using System.Security.Cryptography.X509Certificates; using NUnit.Framework; using Opc.Ua.Tests; - using Assert = NUnit.Framework.Legacy.ClassicAssert; +using Assert = NUnit.Framework.Legacy.ClassicAssert; namespace Opc.Ua.Security.Certificates.Tests { @@ -95,7 +95,7 @@ public void VerifyOneSelfSignedAppCertForAll() .SetECCurve(eCCurveHash.Curve) .CreateForECDsa()) { - + Assert.NotNull(cert); WriteCertificate(cert, $"Default cert with ECDsa {eCCurveHash.Curve.Oid.FriendlyName} {eCCurveHash.HashAlgorithmName} signature."); Assert.AreEqual(eCCurveHash.HashAlgorithmName, Oids.GetHashAlgorithmName(cert.SignatureAlgorithm.Value)); @@ -109,7 +109,7 @@ public void VerifyOneSelfSignedAppCertForAll() } /// - /// Create the default RSA certificate. + /// Create the default ECDsa certificate. /// [Theory, Repeat(10)] public void CreateSelfSignedForECDsaDefaultTest(ECCurveHashPair eccurveHashPair) @@ -355,13 +355,33 @@ private static ECCurveHashPair[] GetECCurveHashPairs() { var result = new ECCurveHashPairCollection { { ECCurve.NamedCurves.nistP256, HashAlgorithmName.SHA256 }, - { ECCurve.NamedCurves.nistP384, HashAlgorithmName.SHA384 } }; - if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) - { - result.AddRange(new ECCurveHashPairCollection { + { ECCurve.NamedCurves.nistP384, HashAlgorithmName.SHA384 }, { ECCurve.NamedCurves.brainpoolP256r1, HashAlgorithmName.SHA256 }, - { ECCurve.NamedCurves.brainpoolP384r1, HashAlgorithmName.SHA384 }}); + { ECCurve.NamedCurves.brainpoolP384r1, HashAlgorithmName.SHA384 } + }; + + int i = 0; + while (i < result.Count) + { + ECDsa key = null; + + // test if curve is supported + try + { + key = ECDsa.Create(result[i].Curve); + } + catch + { + result.RemoveAt(i); + continue; + } + finally + { + Utils.SilentDispose(key); + } + i++; } + return result.ToArray(); } diff --git a/common.props b/common.props index 755327f6f9..c80f958047 100644 --- a/common.props +++ b/common.props @@ -5,6 +5,7 @@ 1.05.374 preview-$([System.DateTime]::Now.ToString("yyyyMMdd")) Copyright © 2004-2024 OPC Foundation, Inc + OPCFoundation.NetStandard OPC Foundation OPC Foundation NU5125;CA2254;CA1307