Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/instructions/snyk_rules.instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
alwaysApply: true
always_on: true
trigger: always_on
applyTo: "**"
description: Snyk Security At Inception
---

# Project security best practices

- Always run snyk_code_scan tool for new first party code that is generated in a Snyk-supported language.
- If any security issues are found based on newly introduced or modified code or dependencies, attempt to fix the issues using the results context from Snyk.
- Rescan the code after fixing the issues to ensure that the issues were fixed and that there are no newly introduced issues.
- Repeat this process until no new issues are found.
26 changes: 26 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project>
<!-- Shared Version Properties -->
<PropertyGroup>
<Authors>Hideki Saito</Authors>
<Company>Hideki Saito</Company>
<Copyright>Copyright (c) 2025 Hideki Saito</Copyright>
<PackageLicenseUrl>https://github.com/hsaito/MyNumber.NET/blob/master/LICENSE</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/hsaito/MyNumber.NET</PackageProjectUrl>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<!-- Library Versions -->
<PropertyGroup>
<MyNumberNETVersion>1.0.7.0</MyNumberNETVersion>
<MyNumberNETCliVersion>1.0.7.0</MyNumberNETCliVersion>
<MyNumberNETTestVersion>1.0.7.0</MyNumberNETTestVersion>
</PropertyGroup>

<!-- Build Properties -->
<PropertyGroup>
<Deterministic>true</Deterministic>
<DeterministicSourceRoot>/_/</DeterministicSourceRoot>
<RepoRoot>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)'))</RepoRoot>
<PathMap>$(RepoRoot)=$(DeterministicSourceRoot)</PathMap>
</PropertyGroup>
</Project>
13 changes: 4 additions & 9 deletions MyNumberNET/MyNumber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,13 @@ public static int CalculateCheckDigits(int[] number)
throw new MyNumberMalformedException("Malformed sequence. Must be 11 digits.");
if (Array.Exists(number, n => n < 0 || n > 9))
throw new MyNumberMalformedException("All digits must be between 0 and 9.");

