Skip to content

Commit

Permalink
Fix 4th 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 bd1b98d commit 19de754
Show file tree
Hide file tree
Showing 28 changed files with 200 additions and 157 deletions.
2 changes: 1 addition & 1 deletion KeyManager.Library.KeyStore.File/FileKeyStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private byte[] GetWrappingKey()
return key;
}

public override Task<IList<KeyEntryId>> GetAll(KeyEntryClass? keClass = null)
public override Task<IList<KeyEntryId>> GetAll(KeyEntryClass? keClass)
{
log.Info(string.Format("Getting all key entries (class: `{0}`)...", keClass));
IList<KeyEntryId> keyEntries = new List<KeyEntryId>();
Expand Down
4 changes: 3 additions & 1 deletion KeyManager.Library.KeyStore.HSM_PKCS11/PKCS11KeyEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Leosac.KeyManager.Library.KeyStore.HSM_PKCS11
{
public abstract class PKCS11KeyEntry : KeyEntry
{
public PKCS11KeyEntry()
protected PKCS11KeyEntry()
{
Identifier.Id = Guid.NewGuid().ToString("N");
}
Expand Down Expand Up @@ -78,7 +78,9 @@ private static uint GetKeySize(CKK ckk)
public static KeyEntryClass GetKeyEntryClassFromCKK(CKK ckk)
{
if (ckk == CKK.CKK_DSA || ckk == CKK.CKK_ECDSA || ckk == CKK.CKK_RSA)
{
return KeyEntryClass.Asymmetric;
}

return KeyEntryClass.Symmetric;
}
Expand Down
11 changes: 5 additions & 6 deletions KeyManager.Library.KeyStore.LCP/LCPKeyStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ public class LCPKeyStore : KeyStore
private ICredentialKeyAPI? _keyAPI;
private string? _authToken;

public LCPKeyStore()
{

}

public override string Name => "LCP";

public override bool CanCreateKeyEntries => true;
Expand Down Expand Up @@ -168,7 +163,7 @@ public override async Task<IList<KeyEntryId>> GetAll(KeyEntryClass? keClass)
var keys = await _keyAPI!.GetAll();
foreach (var k in keys)
{
entries.Add(new KeyEntryId()
entries.Add(new KeyEntryId
{
Id = k.Id.ToString(),
Label = k.Name
Expand All @@ -182,7 +177,9 @@ public override async Task<IList<KeyEntryId>> GetAll(KeyEntryClass? keClass)
private void CheckAuthentication()
{
if (_authAPI == null || _keyAPI == null || string.IsNullOrEmpty(_authToken))
{
throw new Exception("Please open the key store first to perform authentication.");
}
}

public LCPKeyStoreProperties GetLCPProperties()
Expand Down Expand Up @@ -277,7 +274,9 @@ public override async Task Update(IChangeKeyEntry change, bool ignoreIfMissing)
}
}
else
{
throw new NotImplementedException();
}

log.Info(string.Format("Key entry `{0}` updated.", change.Identifier));
}
Expand Down
7 changes: 3 additions & 4 deletions KeyManager.Library.KeyStore.LCP/LCPKeyStoreProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public override bool Equals(object? obj)
public bool Equals(LCPKeyStoreProperties? p)
{
if (p is null)
{
return false;
}

if (Object.ReferenceEquals(this, p))
{
Expand All @@ -51,10 +53,7 @@ public bool Equals(LCPKeyStoreProperties? p)
{
if (lhs is null)
{
if (rhs is null)
return true;

return false;
return rhs is null;
}

return lhs.Equals(rhs);
Expand Down
2 changes: 1 addition & 1 deletion KeyManager.Library.KeyStore.Memory/MemoryKeyEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public override IList<KeyEntryVariant> GetAllVariants(KeyEntryClass? classFilter
if (classFilter == null || classFilter == KeyEntryClass.Asymmetric)
{
var rsavar = new KeyEntryVariant { Name = "RSA" };
rsavar.KeyContainers.Add(new KeyContainer("Key", new Key(new[] { "RSA", KeyEntryClass.Asymmetric.ToString() }, 0, new KeyMaterial[]
rsavar.KeyContainers.Add(new KeyContainer("Key", new Key(new[] { "RSA", KeyEntryClass.Asymmetric.ToString() }, 0, new[]
{
new KeyMaterial("", KeyMaterial.PRIVATE_KEY),
new KeyMaterial("", KeyMaterial.PUBLIC_KEY)
Expand Down
2 changes: 1 addition & 1 deletion KeyManager.Library.KeyStore.Memory/MemoryKeyStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public override async Task Delete(KeyEntryId identifier, KeyEntryClass keClass,
return keyEntry;
}

public override Task<IList<KeyEntryId>> GetAll(KeyEntryClass? keClass = null)
public override Task<IList<KeyEntryId>> GetAll(KeyEntryClass? keClass)
{
IList<KeyEntryId> list = _keyEntries.Where(k => keClass == null || k.KClass == keClass).Select(k => k.Identifier).ToList();
return Task.FromResult(list);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public SAMKeyStorePropertiesControlViewModel()
});
}

private LibLogicalAccess.LibraryManager _lla;
private readonly LibLogicalAccess.LibraryManager _lla;

public SAMKeyStoreProperties? SAMProperties
{
Expand Down
17 changes: 16 additions & 1 deletion KeyManager.Library.KeyStore.NXP_SAM/SAMKeyStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ public override Task Close()
public override Task<bool> CheckKeyEntryExists(KeyEntryId identifier, KeyEntryClass keClass)
{
if (identifier.Id == null)
{
return Task.FromResult(false);
}

if (uint.TryParse(identifier.Id, out uint entry))
{
Expand Down Expand Up @@ -423,16 +425,25 @@ public override Task Update(IChangeKeyEntry change, bool ignoreIfMissing)
foreach (var keyversion in samkey.Variant.KeyContainers)
{
if (string.IsNullOrEmpty(keyversion.Key.GetAggregatedValue<string>()))
{
keys.Add(new LibLogicalAccess.ByteVector(new byte[keyversion.Key.KeySize]));
}
else
{
keys.Add(new LibLogicalAccess.ByteVector(keyversion.Key.GetAggregatedValue<byte[]>(KeyValueFormat.Binary)));
}
}

infoav2.vera = keyVersions[0].Version;
if (keyVersions.Length >= 2)
{
infoav2.verb = keyVersions[1].Version;
}

if (keyVersions.Length >= 3)
{
infoav2.verc = keyVersions[2].Version;
}

if (keyVersions[0].Key.Tags.Contains("AES"))
{
Expand Down Expand Up @@ -489,7 +500,7 @@ public override Task Update(IChangeKeyEntry change, bool ignoreIfMissing)
}

OnKeyEntryUpdated(change);
log.Info(String.Format("Key entry `{0}` updated.", change.Identifier));
log.Info(string.Format("Key entry `{0}` updated.", change.Identifier));
return Task.CompletedTask;
}

Expand Down Expand Up @@ -678,9 +689,13 @@ public void UpdateCounter(SAMKeyUsageCounter counter)
byte[] div;
log.Info(string.Format("Resolving key link with Key Entry Identifier `{0}`, Key Version `{1}`, Div Input `{2}`...", keyIdentifier, containerSelector, divInput));
if (!string.IsNullOrEmpty(divInput))
{
div = Convert.FromHexString(divInput);
}
else
{
div = Array.Empty<byte>();
}

if (!await CheckKeyEntryExists(keyIdentifier, keClass))
{
Expand Down
15 changes: 9 additions & 6 deletions KeyManager.Library.KeyStore.NXP_SAM/SAMKeyStoreProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ namespace Leosac.KeyManager.Library.KeyStore.NXP_SAM
{
public class SAMKeyStoreProperties : KeyStoreProperties, IEquatable<SAMKeyStoreProperties>
{
public SAMKeyStoreProperties() : base()
public SAMKeyStoreProperties()
{
_readerProvider = "PCSC";
_readerUnit = String.Empty;
_readerUnit = string.Empty;
_autoSwitchToAV2 = true;
_authenticateKeyEntryIdentifier = 0;
_authenticateKeyType = DESFireKeyType.DF_KEY_AES;
Expand Down Expand Up @@ -80,13 +80,19 @@ public override bool Equals(object? obj)
public bool Equals(SAMKeyStoreProperties? p)
{
if (p is null)
{
return false;
}

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

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

return (ReaderProvider == p.ReaderProvider) && (ReaderUnit == p.ReaderUnit) && (AutoSwitchToAV2 == p.AutoSwitchToAV2) &&
(AuthenticateKeyEntryIdentifier == p.AuthenticateKeyEntryIdentifier) && (_authenticateKeyVersion == p._authenticateKeyVersion) &&
Expand All @@ -99,10 +105,7 @@ public bool Equals(SAMKeyStoreProperties? p)
{
if (lhs is null)
{
if (rhs is null)
return true;

return false;
return rhs is null;
}

return lhs.Equals(rhs);
Expand Down
Loading

0 comments on commit 19de754

Please sign in to comment.