Skip to content

Commit

Permalink
Fix 2nd set of Codacy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxhy committed Oct 14, 2023
1 parent cdbff94 commit 9cd3bfa
Show file tree
Hide file tree
Showing 42 changed files with 214 additions and 202 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Leosac.KeyManager.Library.KeyStore.HSM_PKCS11
{
public class SymmetricPKCS11KeyEntry : PKCS11KeyEntry
{
public SymmetricPKCS11KeyEntry() : base()
public SymmetricPKCS11KeyEntry()
{
Properties = new SymmetricPKCS11KeyEntryProperties();
}
Expand Down
21 changes: 13 additions & 8 deletions KeyManager.Library.KeyStore.LCP/LCPKeyEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ namespace Leosac.KeyManager.Library.KeyStore.LCP
{
public class LCPKeyEntry : KeyEntry
{
public LCPKeyEntry(KeyEntryClass kclass = KeyEntryClass.Symmetric)
public LCPKeyEntry() : this(KeyEntryClass.Symmetric)
{

}

public LCPKeyEntry(KeyEntryClass kclass)
{
Properties = new LCPKeyEntryProperties();
_kclass = kclass;
Expand All @@ -28,29 +33,29 @@ public override IList<KeyEntryVariant> GetAllVariants(KeyEntryClass? classFilter
if (classFilter == null || classFilter == KeyEntryClass.Symmetric)
{
var desvar = new KeyEntryVariant { Name = "DES" };
desvar.KeyContainers.Add(new KeyVersion("Key", 0,new Key(new string[] { "DES", KeyEntryClass.Symmetric.ToString() }, 16)));
desvar.KeyContainers.Add(new KeyVersion("Key", 0, new Key(new[] { "DES", KeyEntryClass.Symmetric.ToString() }, 16)));
variants.Add(desvar);
var tk3desvar = new KeyEntryVariant { Name = "TK3DES" };
tk3desvar.KeyContainers.Add(new KeyVersion("Key", 0, new Key(new string[] { "DES", KeyEntryClass.Symmetric.ToString() }, 24)));
tk3desvar.KeyContainers.Add(new KeyVersion("Key", 0, new Key(new[] { "DES", KeyEntryClass.Symmetric.ToString() }, 24)));
variants.Add(tk3desvar);
var aes128var = new KeyEntryVariant { Name = "AES128" };
aes128var.KeyContainers.Add(new KeyVersion("Key", 0,new Key(new string[] { "AES", KeyEntryClass.Symmetric.ToString() }, 16)));
aes128var.KeyContainers.Add(new KeyVersion("Key", 0,new Key(new[] { "AES", KeyEntryClass.Symmetric.ToString() }, 16)));
variants.Add(aes128var);
var aes256var = new KeyEntryVariant { Name = "AES256" };
aes256var.KeyContainers.Add(new KeyVersion("Key", 0,new Key(new string[] { "AES", KeyEntryClass.Symmetric.ToString() }, 32)));
aes256var.KeyContainers.Add(new KeyVersion("Key", 0,new Key(new[] { "AES", KeyEntryClass.Symmetric.ToString() }, 32)));
variants.Add(aes256var);
var hmacvar = new KeyEntryVariant { Name = "HMAC" };
hmacvar.KeyContainers.Add(new KeyVersion("Key", 0, new Key(new string[] { "HMAC", KeyEntryClass.Symmetric.ToString() })));
hmacvar.KeyContainers.Add(new KeyVersion("Key", 0, new Key(new[] { "HMAC", KeyEntryClass.Symmetric.ToString() })));
variants.Add(hmacvar);
}

if (classFilter == null || classFilter == KeyEntryClass.Asymmetric)
{
var rsapubvar = new KeyEntryVariant { Name = "RSA Public Key" };
rsapubvar.KeyContainers.Add(new KeyVersion("Key", 0, new Key(new string[] { "RSA", KeyEntryClass.Asymmetric.ToString(), KeyEntryClass.PublicKey.ToString() })));
rsapubvar.KeyContainers.Add(new KeyVersion("Key", 0, new Key(new[] { "RSA", KeyEntryClass.Asymmetric.ToString(), KeyEntryClass.PublicKey.ToString() })));
variants.Add(rsapubvar);
var rsaprivar = new KeyEntryVariant { Name = "RSA Private Key" };
rsaprivar.KeyContainers.Add(new KeyVersion("Key", 0, new Key(new string[] { "RSA", KeyEntryClass.Asymmetric.ToString(), KeyEntryClass.PrivateKey.ToString() })));
rsaprivar.KeyContainers.Add(new KeyVersion("Key", 0, new Key(new[] { "RSA", KeyEntryClass.Asymmetric.ToString(), KeyEntryClass.PrivateKey.ToString() })));
variants.Add(rsaprivar);
}

Expand Down
10 changes: 5 additions & 5 deletions KeyManager.Library.KeyStore.LCP/LCPKeyStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public override async Task Create(IChangeKeyEntry change)
log.Info(string.Format("Key entry `{0}` created.", change.Identifier));
}

public override async Task Delete(KeyEntryId identifier, KeyEntryClass keClass, bool ignoreIfMissing = false)
public override async Task Delete(KeyEntryId identifier, KeyEntryClass keClass, bool ignoreIfMissing)
{
log.Info(string.Format("Deleting key entry `{0}`...", identifier));
var exists = await CheckKeyEntryExists(identifier, keClass);
Expand Down Expand Up @@ -158,7 +158,7 @@ public override async Task Delete(KeyEntryId identifier, KeyEntryClass keClass,
return ke;
}

public override async Task<IList<KeyEntryId>> GetAll(KeyEntryClass? keClass = null)
public override async Task<IList<KeyEntryId>> GetAll(KeyEntryClass? keClass)
{
log.Info(string.Format("Getting all key entries (class: `{0}`)...", keClass));

Expand Down Expand Up @@ -225,12 +225,12 @@ public override async Task Open()
log.Info("Key Store opened.");
}

public override Task<string?> ResolveKeyEntryLink(KeyEntryId keyIdentifier, KeyEntryClass keClass, string? divInput = null, KeyEntryId? wrappingKeyId = null, string? wrappingContainerSelector = null)
public override Task<string?> ResolveKeyEntryLink(KeyEntryId keyIdentifier, KeyEntryClass keClass, string? divInput, KeyEntryId? wrappingKeyId, string? wrappingContainerSelector)
{
throw new NotSupportedException();
}

public override Task<string?> ResolveKeyLink(KeyEntryId keyIdentifier, KeyEntryClass keClass, string? containerSelector = null, string? divInput = null)
public override Task<string?> ResolveKeyLink(KeyEntryId keyIdentifier, KeyEntryClass keClass, string? containerSelector, string? divInput)
{
throw new NotSupportedException();
}
Expand All @@ -254,7 +254,7 @@ public override async Task Store(IList<IChangeKeyEntry> changes)
log.Info("Key Entries storing completed.");
}

public override async Task Update(IChangeKeyEntry change, bool ignoreIfMissing = false)
public override async Task Update(IChangeKeyEntry change, bool ignoreIfMissing)
{
log.Info(string.Format("Updating key entry `{0}`...", change.Identifier));

Expand Down
4 changes: 4 additions & 0 deletions KeyManager.Library.KeyStore.LCP/LCPKeyStoreProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ public bool Equals(LCPKeyStoreProperties? p)
return false;

if (Object.ReferenceEquals(this, p))
{
return true;
}

if (this.GetType() != p.GetType())
{
return false;
}

return (ServerAddress == p.ServerAddress && Username == p.Username);
}
Expand Down
24 changes: 12 additions & 12 deletions KeyManager.Library.KeyStore.Memory/MemoryKeyEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,27 @@ public override IList<KeyEntryVariant> GetAllVariants(KeyEntryClass? classFilter

if (classFilter == null || classFilter == KeyEntryClass.Symmetric)
{
var desvar = new KeyEntryVariant() { Name = "DES" };
desvar.KeyContainers.Add(new KeyContainer("Key", new Key(new string[] { "DES", KeyEntryClass.Symmetric.ToString() }, 16)));
var desvar = new KeyEntryVariant { Name = "DES" };
desvar.KeyContainers.Add(new KeyContainer("Key", new Key(new[] { "DES", KeyEntryClass.Symmetric.ToString() }, 16)));
variants.Add(desvar);
var tk3desvar = new KeyEntryVariant() { Name = "TK3DES" };
tk3desvar.KeyContainers.Add(new KeyContainer("Key", new Key(new string[] { "DES", KeyEntryClass.Symmetric.ToString() }, 24)));
var tk3desvar = new KeyEntryVariant { Name = "TK3DES" };
tk3desvar.KeyContainers.Add(new KeyContainer("Key", new Key(new[] { "DES", KeyEntryClass.Symmetric.ToString() }, 24)));
variants.Add(tk3desvar);
var aes128var = new KeyEntryVariant() { Name = "AES128" };
aes128var.KeyContainers.Add(new KeyContainer("Key", new Key(new string[] { "AES", KeyEntryClass.Symmetric.ToString() }, 16)));
var aes128var = new KeyEntryVariant { Name = "AES128" };
aes128var.KeyContainers.Add(new KeyContainer("Key", new Key(new[] { "AES", KeyEntryClass.Symmetric.ToString() }, 16)));
variants.Add(aes128var);
var aes192var = new KeyEntryVariant() { Name = "AES192" };
aes192var.KeyContainers.Add(new KeyContainer("Key", new Key(new string[] { "AES", KeyEntryClass.Symmetric.ToString() }, 24)));
var aes192var = new KeyEntryVariant { Name = "AES192" };
aes192var.KeyContainers.Add(new KeyContainer("Key", new Key(new[] { "AES", KeyEntryClass.Symmetric.ToString() }, 24)));
variants.Add(aes192var);
var aes256var = new KeyEntryVariant() { Name = "AES256" };
aes256var.KeyContainers.Add(new KeyContainer("Key", new Key(new string[] { "AES", KeyEntryClass.Symmetric.ToString() }, 32)));
var aes256var = new KeyEntryVariant { Name = "AES256" };
aes256var.KeyContainers.Add(new KeyContainer("Key", new Key(new[] { "AES", KeyEntryClass.Symmetric.ToString() }, 32)));
variants.Add(aes256var);
}

if (classFilter == null || classFilter == KeyEntryClass.Asymmetric)
{
var rsavar = new KeyEntryVariant() { Name = "RSA" };
rsavar.KeyContainers.Add(new KeyContainer("Key", new Key(new string[] { "RSA", KeyEntryClass.Asymmetric.ToString() }, 0, new KeyMaterial[]
var rsavar = new KeyEntryVariant { Name = "RSA" };
rsavar.KeyContainers.Add(new KeyContainer("Key", new Key(new[] { "RSA", KeyEntryClass.Asymmetric.ToString() }, 0, new KeyMaterial[]
{
new KeyMaterial("", KeyMaterial.PRIVATE_KEY),
new KeyMaterial("", KeyMaterial.PUBLIC_KEY)
Expand Down
4 changes: 2 additions & 2 deletions KeyManager.Library.KeyStore.Memory/MemoryKeyStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public override async Task Create(IChangeKeyEntry change)
}
}

public override async Task Delete(KeyEntryId identifier, KeyEntryClass keClass, bool ignoreIfMissing = false)
public override async Task Delete(KeyEntryId identifier, KeyEntryClass keClass, bool ignoreIfMissing)
{
if (!await CheckKeyEntryExists(identifier, keClass, out KeyEntry? keyEntry) && !ignoreIfMissing)
{
Expand Down Expand Up @@ -123,7 +123,7 @@ public override async Task Store(IList<IChangeKeyEntry> changes)
}
}

public override async Task Update(IChangeKeyEntry change, bool ignoreIfMissing = false)
public override async Task Update(IChangeKeyEntry change, bool ignoreIfMissing)
{
await Delete(change.Identifier, change.KClass, ignoreIfMissing);
await Create(change);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public SAMKeyStoreKeyCounterControlViewModel()
{
try
{
var model = new SAMKeyUsageCounterDialogViewModel()
var model = new SAMKeyUsageCounterDialogViewModel
{
Counter = (KeyStore as SAMKeyStore)!.GetCounter(identifier.Value)
};
var dialog = new SAMKeyUsageCounterDialog()
var dialog = new SAMKeyUsageCounterDialog
{
DataContext = model
};
Expand Down
18 changes: 9 additions & 9 deletions KeyManager.Library.KeyStore.NXP_SAM/SAMSymmetricKeyEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Leosac.KeyManager.Library.KeyStore.NXP_SAM
{
public class SAMSymmetricKeyEntry : KeyEntry
{
public SAMSymmetricKeyEntry() : base()
public SAMSymmetricKeyEntry()
{
Identifier.Id = "0";
Properties = new SAMSymmetricKeyEntryProperties();
Expand All @@ -25,18 +25,18 @@ public override IList<KeyEntryVariant> GetAllVariants(KeyEntryClass? classFilter
if (classFilter == null || classFilter == KeyEntryClass.Symmetric)
{
var desvar = new KeyEntryVariant { Name = "DES" };
desvar.KeyContainers.Add(new KeyVersion("Key Version A", 0, new Key(new string[] { "DES", KeyEntryClass.Symmetric.ToString() }, 16)));
desvar.KeyContainers.Add(new KeyVersion("Key Version B", 0, new Key(new string[] { "DES", KeyEntryClass.Symmetric.ToString() }, 16)));
desvar.KeyContainers.Add(new KeyVersion("Key Version C", 0, new Key(new string[] { "DES", KeyEntryClass.Symmetric.ToString() }, 16)));
desvar.KeyContainers.Add(new KeyVersion("Key Version A", 0, new Key(new[] { "DES", KeyEntryClass.Symmetric.ToString() }, 16)));
desvar.KeyContainers.Add(new KeyVersion("Key Version B", 0, new Key(new[] { "DES", KeyEntryClass.Symmetric.ToString() }, 16)));
desvar.KeyContainers.Add(new KeyVersion("Key Version C", 0, new Key(new[] { "DES", KeyEntryClass.Symmetric.ToString() }, 16)));
variants.Add(desvar);
var tk3desvar = new KeyEntryVariant { Name = "TK3DES" };
tk3desvar.KeyContainers.Add(new KeyVersion("Key Version A", 0, new Key(new string[] { "DES", KeyEntryClass.Symmetric.ToString() }, 24)));
tk3desvar.KeyContainers.Add(new KeyVersion("Key Version B", 0, new Key(new string[] { "DES", KeyEntryClass.Symmetric.ToString() }, 24)));
tk3desvar.KeyContainers.Add(new KeyVersion("Key Version A", 0, new Key(new[] { "DES", KeyEntryClass.Symmetric.ToString() }, 24)));
tk3desvar.KeyContainers.Add(new KeyVersion("Key Version B", 0, new Key(new[] { "DES", KeyEntryClass.Symmetric.ToString() }, 24)));
variants.Add(tk3desvar);
var aes128var = new KeyEntryVariant { Name = "AES128" };
aes128var.KeyContainers.Add(new KeyVersion("Key Version A", 0, new Key(new string[] { "AES", KeyEntryClass.Symmetric.ToString() }, 16)));
aes128var.KeyContainers.Add(new KeyVersion("Key Version B", 0, new Key(new string[] { "AES", KeyEntryClass.Symmetric.ToString() }, 16)));
aes128var.KeyContainers.Add(new KeyVersion("Key Version C", 0, new Key(new string[] { "AES", KeyEntryClass.Symmetric.ToString() }, 16)));
aes128var.KeyContainers.Add(new KeyVersion("Key Version A", 0, new Key(new[] { "AES", KeyEntryClass.Symmetric.ToString() }, 16)));
aes128var.KeyContainers.Add(new KeyVersion("Key Version B", 0, new Key(new[] { "AES", KeyEntryClass.Symmetric.ToString() }, 16)));
aes128var.KeyContainers.Add(new KeyVersion("Key Version C", 0, new Key(new[] { "AES", KeyEntryClass.Symmetric.ToString() }, 16)));
variants.Add(aes128var);
}

Expand Down
4 changes: 2 additions & 2 deletions KeyManager.Library.UI/Domain/FolderBrowserDialogViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public FolderBrowserDialogViewModel()
);
}

private bool noDirUpdate = false;
private bool noDirUpdate;
private DirectoryInfo? _selectedDirectory;
private string? _ioError;
private bool _hasError = false;
private bool _hasError;
private string? _newFolderName;

private DriveInfo? _selectedDrive;
Expand Down
16 changes: 7 additions & 9 deletions KeyManager.Library.UI/Domain/KeyEntriesControlViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
using Leosac.KeyManager.Library.KeyStore;
using Leosac.KeyManager.Library.Plugin;
using Leosac.KeyManager.Library.Plugin.UI;
using Leosac.WpfApp.Domain;
using Leosac.WpfApp;
using MaterialDesignThemes.Wpf;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows.Data;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System.Windows.Threading;
using System.Windows.Input;

namespace Leosac.KeyManager.Library.UI.Domain
Expand All @@ -25,15 +23,15 @@ public KeyEntriesControlViewModel(ISnackbarMessageQueue snackbarMessageQueue)
BindingOperations.EnableCollectionSynchronization(Identifiers, _identifierLock);
WizardFactories = new ObservableCollection<WizardFactory>(WizardFactory.RegisteredFactories);

CreateKeyEntryCommand = new RelayCommand(
() =>
CreateKeyEntryCommand = new AsyncRelayCommand(
async () =>
{
var model = new KeyEntryDialogViewModel() { KClass = _keClass };
var dialog = new KeyEntryDialog()
{
DataContext = model
};
CreateKeyEntry(dialog);
await CreateKeyEntry(dialog);
});

EditKeyEntryCommand = new AsyncRelayCommand<SelectableKeyEntryId>(
Expand Down Expand Up @@ -206,9 +204,9 @@ public bool ShowSelection
set => SetProperty(ref _showSelection, value);
}

public RelayCommand CreateKeyEntryCommand { get; }
public AsyncRelayCommand CreateKeyEntryCommand { get; }

private async void CreateKeyEntry(KeyEntryDialog dialog)
private async Task CreateKeyEntry(KeyEntryDialog dialog)
{
var ret = await DialogHelper.ForceShow(dialog, "RootDialog");
if (ret != null && dialog.DataContext is KeyEntryDialogViewModel model)
Expand All @@ -226,13 +224,13 @@ private async void CreateKeyEntry(KeyEntryDialog dialog)
catch (KeyStoreException ex)
{
SnackbarHelper.EnqueueError(_snackbarMessageQueue, ex, "Key Store Error");
CreateKeyEntry(dialog);
await CreateKeyEntry(dialog);
}
catch (Exception ex)
{
log.Error("Creating the Key Entry failed unexpected.", ex);
SnackbarHelper.EnqueueError(_snackbarMessageQueue, ex);
CreateKeyEntry(dialog);
await CreateKeyEntry(dialog);
}
}
}
Expand Down
9 changes: 7 additions & 2 deletions KeyManager.Library.UI/Domain/KeyEntryItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ public class KeyEntryItem : ObservableValidator
{
private readonly KeyEntryUIFactory _factory;

private KeyEntryPropertiesControlViewModel? _dataContext;
private readonly KeyEntryPropertiesControlViewModel? _dataContext;

private object? _content;

public KeyEntryItem(KeyEntryUIFactory factory, KeyEntryPropertiesControlViewModel? dataContext = null)
public KeyEntryItem(KeyEntryUIFactory factory) : this(factory, null)
{

}

public KeyEntryItem(KeyEntryUIFactory factory, KeyEntryPropertiesControlViewModel? dataContext)
{
_factory = factory;
_dataContext = dataContext ?? factory.CreateKeyEntryPropertiesControlViewModel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Leosac.KeyManager.Library.UI.Domain
{
public class KeyEntryLinkDialogViewModel : LinkDialogViewModel
{
public KeyEntryLinkDialogViewModel() : base()
public KeyEntryLinkDialogViewModel()
{

}
Expand Down
9 changes: 7 additions & 2 deletions KeyManager.Library.UI/Domain/KeyStoreItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ public class KeyStoreItem : ObservableValidator
{
private readonly KeyStoreUIFactory _factory;

private KeyStorePropertiesControlViewModel? _dataContext;
private readonly KeyStorePropertiesControlViewModel? _dataContext;

private object? _content;

public KeyStoreItem(KeyStoreUIFactory factory, KeyStorePropertiesControlViewModel? dataContext = null)
public KeyStoreItem(KeyStoreUIFactory factory) : this(factory, null)
{

}

public KeyStoreItem(KeyStoreUIFactory factory, KeyStorePropertiesControlViewModel? dataContext)
{
_factory = factory;
_dataContext = dataContext ?? factory.CreateKeyStorePropertiesControlViewModel();
Expand Down
7 changes: 1 addition & 6 deletions KeyManager.Library.UI/Domain/NotEmptyValidationRule.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;
using System.Windows.Controls;

namespace Leosac.KeyManager.Library.UI.Domain
Expand Down
Loading

0 comments on commit 9cd3bfa

Please sign in to comment.