Skip to content

Commit 2f0bdd1

Browse files
authored
Some leftover cleanup for removin net6.0 (npgsql#5949)
Part of npgsql#5946
1 parent b0dde48 commit 2f0bdd1

File tree

7 files changed

+1
-58
lines changed

7 files changed

+1
-58
lines changed

src/Npgsql/Internal/Converters/Primitive/GuidUuidConverter.cs

-26
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,4 @@ protected override void WriteCore(PgWriter writer, Guid value)
2121
value.TryWriteBytes(bytes, bigEndian: true, out _);
2222
writer.WriteBytes(bytes);
2323
}
24-
25-
#if !NET8_0_OR_GREATER
26-
// The following table shows .NET GUID vs Postgres UUID (RFC 4122) layouts.
27-
//
28-
// Note that the first fields are converted from/to native endianness (handled by the Read*
29-
// and Write* methods), while the last field is always read/written in big-endian format.
30-
//
31-
// We're reverting endianness on little endian systems to get it into big endian format.
32-
//
33-
// | Bits | Bytes | Name | Endianness (GUID) | Endianness (RFC 4122) |
34-
// | ---- | ----- | ----- | ----------------- | --------------------- |
35-
// | 32 | 4 | Data1 | Native | Big |
36-
// | 16 | 2 | Data2 | Native | Big |
37-
// | 16 | 2 | Data3 | Native | Big |
38-
// | 64 | 8 | Data4 | Big | Big |
39-
[StructLayout(LayoutKind.Explicit)]
40-
struct GuidRaw
41-
{
42-
[FieldOffset(0)] public Guid Value;
43-
[FieldOffset(0)] public int Data1;
44-
[FieldOffset(4)] public short Data2;
45-
[FieldOffset(6)] public short Data3;
46-
[FieldOffset(8)] public long Data4;
47-
public GuidRaw(Guid value) : this() => Value = value;
48-
}
49-
#endif
5024
}

src/Npgsql/Internal/NpgsqlConnector.Auth.cs

+1-15
Original file line numberDiff line numberDiff line change
@@ -255,17 +255,7 @@ static byte[] Xor(byte[] buffer1, byte[] buffer2)
255255
return buffer1;
256256
}
257257

258-
static byte[] HMAC(byte[] key, string data)
259-
{
260-
var dataBytes = Encoding.UTF8.GetBytes(data);
261-
#if NET7_0_OR_GREATER
262-
return HMACSHA256.HashData(key, dataBytes);
263-
#else
264-
using var ih = IncrementalHash.CreateHMAC(HashAlgorithmName.SHA256, key);
265-
ih.AppendData(dataBytes);
266-
return ih.GetHashAndReset();
267-
#endif
268-
}
258+
static byte[] HMAC(byte[] key, string data) => HMACSHA256.HashData(key, Encoding.UTF8.GetBytes(data));
269259

270260
async Task AuthenticateMD5(string username, byte[] salt, bool async, CancellationToken cancellationToken = default)
271261
{
@@ -298,11 +288,7 @@ async Task AuthenticateMD5(string username, byte[] salt, bool async, Cancellatio
298288
prehashbytes.CopyTo(cryptBuf, 0);
299289

300290
sb = new StringBuilder("md5");
301-
#if NET7_0_OR_GREATER
302291
hashResult = MD5.HashData(cryptBuf);
303-
#else
304-
hashResult = md5.ComputeHash(cryptBuf);
305-
#endif
306292
foreach (var b in hashResult)
307293
sb.Append(b.ToString("x2"));
308294

src/Npgsql/Internal/NpgsqlConnector.cs

-3
Original file line numberDiff line numberDiff line change
@@ -392,10 +392,7 @@ internal NpgsqlConnector(NpgsqlDataSource dataSource, NpgsqlConnection conn)
392392
CopyLogger = LoggingConfiguration.CopyLogger;
393393

394394
SslClientAuthenticationOptionsCallback = dataSource.SslClientAuthenticationOptionsCallback;
395-
396-
#if NET7_0_OR_GREATER
397395
NegotiateOptionsCallback = dataSource.Configuration.NegotiateOptionsCallback;
398-
#endif
399396

400397
State = ConnectorState.Closed;
401398
TransactionStatus = TransactionStatus.Idle;

src/Npgsql/Internal/ResolverFactories/NetworkTypeInfoResolverFactory.cs

-3
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,7 @@ static TypeInfoMappingCollection AddMappings(TypeInfoMappingCollection mappings)
7878

7979
// cidr
8080
mappings.AddStructArrayType<NpgsqlCidr>(DataTypeNames.Cidr);
81-
82-
#if NET8_0_OR_GREATER
8381
mappings.AddStructArrayType<IPNetwork>(DataTypeNames.Cidr);
84-
#endif
8582

8683
return mappings;
8784
}

src/Npgsql/MetricsReporter.cs

-7
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,4 @@ public void Dispose()
242242
Reporters.Remove(this);
243243
}
244244
}
245-
246-
#if !NET7_0_OR_GREATER
247-
const long TicksPerMicrosecond = 10;
248-
const long TicksPerMillisecond = TicksPerMicrosecond * 1000;
249-
const long TicksPerSecond = TicksPerMillisecond * 1000; // 10,000,000
250-
static readonly double StopWatchTickFrequency = (double)TicksPerSecond / Stopwatch.Frequency;
251-
#endif
252245
}

src/Npgsql/NpgsqlSlimDataSourceBuilder.cs

-2
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,6 @@ public NpgsqlSlimDataSourceBuilder UsePasswordProvider(
341341
return this;
342342
}
343343

344-
#if NET7_0_OR_GREATER
345344
/// <summary>
346345
/// When using Kerberos, this is a callback that allows customizing default settings for Kerberos authentication.
347346
/// </summary>
@@ -358,7 +357,6 @@ public NpgsqlSlimDataSourceBuilder UseNegotiateOptionsCallback(Action<NegotiateA
358357

359358
return this;
360359
}
361-
#endif
362360

363361
#endregion Authentication
364362

src/Npgsql/PostgresException.cs

-2
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,7 @@ internal PostgresException(SerializationInfo info, StreamingContext context)
141141
/// </summary>
142142
/// <param name="info">The <see cref="SerializationInfo"/> to populate with data.</param>
143143
/// <param name="context">The destination (see <see cref="StreamingContext"/>) for this serialization.</param>
144-
#if NET8_0_OR_GREATER
145144
[Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.")]
146-
#endif
147145
public override void GetObjectData(SerializationInfo info, StreamingContext context)
148146
{
149147
base.GetObjectData(info, context);

0 commit comments

Comments
 (0)