Skip to content

Commit b255184

Browse files
committed
NuGet governance assessment: add Directory.Build.props, Directory.Packages.props, CI/CD, update SDK and dependencies, fix Codacy issues
1 parent 471bd00 commit b255184

18 files changed

Lines changed: 213 additions & 84 deletions

File tree

.github/workflows/ci.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
16+
17+
- name: Setup .NET
18+
uses: actions/setup-dotnet@v4
19+
with:
20+
dotnet-version: '10.0.x'
21+
22+
- name: Restore dependencies
23+
run: dotnet restore
24+
25+
- name: Build
26+
run: dotnet build --no-restore --configuration Release
27+
28+
- name: Test
29+
run: dotnet test --no-build --configuration Release --verbosity normal

Directory.Build.props

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project>
2+
<PropertyGroup>
3+
<Company>Panoramic Data Limited</Company>
4+
<Authors>Panoramic Data Limited</Authors>
5+
<Copyright>Copyright © $([System.DateTime]::Now.Year) Panoramic Data Limited</Copyright>
6+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
7+
<Nullable>enable</Nullable>
8+
<NuGetAuditMode>All</NuGetAuditMode>
9+
<!-- Nullable warnings kept as warnings (not errors) for gradual adoption in existing codebase -->
10+
<WarningsNotAsErrors>$(WarningsNotAsErrors);CS8600;CS8601;CS8602;CS8603;CS8604;CS8610;CS8618;CS8619;CS8620;CS8622;CS8625;CS8631;CS8634;CS8714;CS8765;CS8767</WarningsNotAsErrors>
11+
</PropertyGroup>
12+
</Project>

Directory.Packages.props

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project>
2+
<PropertyGroup>
3+
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
4+
</PropertyGroup>
5+
<ItemGroup>
6+
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="10.0.5" />
7+
<PackageVersion Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="10.0.5" />
8+
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="10.0.5" />
9+
<PackageVersion Include="Microsoft.Extensions.Configuration.UserSecrets" Version="10.0.5" />
10+
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="10.0.5" />
11+
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.5" />
12+
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="10.0.5" />
13+
<PackageVersion Include="Nerdbank.GitVersioning" Version="3.9.50" />
14+
</ItemGroup>
15+
</Project>

LICENSE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
The MIT License (MIT)
22

33
Copyright (c) 2021 Aimeast
4+
Copyright (c) 2024 Panoramic Data Limited
45

56
Permission is hereby granted, free of charge, to any person obtaining a copy
67
of this software and associated documentation files (the "Software"), to deal

PanoramicData.SshServer.Test/CommandService.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ namespace ExampleApp;
77

88
public class CommandService
99
{
10-
private Process _process = null;
11-
private ProcessStartInfo _startInfo = null;
10+
private Process? _process;
11+
private readonly ProcessStartInfo _startInfo;
1212

1313
public CommandService(string command, string args)
1414
{
@@ -22,13 +22,14 @@ public CommandService(string command, string args)
2222
};
2323
}
2424

25-
public event EventHandler<byte[]> DataReceived;
26-
public event EventHandler EofReceived;
27-
public event EventHandler<uint> CloseReceived;
25+
public event EventHandler<byte[]>? DataReceived;
26+
public event EventHandler? EofReceived;
27+
public event EventHandler<uint>? CloseReceived;
2828

2929
public void Start()
3030
{
31-
_process = Process.Start(_startInfo);
31+
_process = Process.Start(_startInfo)
32+
?? throw new InvalidOperationException("Failed to start process.");
3233
Task.Run(() => MessageLoop());
3334
}
3435

PanoramicData.SshServer.Test/ExampleApp.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.1" />
10-
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="10.0.1" />
11-
<PackageReference Include="Microsoft.Extensions.Configuration" Version="10.0.1" />
12-
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="10.0.1" />
13-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="10.0.1" />
14-
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="10.0.1" />
9+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" />
10+
<PackageReference Include="Microsoft.Extensions.Logging.Console" />
11+
<PackageReference Include="Microsoft.Extensions.Configuration" />
12+
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" />
13+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" />
14+
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" />
1515
</ItemGroup>
1616

1717
<ItemGroup>

PanoramicData.SshServer.Test/MiniTerm/Native/ProcessApi.cs

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Runtime.InteropServices;
1+
using System;
2+
using System.Runtime.InteropServices;
23

34
namespace ExampleApp.MiniTerm.Native;
45

@@ -10,10 +11,21 @@ static class ProcessApi
1011
internal const uint EXTENDED_STARTUPINFO_PRESENT = 0x00080000;
1112

1213
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
13-
internal struct STARTUPINFOEX
14+
internal struct STARTUPINFOEX : IEquatable<STARTUPINFOEX>
1415
{
1516
public STARTUPINFO StartupInfo;
1617
public nint lpAttributeList;
18+
19+
public readonly bool Equals(STARTUPINFOEX other) =>
20+
StartupInfo.Equals(other.StartupInfo) && lpAttributeList == other.lpAttributeList;
21+
22+
public override readonly bool Equals(object? obj) => obj is STARTUPINFOEX other && Equals(other);
23+
24+
public override readonly int GetHashCode() => HashCode.Combine(StartupInfo, lpAttributeList);
25+
26+
public static bool operator ==(STARTUPINFOEX left, STARTUPINFOEX right) => left.Equals(right);
27+
28+
public static bool operator !=(STARTUPINFOEX left, STARTUPINFOEX right) => !left.Equals(right);
1729
}
1830

1931
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
@@ -40,20 +52,44 @@ internal struct STARTUPINFO
4052
}
4153

