From 6489c1283fc77ec9bb5f1bfda652abe4a449a0a2 Mon Sep 17 00:00:00 2001 From: Suciu Mircea Adrian Date: Thu, 19 Dec 2024 09:04:20 +0200 Subject: [PATCH] Removed unreachable code (#2916) --- .../Encoding/UadpNetworkMessage.cs | 2 +- .../Certificates/CertificateIdentifier.cs | 19 ------------------- .../Security/Certificates/EccUtils.cs | 16 +++++++++------- .../Security/Constants/SecurityPolicies.cs | 5 ----- 4 files changed, 10 insertions(+), 32 deletions(-) diff --git a/Libraries/Opc.Ua.PubSub/Encoding/UadpNetworkMessage.cs b/Libraries/Opc.Ua.PubSub/Encoding/UadpNetworkMessage.cs index 970601b5e4..be03543c2c 100644 --- a/Libraries/Opc.Ua.PubSub/Encoding/UadpNetworkMessage.cs +++ b/Libraries/Opc.Ua.PubSub/Encoding/UadpNetworkMessage.cs @@ -117,7 +117,7 @@ public UadpNetworkMessage(UADPNetworkMessageDiscoveryType discoveryType) /// Create new instance of as a DiscoveryResponse of PublisherEndpoints type /// /// - /// + /// public UadpNetworkMessage(EndpointDescription[] publisherEndpoints, StatusCode publisherProvidesEndpoints) : base(null, new List()) { diff --git a/Stack/Opc.Ua.Core/Security/Certificates/CertificateIdentifier.cs b/Stack/Opc.Ua.Core/Security/Certificates/CertificateIdentifier.cs index 0ad4f52623..3e1399c0f5 100644 --- a/Stack/Opc.Ua.Core/Security/Certificates/CertificateIdentifier.cs +++ b/Stack/Opc.Ua.Core/Security/Certificates/CertificateIdentifier.cs @@ -12,8 +12,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. using System; using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; using System.Text; @@ -243,20 +241,6 @@ public async Task Find(bool needPrivateKey) return certificate; } - /// - /// Updates the object from another object (usage is not updated). - /// - /// The certificate. - private void Paste(CertificateIdentifier certificate) - { - this.SubjectName = certificate.SubjectName; - this.Thumbprint = certificate.Thumbprint; - this.RawData = certificate.RawData; - this.ValidationOptions = certificate.ValidationOptions; - this.Certificate = certificate.Certificate; - this.CertificateType = certificate.CertificateType; - } - /// /// Returns a display name for a certificate. /// @@ -528,9 +512,6 @@ public ushort GetMinKeySize(SecurityConfiguration securityConfiguration) // non RSA return 0; } - - throw new ArgumentException("Certificate type is unknown"); - } diff --git a/Stack/Opc.Ua.Core/Security/Certificates/EccUtils.cs b/Stack/Opc.Ua.Core/Security/Certificates/EccUtils.cs index 17d6e9f673..d01c4d27dd 100644 --- a/Stack/Opc.Ua.Core/Security/Certificates/EccUtils.cs +++ b/Stack/Opc.Ua.Core/Security/Certificates/EccUtils.cs @@ -181,8 +181,7 @@ public static string GetECDsaQualifier(X509Certificate2 certificate) /// public static ECDsa GetPublicKey(X509Certificate2 certificate) { - string[] securityPolicyUris; - return GetPublicKey(certificate, out securityPolicyUris); + return GetPublicKey(certificate, out string[] _); } /// @@ -195,14 +194,19 @@ public static ECDsa GetPublicKey(X509Certificate2 certificate, out string[] secu { securityPolicyUris = null; + if (certificate == null) + { + return null; + } + var keyAlgorithm = certificate.GetKeyAlgorithm(); - if (certificate == null || keyAlgorithm != Oids.ECPublicKey) + if (keyAlgorithm != Oids.ECPublicKey) { return null; } - const X509KeyUsageFlags SufficientFlags = + const X509KeyUsageFlags kSufficientFlags = X509KeyUsageFlags.KeyAgreement | X509KeyUsageFlags.DigitalSignature | X509KeyUsageFlags.NonRepudiation | @@ -215,7 +219,7 @@ public static ECDsa GetPublicKey(X509Certificate2 certificate, out string[] secu { X509KeyUsageExtension kuExt = (X509KeyUsageExtension)extension; - if ((kuExt.KeyUsages & SufficientFlags) == 0) + if ((kuExt.KeyUsages & kSufficientFlags) == 0) { return null; } @@ -302,8 +306,6 @@ public static int GetSignatureLength(X509Certificate2 signingCertificate) return publicKey.KeySize / 4; } - - throw new NotImplementedException(); } /// diff --git a/Stack/Opc.Ua.Core/Security/Constants/SecurityPolicies.cs b/Stack/Opc.Ua.Core/Security/Constants/SecurityPolicies.cs index f3a55fa0d0..6e22449dd4 100644 --- a/Stack/Opc.Ua.Core/Security/Constants/SecurityPolicies.cs +++ b/Stack/Opc.Ua.Core/Security/Constants/SecurityPolicies.cs @@ -621,11 +621,6 @@ public static bool Verify(X509Certificate2 certificate, string securityPolicyUri securityPolicyUri); } } - - throw ServiceResultException.Create( - StatusCodes.BadSecurityChecksFailed, - "Unexpected security policy Uri: {0}", - securityPolicyUri); } #endregion }