// Calculate check digit using the official My Number algorithm
// Process digits from right to left with specific weights
// Array indexing: number[11-n] safely accesses indices 10,9,8,...,0 for n=1,2,3,...,11
// This avoids Array.Reverse() while maintaining correct algorithm behavior
Array.Reverse(number);
var sum = 0;
// First loop: rightmost 6 digits (indices 10,9,8,7,6,5) with weights 2,3,4,5,6,7
for (var n = 1; n < 7; n++)
sum += (n + 1) * number[11 - n];
// Second loop: leftmost 5 digits (indices 4,3,2,1,0) with weights 2,3,4,5,6
sum += (n + 1) * number[n - 1];
for (var n = 7; n < 12; n++)
sum += (n - 5) * number[11 - n];
sum += (n - 5) * number[n - 1];
Array.Reverse(number);
if (sum % 11 <= 1)
return 0;
return 11 - sum % 11;
Expand Down
19 changes: 3 additions & 16 deletions MyNumberNET/MyNumberNET.csproj
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Authors>Hideki Saito</Authors>
<Company>Hideki Saito</Company>
<Title>MyNumberNET My Number Validation Library</Title>
<Product>MyNumberNET</Product>
<PackageId>MyNumberNET</PackageId>
<Description>My Number for .NET (Library)</Description>
<Copyright>Copyright (c) 2019 Hideki Saito</Copyright>
<PackageLicenseUrl>https://github.com/hsaito/MyNumber.NET/blob/master/LICENSE</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/hsaito/MyNumber.NET</PackageProjectUrl>
<Version>1.0.6.0</Version>
<AssemblyVersion>1.0.6.0</AssemblyVersion>
<FileVersion>1.0.6.0</FileVersion>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<PropertyGroup>
<Deterministic>true</Deterministic>
<DeterministicSourceRoot>/_/</DeterministicSourceRoot>
<RepoRoot>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\..\'))</RepoRoot>
<PathMap>$(RepoRoot)=$(DeterministicSourceRoot)</PathMap>
<Version>$(MyNumberNETVersion)</Version>
<AssemblyVersion>$(MyNumberNETVersion)</AssemblyVersion>
<FileVersion>$(MyNumberNETVersion)</FileVersion>
</PropertyGroup>
</Project>
20 changes: 4 additions & 16 deletions MyNumberNET_CLI/MyNumberNET_CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,20 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<Authors>Hideki Saito</Authors>
<Company>Hideki Saito</Company>
<Title>MyNumber My Number Validation Command Line Tool</Title>
<Product>MyNumberNET_CLI</Product>
<PackageId>MyNumberNET_CLI</PackageId>
<Description>My Number for .NET (CLI)</Description>
<Copyright>Copyright (c) 2017 Hideki Saito</Copyright>
<PackageLicenseUrl>https://github.com/hsaito/MyNumber.NET/blob/master/LICENSE</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/hsaito/MyNumber.NET</PackageProjectUrl>
<Version>1.0.5.0</Version>
<AssemblyVersion>1.0.5.0</AssemblyVersion>
<FileVersion>1.0.5.0</FileVersion>
<LangVersion>latest</LangVersion>
<Version>$(MyNumberNETCliVersion)</Version>
<AssemblyVersion>$(MyNumberNETCliVersion)</AssemblyVersion>
<FileVersion>$(MyNumberNETCliVersion)</FileVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NLog" Version="6.0.4" />
<PackageReference Include="NLog" Version="6.0.6" />
<PackageReference Include="System.Console" Version="4.3.1" />
<PackageReference Include="System.Net.Sockets" Version="4.3.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MyNumberNET\MyNumberNET.csproj" />
</ItemGroup>
<PropertyGroup>
<Deterministic>true</Deterministic>
<DeterministicSourceRoot>/_/</DeterministicSourceRoot>
<RepoRoot>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\..\'))</RepoRoot>
<PathMap>$(RepoRoot)=$(DeterministicSourceRoot)</PathMap>
</PropertyGroup>
</Project>
25 changes: 6 additions & 19 deletions MyNumberNET_Test/MyNumberNET_Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,22 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
<Authors>Hideki Saito</Authors>
<Company>Hideki Saito</Company>
<Title>MyNumberNet My Number Validation Unit Tests</Title>
<Product>MyNumberNET_Test</Product>
<PackageId>MyNumberNET_Test</PackageId>
<Description>My Number for .NET (Unit Test)</Description>
<Copyright>Copyright (c) 2019 Hideki Saito</Copyright>
<PackageLicenseUrl>https://github.com/hsaito/MyNumber.NET/blob/master/LICENSE</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/hsaito/MyNumber.NET</PackageProjectUrl>
<Version>1.0.5.0</Version>
<AssemblyVersion>1.0.5.0</AssemblyVersion>
<FileVersion>1.0.5.0</FileVersion>
<LangVersion>latest</LangVersion>
<Version>$(MyNumberNETTestVersion)</Version>
<AssemblyVersion>$(MyNumberNETTestVersion)</AssemblyVersion>
<FileVersion>$(MyNumberNETTestVersion)</FileVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageReference Include="MSTest.TestAdapter" Version="3.10.4" />
<PackageReference Include="MSTest.TestFramework" Version="3.10.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageReference Include="MSTest.TestAdapter" Version="4.0.2" />
<PackageReference Include="MSTest.TestFramework" Version="4.0.2" />
<PackageReference Include="xunit" Version="2.9.3" />
<!-- Other test dependencies -->
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MyNumberNET\MyNumberNET.csproj" />
<ProjectReference Include="..\MyNumberNET_ApiServer\MyNumberNET_ApiServer.csproj" />
</ItemGroup>
<PropertyGroup>
<Deterministic>true</Deterministic>
<DeterministicSourceRoot>/_/</DeterministicSourceRoot>
<RepoRoot>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\..\'))</RepoRoot>
<PathMap>$(RepoRoot)=$(DeterministicSourceRoot)</PathMap>
</PropertyGroup>
</Project>
26 changes: 13 additions & 13 deletions MyNumberNET_Test/MyNumberValueTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@ public void Constructor_ValidDigits_CreatesMyNumberValue()
public void Constructor_InvalidDigits_ThrowsException()
{
// Act & Assert
Assert.ThrowsException<MyNumber.MyNumberMalformedException>(() => new MyNumberValue(_invalidMyNumber));
Assert.ThrowsExactly<MyNumber.MyNumberMalformedException>(() => new MyNumberValue(_invalidMyNumber));
}