4254
[StructLayout(LayoutKind.Sequential)]
43-
internal struct PROCESS_INFORMATION
55+
internal struct PROCESS_INFORMATION : IEquatable<PROCESS_INFORMATION>
4456
{
4557
public nint hProcess;
4658
public nint hThread;
4759
public int dwProcessId;
4860
public int dwThreadId;
61+
62+
public readonly bool Equals(PROCESS_INFORMATION other) =>
63+
hProcess == other.hProcess && hThread == other.hThread &&
64+
dwProcessId == other.dwProcessId && dwThreadId == other.dwThreadId;
65+
66+
public override readonly bool Equals(object? obj) => obj is PROCESS_INFORMATION other && Equals(other);
67+
68+
public override readonly int GetHashCode() => HashCode.Combine(hProcess, hThread, dwProcessId, dwThreadId);
69+
70+
public static bool operator ==(PROCESS_INFORMATION left, PROCESS_INFORMATION right) => left.Equals(right);
71+
72+
public static bool operator !=(PROCESS_INFORMATION left, PROCESS_INFORMATION right) => !left.Equals(right);
4973
}
5074

5175
[StructLayout(LayoutKind.Sequential)]
52-
internal struct SECURITY_ATTRIBUTES
76+
internal struct SECURITY_ATTRIBUTES : IEquatable<SECURITY_ATTRIBUTES>
5377
{
5478
public int nLength;
5579
public nint lpSecurityDescriptor;
5680
public int bInheritHandle;
81+
82+
public readonly bool Equals(SECURITY_ATTRIBUTES other) =>
83+
nLength == other.nLength && lpSecurityDescriptor == other.lpSecurityDescriptor &&
84+
bInheritHandle == other.bInheritHandle;
85+
86+
public override readonly bool Equals(object? obj) => obj is SECURITY_ATTRIBUTES other && Equals(other);
87+
88+
public override readonly int GetHashCode() => HashCode.Combine(nLength, lpSecurityDescriptor, bInheritHandle);
89+
90+
public static bool operator ==(SECURITY_ATTRIBUTES left, SECURITY_ATTRIBUTES right) => left.Equals(right);
91+
92+
public static bool operator !=(SECURITY_ATTRIBUTES left, SECURITY_ATTRIBUTES right) => !left.Equals(right);
5793
}
5894

5995
[DllImport("kernel32.dll", SetLastError = true)]

PanoramicData.SshServer.Test/MiniTerm/Program.cs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,6 @@
1414
/// Terminal UI starts the PseudoConsole, and controls it using a pair of PseudoConsolePipes
1515
/// Terminal UI will run the Process (cmd.exe) and associate it with the PseudoConsole.
1616
/// </remarks>
17-
//static class Program
18-
//{
19-
// static void Main(string[] args)
20-
// {
21-
// try
22-
// {
23-
// var terminal = new Terminal();
24-
// terminal.Run("cmd.exe");
25-
// }
26-
// catch (InvalidOperationException e)
27-
// {
28-
// Console.Error.WriteLine(e.Message);
29-
// throw;
30-
// }
31-
// }
32-
//}
17+
static class Program
18+
{
19+
}

PanoramicData.SshServer.Test/MiniTerm/Terminal.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ public Terminal(string command, uint windowWidth, uint windowHeight)
3030
_reader = new FileStream(_outputPipe.ReadSide, FileAccess.Read);
3131
}
3232

33-
public event EventHandler<byte[]> DataReceived;
34-
public event EventHandler<uint> CloseReceived;
33+
public event EventHandler<byte[]>? DataReceived;
34+
public event EventHandler<uint>? CloseReceived;
3535

3636
/// <summary>
3737
/// Start the pseudo console and run the process as shown in
@@ -48,7 +48,10 @@ public void Run() =>
4848
{
4949
var length = _reader.Read(buf, 0, buf.Length);
5050
if (length == 0)
51+
{
5152
break;
53+
}
54+
5255
DataReceived?.Invoke(this, buf.Take(length).ToArray());
5356
}
5457

@@ -89,6 +92,5 @@ public void Dispose()
8992
{
9093
// Do not change this code. Put clean-up code in 'Dispose(bool disposing)' method
9194
Dispose(disposing: true);
92-
GC.SuppressFinalize(this);
9395
}
9496
}

PanoramicData.SshServer/Algorithms/CtrModeCryptoTransform.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Diagnostics.Contracts;
1+
using System;
2+
using System.Diagnostics.Contracts;
23
using System.Security.Cryptography;
34

45
namespace PanoramicData.SshServer.Algorithms;
@@ -13,8 +14,9 @@ public class CtrModeCryptoTransform : ICryptoTransform
1314

1415
public CtrModeCryptoTransform(SymmetricAlgorithm algorithm)
1516
{
16-
Contract.Requires(algorithm != null);
17+
ArgumentNullException.ThrowIfNull(algorithm);
1718

19+
// ECB mode is intentionally used here as the base cipher for CTR mode implementation
1820
algorithm.Mode = CipherMode.ECB;
1921
algorithm.Padding = PaddingMode.None;
2022

@@ -42,10 +44,15 @@ public int TransformBlock(byte[] inputBuffer, int inputOffset, int inputCount, b
4244
written += _transform.TransformBlock(_iv, 0, bytesPerBlock, _block, 0);
4345

4446
for (var j = 0; j < bytesPerBlock; j++)
47+
{
4548
outputBuffer[outputOffset + i + j] = (byte)(_block[j] ^ inputBuffer[inputOffset + i + j]);
49+
}
4650

4751
var k = _iv.Length;
48-
while (--k >= 0 && ++_iv[k] == 0) ;
52+
while (--k >= 0 && ++_iv[k] == 0)
53+
{
54+
// Increment IV counter with carry propagation
55+
}
4956
}
5057

5158
return written;

0 commit comments

Comments
 (0)