Skip to content

Commit eeb0ad7

Browse files
committed
feat: add null checks for EncryptionParameters
1 parent be0d6a1 commit eeb0ad7

1 file changed

Lines changed: 26 additions & 3 deletions

File tree

src/Helpers/Validators.cs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ public static class Validators
1515
/// <exception cref="ArgumentNullException">
1616
/// Thrown if the specified parameters instance is null or if any of its required properties are null.
1717
/// </exception>
18-
public static void ValidateNotNull(ByteEncryptionParameters parameters)
18+
public static void ValidateNotNull(EncryptionParameters parameters)
1919
{
2020
if (parameters == null)
2121
{
2222
throw new ArgumentNullException(nameof(parameters), "ByteEncryptionParameters instance cannot be null.");
2323
}
2424

25-
if (parameters.Data == null)
25+
if (parameters.DataToEncrypt == null)
2626
{
27-
throw new ArgumentNullException(nameof(parameters.Data), "Data property cannot be null.");
27+
throw new ArgumentNullException(nameof(parameters.DataToEncrypt), "DataToEncrypt property cannot be null.");
2828
}
2929

3030
if (parameters.SecretKey == null)
@@ -60,5 +60,28 @@ public static void ValidateNotNull(StringEncryptionParameters parameters)
6060
throw new ArgumentNullException(nameof(parameters.IV), "IV property cannot be null.");
6161
}
6262
}
63+
64+
/// <summary>
65+
/// Validates whether the provided string is a valid Base64-encoded key.
66+
/// </summary>
67+
/// <param name="keyAsString">The string to validate.</param>
68+
/// <returns>True if the string is a valid Base64-encoded key; otherwise, false.</returns>
69+
public static bool IsBase64String(string keyAsString)
70+
{
71+
if (string.IsNullOrEmpty(keyAsString))
72+
{
73+
return false;
74+
}
75+
76+
try
77+
{
78+
byte[] data = Convert.FromBase64String(keyAsString);
79+
return true;
80+
}
81+
catch (FormatException)
82+
{
83+
return false;
84+
}
85+
}
6386
}
6487
}

0 commit comments

Comments
 (0)