[TestMethod]
public void Constructor_NullDigits_ThrowsException()
{
// Act & Assert
Assert.ThrowsException<MyNumber.MyNumberMalformedException>(() => new MyNumberValue(null));
Assert.ThrowsExactly<MyNumber.MyNumberMalformedException>(() => new MyNumberValue(null));
}

[TestMethod]
public void Constructor_WrongLength_ThrowsException()
{
// Act & Assert
Assert.ThrowsException<MyNumber.MyNumberMalformedException>(() => new MyNumberValue(new int[10]));
Assert.ThrowsException<MyNumber.MyNumberMalformedException>(() => new MyNumberValue(new int[13]));
Assert.ThrowsExactly<MyNumber.MyNumberMalformedException>(() => new MyNumberValue(new int[10]));
Assert.ThrowsExactly<MyNumber.MyNumberMalformedException>(() => new MyNumberValue(new int[13]));
}

[TestMethod]
Expand Down Expand Up @@ -72,9 +72,9 @@ public void FromFirstElevenDigits_ValidDigits_CreatesMyNumberValue()
public void FromFirstElevenDigits_InvalidLength_ThrowsException()
{
// Act & Assert
Assert.ThrowsException<MyNumber.MyNumberMalformedException>(() =>
Assert.ThrowsExactly<MyNumber.MyNumberMalformedException>(() =>
MyNumberValue.FromFirstElevenDigits(new int[10]));
Assert.ThrowsException<MyNumber.MyNumberMalformedException>(() =>
Assert.ThrowsExactly<MyNumber.MyNumberMalformedException>(() =>
MyNumberValue.FromFirstElevenDigits(null));
}

Expand Down Expand Up @@ -154,7 +154,7 @@ public void Parse_ValidString_ReturnsMyNumberValue()
public void Parse_InvalidString_ThrowsException()
{
// Act & Assert
Assert.ThrowsException<ArgumentException>(() => MyNumberValue.Parse("invalid"));
Assert.ThrowsExactly<ArgumentException>(() => MyNumberValue.Parse("invalid"));
}

[TestMethod]
Expand Down Expand Up @@ -204,7 +204,7 @@ public void ToString_InvalidFormat_ThrowsException()
var myNumber = new MyNumberValue(_validMyNumber);

// Act & Assert
Assert.ThrowsException<FormatException>(() => myNumber.ToString("X"));
Assert.ThrowsExactly<FormatException>(() => myNumber.ToString("X"));
}

[TestMethod]
Expand Down Expand Up @@ -311,14 +311,14 @@ public void ExplicitConversion_FromString_CreatesMyNumberValue()
public void ExplicitConversion_FromInvalidIntArray_ThrowsException()
{
// Act & Assert
Assert.ThrowsException<MyNumber.MyNumberMalformedException>(() => (MyNumberValue)_invalidMyNumber);
Assert.ThrowsExactly<MyNumber.MyNumberMalformedException>(() => (MyNumberValue)_invalidMyNumber);
}

[TestMethod]
public void ExplicitConversion_FromInvalidString_ThrowsException()
{
// Act & Assert
Assert.ThrowsException<ArgumentException>(() => (MyNumberValue)"invalid");
Assert.ThrowsExactly<ArgumentException>(() => (MyNumberValue)"invalid");
}

[TestMethod]
Expand All @@ -343,7 +343,7 @@ public void Digits_UninitializedValue_ThrowsException()
var myNumber = new MyNumberValue();

// Act & Assert
Assert.ThrowsException<InvalidOperationException>(() => myNumber.Digits);
Assert.ThrowsExactly<InvalidOperationException>(() => myNumber.Digits);
}

[TestMethod]
Expand All @@ -353,7 +353,7 @@ public void ToString_UninitializedValue_ThrowsException()
var myNumber = new MyNumberValue();

// Act & Assert
Assert.ThrowsException<InvalidOperationException>(() => myNumber.ToString());
Assert.ThrowsExactly<InvalidOperationException>(() => myNumber.ToString());
}
}
}
}
Loading