Skip to content

Commit 59cd0ff

Browse files
Fix all warnings in the driver project (#898)
* Fix all warnings in the driver project * Fix null notifications
1 parent c0340c5 commit 59cd0ff

File tree

18 files changed

+92
-15
lines changed

18 files changed

+92
-15
lines changed

Neo4j.Driver/Neo4j.Driver.Tests/Neo4j.Driver.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<GenerateAssemblyFileVersionAttribute>true</GenerateAssemblyFileVersionAttribute>
1515
<LangVersion>default</LangVersion>
1616
<Platforms>AnyCPU</Platforms>
17-
<TargetFramework>net10.0</TargetFramework>
17+
<TargetFrameworks>net10.0;net8.0;net9.0</TargetFrameworks>
1818
</PropertyGroup>
1919
<PropertyGroup Condition=" '$(Configuration)' == 'CI' ">
2020
<Optimize Condition=" '$(Optimize)' == '' ">true</Optimize>

Neo4j.Driver/Neo4j.Driver/Internal/Auth/DefaultTlsNegotiator.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ internal sealed class DefaultTlsNegotiator : ITlsNegotiator
2424
{
2525
private readonly EncryptionManager _encryptionManager;
2626
private readonly INeo4jLogger _neo4JLogger;
27+
private readonly IInternalX509CertificateLoader _internalX509CertificateLoader
28+
= new InternalX509CertificateLoader();
2729

2830
public DefaultTlsNegotiator(INeo4jLogger neo4JLogger, EncryptionManager encryptionManager)
2931
{
@@ -45,9 +47,10 @@ public SslStream NegotiateTls(Uri uri, Stream stream)
4547
return false;
4648
}
4749

50+
var certData = certificate!.Export(X509ContentType.Cert);
4851
var trust = _encryptionManager.TrustManager.ValidateServerCertificate(
4952
uri,
50-
new X509Certificate2(certificate.Export(X509ContentType.Cert)),
53+
_internalX509CertificateLoader.LoadCertificate(certData),
5154
chain,
5255
errors);
5356

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright (c) "Neo4j"
2+
// Neo4j Sweden AB [https://neo4j.com]
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License").
5+
// You may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
using System.Security.Cryptography.X509Certificates;
17+
18+
namespace Neo4j.Driver.Internal.Auth;
19+
20+
internal interface IInternalX509CertificateLoader
21+
{
22+
X509Certificate2 LoadCertificate(byte[] rawData);
23+
X509Certificate2 LoadCertificate(string filename);
24+
}
25+
26+
// this class is to hide away the conditional compilation for .NET >= 9
27+
internal class InternalX509CertificateLoader : IInternalX509CertificateLoader
28+
{
29+
public X509Certificate2 LoadCertificate(byte[] rawData)
30+
{
31+
#if NET9_0_OR_GREATER
32+
return X509CertificateLoader.LoadCertificate(rawData);
33+
#else
34+
return new X509Certificate2(rawData);
35+
#endif
36+
}
37+
38+
public X509Certificate2 LoadCertificate(string filename)
39+
{
40+
#if NET9_0_OR_GREATER
41+
return X509CertificateLoader.LoadCertificateFromFile(filename);
42+
#else
43+
return new X509Certificate2(filename);
44+
#endif
45+
}
46+
}

Neo4j.Driver/Neo4j.Driver/Internal/ExceptionHandling/Neo4jExceptionFactory.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ Neo4jException Factory(FailureMessage message, Exception inner)
105105
public Neo4jException GetException(FailureMessage failureMessage)
106106
{
107107
var factoryInfo =
108-
_exceptionFactories.FirstOrDefault(f => _simpleWildcardHelper.StringMatches(failureMessage.Code, f.Code));
108+
_exceptionFactories.FirstOrDefault(
109+
f => _simpleWildcardHelper.StringMatches(failureMessage.CodeInternal, f.Code));
109110

110111
if (factoryInfo is null)
111112
{

Neo4j.Driver/Neo4j.Driver/Internal/GqlCompliance/GqlErrors.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ internal static class GqlErrors
3232

3333
public static void FillGqlDefaults(FailureMessage message)
3434
{
35-
message.Code ??= UnknownNeo4JCode;
35+
message.CodeInternal ??= UnknownNeo4JCode;
3636
message.Message ??= UnknownMessage;
3737
message.GqlStatus ??= UnknownGqlStatus;
3838

Neo4j.Driver/Neo4j.Driver/Internal/IO/MessageSerializers/FailureMessageSerializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ internal static FailureMessage BuildFailureMessage(IReadOnlyDictionary<string, o
5656
{
5757
case "neo4j_code":
5858
case "code":
59-
response.Code = FixCodeForBolt5(majorVersion, value?.ToString() ?? string.Empty);
59+
response.CodeInternal = FixCodeForBolt5(majorVersion, value?.ToString() ?? string.Empty);
6060
break;
6161

6262
case "message":

Neo4j.Driver/Neo4j.Driver/Internal/IO/PackStreamBitConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public static byte[] GetBytes(long value)
7777

7878
/// <summary>Converts a float (Float32) to bytes.</summary>
7979
/// <param name="value">The float (Float32) value to convert.</param>
80-
/// <returns>The specified float (Float32) value as an array of bytes.</returns
80+
/// <returns>The specified float (Float32) value as an array of bytes.</returns>
8181
public static byte[] GetBytes(float value)
8282
{
8383
var bytes = BitConverter.GetBytes(value);

Neo4j.Driver/Neo4j.Driver/Internal/MessageHandling/Metadata/GqlStatusObjectsAndNotifications.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
namespace Neo4j.Driver.Internal.MessageHandling.Metadata;
2222

2323
internal sealed record GqlStatusObjectsAndNotifications(
24-
IList<INotification> Notifications,
24+
IList<Notification> Notifications,
2525
IList<IGqlStatusObject> GqlStatusObjects,
2626
bool UseRawStatuses)
2727
{
@@ -62,7 +62,7 @@ private static string GetStatusOrderingValue(IGqlStatusObject x)
6262
return status?.Length > 1 ? status.Substring(0, 2) : "";
6363
}
6464

65-
public IList<INotification> FinalizeNotifications(CursorMetadata cursorMetadata)
65+
public IList<Notification> FinalizeNotifications(CursorMetadata cursorMetadata)
6666
{
6767
return Notifications;
6868
}

Neo4j.Driver/Neo4j.Driver/Internal/MessageHandling/Metadata/GqlStatusObjectsAndNotificationsCollector.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private static IList<T> ConvertObjects<T>(
7171
return null;
7272
}
7373

74-
private static INotification ConvertNotification(IDictionary<string, object> notification)
74+
private static Notification ConvertNotification(IDictionary<string, object> notification)
7575
{
7676
var code = notification.GetValue("code", string.Empty);
7777
var title = notification.GetValue("title", string.Empty);
@@ -160,7 +160,7 @@ private static IGqlStatusObject ConvertNotificationValuesToStatus(IDictionary<st
160160
!string.IsNullOrEmpty(code));
161161
}
162162

163-
private static INotification ConvertStatusValuesToNotification(IDictionary<string, object> gqlStatus)
163+
private static Notification ConvertStatusValuesToNotification(IDictionary<string, object> gqlStatus)
164164
{
165165
var code = gqlStatus.GetValue<string>("neo4j_code", null);
166166
if (code == null)

Neo4j.Driver/Neo4j.Driver/Internal/MessageHandling/ResponsePipeline.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void OnRecord(object[] fieldValues)
8181

8282
public void OnFailure(FailureMessage failureMessage)
8383
{
84-
LogFailure(failureMessage.Code, failureMessage.Message);
84+
LogFailure(failureMessage.CodeInternal, failureMessage.Message);
8585
var handler = Dequeue();
8686
_error = new ResponsePipelineError(ErrorExtensions.ParseServerException(failureMessage));
8787
handler.OnFailure(_error);

0 commit comments

Comments
 (0)