Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Code style refactor (#11)

Leendert de Borst7e2a754b271c
diff --git a/src/AliasDb/Migrations/20240526135300_InitialMigration.cs b/src/AliasDb/Migrations/20240526135300_InitialMigration.cs
index 8dea7095e..545dfcdb5 100644
--- a/src/AliasDb/Migrations/20240526135300_InitialMigration.cs
+++ b/src/AliasDb/Migrations/20240526135300_InitialMigration.cs
@@ -1,4 +1,5 @@
-using System;
+// <auto-generated/>
+using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
diff --git a/src/AliasDb/Migrations/20240527082514_BasicEntities.cs b/src/AliasDb/Migrations/20240527082514_BasicEntities.cs
index 872388fd1..877512e87 100644
--- a/src/AliasDb/Migrations/20240527082514_BasicEntities.cs
+++ b/src/AliasDb/Migrations/20240527082514_BasicEntities.cs
@@ -1,4 +1,5 @@
-using System;
+// <auto-generated/>
+using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
diff --git a/src/AliasDb/Migrations/20240529140248_LoginUserId.cs b/src/AliasDb/Migrations/20240529140248_LoginUserId.cs
index ce6cdb91e..9872ca0de 100644
--- a/src/AliasDb/Migrations/20240529140248_LoginUserId.cs
+++ b/src/AliasDb/Migrations/20240529140248_LoginUserId.cs
@@ -1,4 +1,5 @@
-using Microsoft.EntityFrameworkCore.Migrations;
+// <auto-generated/>
+using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
@@ -20,7 +21,7 @@ namespace AliasDb.Migrations
// Fetch the first UserId from the AspNetUsers table and update the Logins table
migrationBuilder.Sql(@"
- UPDATE Logins
+ UPDATE Logins
SET UserId = (SELECT Id FROM AspNetUsers LIMIT 1)
WHERE UserId = ''
");
diff --git a/src/AliasDb/Migrations/20240531142952_AddServiceLogo.cs b/src/AliasDb/Migrations/20240531142952_AddServiceLogo.cs
index 309c072c8..dc33afc0a 100644
--- a/src/AliasDb/Migrations/20240531142952_AddServiceLogo.cs
+++ b/src/AliasDb/Migrations/20240531142952_AddServiceLogo.cs
@@ -1,4 +1,5 @@
-using Microsoft.EntityFrameworkCore.Migrations;
+// <auto-generated/>
+using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
diff --git a/src/AliasDb/Migrations/20240603175245_AddAspNetUserRefreshTokens.cs b/src/AliasDb/Migrations/20240603175245_AddAspNetUserRefreshTokens.cs
index 44cb11021..c8e76f83a 100644
--- a/src/AliasDb/Migrations/20240603175245_AddAspNetUserRefreshTokens.cs
+++ b/src/AliasDb/Migrations/20240603175245_AddAspNetUserRefreshTokens.cs
@@ -1,4 +1,5 @@
-using System;
+// <auto-generated/>
+using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
diff --git a/src/AliasVault.Shared/Models/TokenModel.cs b/src/AliasVault.Shared/Models/TokenModel.cs
index 696c717f3..6777dc850 100644
--- a/src/AliasVault.Shared/Models/TokenModel.cs
+++ b/src/AliasVault.Shared/Models/TokenModel.cs
@@ -5,10 +5,10 @@
// </copyright>
//-----------------------------------------------------------------------
-using System.Text.Json.Serialization;
-
namespace AliasVault.Shared.Models;
+using System.Text.Json.Serialization;
+
/// <summary>
/// Token model.
/// </summary>
diff --git a/src/AliasVault.WebApp/Auth/Components/InputTextField.razor b/src/AliasVault.WebApp/Auth/Components/InputTextField.razor
index 3c5152a52..19770ac83 100644
--- a/src/AliasVault.WebApp/Auth/Components/InputTextField.razor
+++ b/src/AliasVault.WebApp/Auth/Components/InputTextField.razor
@@ -37,5 +37,5 @@
/// <summary>
/// Gets or sets additional attributes for the input field.
/// </summary>
- [Parameter(CaptureUnmatchedValues = true)] public Dictionary<string, object?> AdditionalAttributes { get; set; } = new();
+ [Parameter(CaptureUnmatchedValues = true)] public Dictionary<string, object>? AdditionalAttributes { get; set; } = new();
}
diff --git a/src/AliasVault.WebApp/Auth/Providers/AuthStateProvider.cs b/src/AliasVault.WebApp/Auth/Providers/AuthStateProvider.cs
index e13fc7d27..948a6ea9c 100644
--- a/src/AliasVault.WebApp/Auth/Providers/AuthStateProvider.cs
+++ b/src/AliasVault.WebApp/Auth/Providers/AuthStateProvider.cs
@@ -5,12 +5,11 @@
// </copyright>
//-----------------------------------------------------------------------
-using AliasVault.WebApp.Auth.Services;
-
namespace AliasVault.WebApp.Auth.Providers;
using System.Security.Claims;
using System.Text.Json;
+using AliasVault.WebApp.Auth.Services;
using Microsoft.AspNetCore.Components.Authorization;
/// <summary>
diff --git a/src/AliasVault/Components/Pages/Aliases/AddEdit.razor b/src/AliasVault/Components/Pages/Aliases/AddEdit.razor
index 95220f0ae..b89706461 100644
--- a/src/AliasVault/Components/Pages/Aliases/AddEdit.razor
+++ b/src/AliasVault/Components/Pages/Aliases/AddEdit.razor
@@ -269,7 +269,7 @@ else
// Try to extract favicon from service URL
if (obj.Service.Url != null && !obj.Service.Url.IsNullOrEmpty())
{
- obj.Service.Logo = await FaviconExtractor.FaviconService.GetFaviconAsync(obj.Service.Url);
+ obj.Service.Logo = await FaviconExtractor.FaviconExtractor.GetFaviconAsync(obj.Service.Url);
}
if (EditMode)
diff --git a/src/Tests/AliasVault.E2ETests/AliasVault.E2ETests.csproj b/src/Tests/AliasVault.E2ETests/AliasVault.E2ETests.csproj
index a5458da96..4fcf8fc15 100644
--- a/src/Tests/AliasVault.E2ETests/AliasVault.E2ETests.csproj
+++ b/src/Tests/AliasVault.E2ETests/AliasVault.E2ETests.csproj
@@ -11,6 +11,7 @@
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
+ <DocumentationFile>bin\Debug\net8.0\AliasVault.E2ETests.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
diff --git a/src/Tests/AliasVault.UnitTests/AliasVault.UnitTests.csproj b/src/Tests/AliasVault.UnitTests/AliasVault.UnitTests.csproj
index 783d3eee7..82bdbe9d2 100644
--- a/src/Tests/AliasVault.UnitTests/AliasVault.UnitTests.csproj
+++ b/src/Tests/AliasVault.UnitTests/AliasVault.UnitTests.csproj
@@ -11,40 +11,42 @@
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
- <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
- <DocumentationFile>bin\Debug\net8.0\AliasVault.UnitTests.xml</DocumentationFile>
+ <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
+ <DocumentationFile>bin\Debug\net8.0\AliasVault.UnitTests.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
- <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
- <DocumentationFile>bin\Release\net8.0\AliasVault.UnitTests.xml</DocumentationFile>
+ <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
+ <DocumentationFile>bin\Release\net8.0\AliasVault.UnitTests.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
- <Content Include="..\..\stylecop.json" Link="stylecop.json" />
+ <AdditionalFiles Include="..\..\stylecop.json">
+ <Link>stylecop.json</Link>
+ </AdditionalFiles>
</ItemGroup>
<ItemGroup>
- <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
- <PackageReference Include="NUnit" Version="4.1.0" />
- <PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
+ <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0"/>
+ <PackageReference Include="NUnit" Version="4.1.0"/>
+ <PackageReference Include="NUnit3TestAdapter" Version="4.5.0"/>
<PackageReference Include="NUnit.Analyzers" Version="4.2.0">
- <PrivateAssets>all</PrivateAssets>
- <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
+ <PrivateAssets>all</PrivateAssets>
+ <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.2">
- <PrivateAssets>all</PrivateAssets>
- <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
+ <PrivateAssets>all</PrivateAssets>
+ <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556">
- <PrivateAssets>all</PrivateAssets>
- <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
+ <PrivateAssets>all</PrivateAssets>
+ <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
- <ProjectReference Include="..\..\Utilities\Cryptography\Cryptography.csproj" />
- <ProjectReference Include="..\..\Utilities\FaviconExtractor\FaviconExtractor.csproj" />
+ <ProjectReference Include="..\..\Utilities\Cryptography\Cryptography.csproj"/>
+ <ProjectReference Include="..\..\Utilities\FaviconExtractor\FaviconExtractor.csproj"/>
</ItemGroup>
</Project>
diff --git a/src/Tests/AliasVault.UnitTests/CryptographyTests.cs b/src/Tests/AliasVault.UnitTests/CryptographyTests.cs
index 7854b33ec..f2cdddc8f 100644
--- a/src/Tests/AliasVault.UnitTests/CryptographyTests.cs
+++ b/src/Tests/AliasVault.UnitTests/CryptographyTests.cs
@@ -1,9 +1,22 @@
-using System.Security.Cryptography;
+//-----------------------------------------------------------------------
+// <copyright file="CryptographyTests.cs" company="lanedirt">
+// Copyright (c) lanedirt. All rights reserved.
+// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
namespace AliasVault.Tests;
+using System.Security.Cryptography;
+
+/// <summary>
+/// Tests for the Cryptography class.
+/// </summary>
public class CryptographyTests
{
+ /// <summary>
+ /// Common setup for all tests.
+ /// </summary>
[SetUp]
public void Setup()
{
@@ -32,7 +45,6 @@ public class CryptographyTests
Assert.That(encrypted, Is.Not.Empty);
Assert.That(encrypted, Is.Not.EqualTo(plaintext));
-
// Decrypt the ciphertext
string decrypted = Cryptography.Cryptography.Decrypt(encrypted, key);
Console.WriteLine($"Decrypted: {decrypted}");
@@ -52,6 +64,7 @@ public class CryptographyTests
// Derive a key from the password using Argon2id
byte[] key = Cryptography.Cryptography.DeriveKeyFromPassword(password, salt);
+
// Encrypt the plaintext
string encrypted = Cryptography.Cryptography.Encrypt(plaintext, key);
diff --git a/src/Tests/AliasVault.UnitTests/FaviconExtractorTests.cs b/src/Tests/AliasVault.UnitTests/FaviconExtractorTests.cs
index f57d7b815..3084839b5 100644
--- a/src/Tests/AliasVault.UnitTests/FaviconExtractorTests.cs
+++ b/src/Tests/AliasVault.UnitTests/FaviconExtractorTests.cs
@@ -1,16 +1,32 @@
+//-----------------------------------------------------------------------
+// <copyright file="FaviconExtractorTests.cs" company="lanedirt">
+// Copyright (c) lanedirt. All rights reserved.
+// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
namespace AliasVault.Tests;
+/// <summary>
+/// Tests for the FaviconExtractor class.
+/// </summary>
public class FaviconExtractorTests
{
+ /// <summary>
+ /// Common setup for all tests.
+ /// </summary>
[SetUp]
public void Setup()
{
}
+ /// <summary>
+ /// Test extracting a favicon from a known website.
+ /// </summary>
[Test]
public void ExtractFaviconSpamOK()
{
- var faviconBytes = FaviconExtractor.FaviconService.GetFaviconAsync("https://spamok.com");
+ var faviconBytes = FaviconExtractor.FaviconExtractor.GetFaviconAsync("https://spamok.com");
Assert.That(faviconBytes, Is.Not.Null);
}
}
diff --git a/src/Tests/AliasVault.UnitTests/GlobalUsings.cs b/src/Tests/AliasVault.UnitTests/GlobalUsings.cs
index cefced496..7655a4f02 100644
--- a/src/Tests/AliasVault.UnitTests/GlobalUsings.cs
+++ b/src/Tests/AliasVault.UnitTests/GlobalUsings.cs
@@ -1 +1,10 @@
-global using NUnit.Framework;
\ No newline at end of file
+//-----------------------------------------------------------------------
+// <copyright file="GlobalUsings.cs" company="lanedirt">
+// Copyright (c) lanedirt. All rights reserved.
+// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+// <auto-generated />
+
+global using NUnit.Framework;
diff --git a/src/Utilities/Cryptography/Cryptography.cs b/src/Utilities/Cryptography/Cryptography.cs
index 29335af23..b618c69b1 100644
--- a/src/Utilities/Cryptography/Cryptography.cs
+++ b/src/Utilities/Cryptography/Cryptography.cs
@@ -1,11 +1,27 @@
-using System.Security.Cryptography;
-using System.Text;
-using Konscious.Security.Cryptography;
+//-----------------------------------------------------------------------
+// <copyright file="Cryptography.cs" company="lanedirt">
+// Copyright (c) lanedirt. All rights reserved.
+// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
namespace Cryptography;
-public class Cryptography
+using System.Security.Cryptography;
+using System.Text;
+using Konscious.Security.Cryptography;
+
+/// <summary>
+/// Cryptography class.
+/// </summary>
+public static class Cryptography
{
+ /// <summary>
+ /// Derive a key used for encryption/decryption based on a user password and system salt.
+ /// </summary>
+ /// <param name="password">User password.</param>
+ /// <param name="salt">The salt to use for the Argon2id hash.</param>
+ /// <returns>Encryption key as byte array.</returns>
public static byte[] DeriveKeyFromPassword(string password, string salt)
{
byte[] passwordBytes = Encoding.UTF8.GetBytes(password);
@@ -16,12 +32,18 @@ public class Cryptography
Salt = saltBytes,
DegreeOfParallelism = 8,
MemorySize = 65536,
- Iterations = 4
+ Iterations = 4,
};
return argon2.GetBytes(32); // Generate a 256-bit key
}
+ /// <summary>
+ /// Encrypt a plaintext string using AES-256.
+ /// </summary>
+ /// <param name="plaintext">The plaintext string.</param>
+ /// <param name="key">Key to use for encryption.</param>
+ /// <returns>The encrypted string (ciphertext).</returns>
public static string Encrypt(string plaintext, byte[] key)
{
using (Aes aes = Aes.Create())
@@ -53,6 +75,12 @@ public class Cryptography
}
}
+ /// <summary>
+ /// Decrypt a ciphertext string using AES-256.
+ /// </summary>
+ /// <param name="ciphertext">The encrypted string (ciphertext).</param>
+ /// <param name="key">The key used to originally encrypt the string.</param>
+ /// <returns>The original plaintext string.</returns>
public static string Decrypt(string ciphertext, byte[] key)
{
byte[] fullCipher = Convert.FromBase64String(ciphertext);
diff --git a/src/Utilities/Cryptography/Cryptography.csproj b/src/Utilities/Cryptography/Cryptography.csproj
index 1ddf2846b..3bfe819a1 100644
--- a/src/Utilities/Cryptography/Cryptography.csproj
+++ b/src/Utilities/Cryptography/Cryptography.csproj
@@ -8,6 +8,7 @@
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
+ <DocumentationFile>bin\Debug\net8.0\Cryptography.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">