mirror of
https://github.com/SabreTools/SabreTools.IO.git
synced 2026-09-22 06:36:01 +00:00
Make validation methods public
This commit is contained in:
@@ -26,18 +26,8 @@ namespace SabreTools.Security.Cryptography
|
||||
get;
|
||||
set
|
||||
{
|
||||
// Ignore missing key data
|
||||
if (value.Length == 0)
|
||||
return;
|
||||
|
||||
// Validate the key data
|
||||
var cipher = AESCTR.CreateEncryptionCipher(value, TestIV);
|
||||
byte[] actual = cipher.ProcessBytes(TestPattern);
|
||||
if (!actual.EqualsExactly(ExpectedKeyX0x18))
|
||||
return;
|
||||
|
||||
// Assign the validated value
|
||||
field = value;
|
||||
if (ValidateKeyX0x18(value))
|
||||
field = value;
|
||||
}
|
||||
} = [];
|
||||
|
||||
@@ -49,18 +39,8 @@ namespace SabreTools.Security.Cryptography
|
||||
get;
|
||||
set
|
||||
{
|
||||
// Ignore missing key data
|
||||
if (value.Length == 0)
|
||||
return;
|
||||
|
||||
// Validate the key data
|
||||
var cipher = AESCTR.CreateEncryptionCipher(value, TestIV);
|
||||
byte[] actual = cipher.ProcessBytes(TestPattern);
|
||||
if (!actual.EqualsExactly(ExpectedDevKeyX0x18))
|
||||
return;
|
||||
|
||||
// Assign the validated value
|
||||
field = value;
|
||||
if (ValidateDevKeyX0x18(value))
|
||||
field = value;
|
||||
}
|
||||
} = [];
|
||||
|
||||
@@ -72,18 +52,8 @@ namespace SabreTools.Security.Cryptography
|
||||
get;
|
||||
set
|
||||
{
|
||||
// Ignore missing key data
|
||||
if (value.Length == 0)
|
||||
return;
|
||||
|
||||
// Validate the key data
|
||||
var cipher = AESCTR.CreateEncryptionCipher(value, TestIV);
|
||||
byte[] actual = cipher.ProcessBytes(TestPattern);
|
||||
if (!actual.EqualsExactly(ExpectedKeyX0x1B))
|
||||
return;
|
||||
|
||||
// Assign the validated value
|
||||
field = value;
|
||||
if (ValidateKeyX0x1B(value))
|
||||
field = value;
|
||||
}
|
||||
} = [];
|
||||
|
||||
@@ -95,18 +65,8 @@ namespace SabreTools.Security.Cryptography
|
||||
get;
|
||||
set
|
||||
{
|
||||
// Ignore missing key data
|
||||
if (value.Length == 0)
|
||||
return;
|
||||
|
||||
// Validate the key data
|
||||
var cipher = AESCTR.CreateEncryptionCipher(value, TestIV);
|
||||
byte[] actual = cipher.ProcessBytes(TestPattern);
|
||||
if (!actual.EqualsExactly(ExpectedDevKeyX0x1B))
|
||||
return;
|
||||
|
||||
// Assign the validated value
|
||||
field = value;
|
||||
if (ValidateDevKeyX0x1B(value))
|
||||
field = value;
|
||||
}
|
||||
} = [];
|
||||
|
||||
@@ -118,18 +78,8 @@ namespace SabreTools.Security.Cryptography
|
||||
get;
|
||||
set
|
||||
{
|
||||
// Ignore missing key data
|
||||
if (value.Length == 0)
|
||||
return;
|
||||
|
||||
// Validate the key data
|
||||
var cipher = AESCTR.CreateEncryptionCipher(value, TestIV);
|
||||
byte[] actual = cipher.ProcessBytes(TestPattern);
|
||||
if (!actual.EqualsExactly(ExpectedKeyX0x25))
|
||||
return;
|
||||
|
||||
// Assign the validated value
|
||||
field = value;
|
||||
if (ValidateKeyX0x25(value))
|
||||
field = value;
|
||||
}
|
||||
} = [];
|
||||
|
||||
@@ -141,18 +91,8 @@ namespace SabreTools.Security.Cryptography
|
||||
get;
|
||||
set
|
||||
{
|
||||
// Ignore missing key data
|
||||
if (value.Length == 0)
|
||||
return;
|
||||
|
||||
// Validate the key data
|
||||
var cipher = AESCTR.CreateEncryptionCipher(value, TestIV);
|
||||
byte[] actual = cipher.ProcessBytes(TestPattern);
|
||||
if (!actual.EqualsExactly(ExpectedDevKeyX0x25))
|
||||
return;
|
||||
|
||||
// Assign the validated value
|
||||
field = value;
|
||||
if (ValidateDevKeyX0x25(value))
|
||||
field = value;
|
||||
}
|
||||
} = [];
|
||||
|
||||
@@ -164,18 +104,8 @@ namespace SabreTools.Security.Cryptography
|
||||
get;
|
||||
set
|
||||
{
|
||||
// Ignore missing key data
|
||||
if (value.Length == 0)
|
||||
return;
|
||||
|
||||
// Validate the key data
|
||||
var cipher = AESCTR.CreateEncryptionCipher(value, TestIV);
|
||||
byte[] actual = cipher.ProcessBytes(TestPattern);
|
||||
if (!actual.EqualsExactly(ExpectedKeyX0x2C))
|
||||
return;
|
||||
|
||||
// Assign the validated value
|
||||
field = value;
|
||||
if (ValidateKeyX0x2C(value))
|
||||
field = value;
|
||||
}
|
||||
} = [];
|
||||
|
||||
@@ -187,18 +117,8 @@ namespace SabreTools.Security.Cryptography
|
||||
get;
|
||||
set
|
||||
{
|
||||
// Ignore missing key data
|
||||
if (value.Length == 0)
|
||||
return;
|
||||
|
||||
// Validate the key data
|
||||
var cipher = AESCTR.CreateEncryptionCipher(value, TestIV);
|
||||
byte[] actual = cipher.ProcessBytes(TestPattern);
|
||||
if (!actual.EqualsExactly(ExpectedDevKeyX0x2C))
|
||||
return;
|
||||
|
||||
// Assign the validated value
|
||||
field = value;
|
||||
if (ValidateDevKeyX0x2C(value))
|
||||
field = value;
|
||||
}
|
||||
} = [];
|
||||
|
||||
@@ -349,5 +269,145 @@ namespace SabreTools.Security.Cryptography
|
||||
];
|
||||
|
||||
#endregion
|
||||
|
||||
#region Validation Methods
|
||||
|
||||
/// <summary>
|
||||
/// Validate a possible KeyX0x18 value
|
||||
/// </summary>
|
||||
/// <param name="key">Key to test</param>
|
||||
/// <returns>True if the key was valid, false otherwise</returns>
|
||||
public bool ValidateKeyX0x18(byte[]? key)
|
||||
{
|
||||
// Missing key data is considered invalid
|
||||
if (key is null || key.Length == 0)
|
||||
return false;
|
||||
|
||||
// Validate the key data
|
||||
var cipher = AESCTR.CreateEncryptionCipher(key, TestIV);
|
||||
byte[] actual = cipher.ProcessBytes(TestPattern);
|
||||
return actual.EqualsExactly(ExpectedKeyX0x18);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate a possible DevKeyX0x18 value
|
||||
/// </summary>
|
||||
/// <param name="key">Key to test</param>
|
||||
/// <returns>True if the key was valid, false otherwise</returns>
|
||||
public bool ValidateDevKeyX0x18(byte[]? key)
|
||||
{
|
||||
// Missing key data is considered invalid
|
||||
if (key is null || key.Length == 0)
|
||||
return false;
|
||||
|
||||
// Validate the key data
|
||||
var cipher = AESCTR.CreateEncryptionCipher(key, TestIV);
|
||||
byte[] actual = cipher.ProcessBytes(TestPattern);
|
||||
return actual.EqualsExactly(ExpectedDevKeyX0x18);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate a possible KeyX0x1B value
|
||||
/// </summary>
|
||||
/// <param name="key">Key to test</param>
|
||||
/// <returns>True if the key was valid, false otherwise</returns>
|
||||
public bool ValidateKeyX0x1B(byte[]? key)
|
||||
{
|
||||
// Missing key data is considered invalid
|
||||
if (key is null || key.Length == 0)
|
||||
return false;
|
||||
|
||||
// Validate the key data
|
||||
var cipher = AESCTR.CreateEncryptionCipher(key, TestIV);
|
||||
byte[] actual = cipher.ProcessBytes(TestPattern);
|
||||
return actual.EqualsExactly(ExpectedKeyX0x1B);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate a possible DevKeyX0x1B value
|
||||
/// </summary>
|
||||
/// <param name="key">Key to test</param>
|
||||
/// <returns>True if the key was valid, false otherwise</returns>
|
||||
public bool ValidateDevKeyX0x1B(byte[]? key)
|
||||
{
|
||||
// Missing key data is considered invalid
|
||||
if (key is null || key.Length == 0)
|
||||
return false;
|
||||
|
||||
// Validate the key data
|
||||
var cipher = AESCTR.CreateEncryptionCipher(key, TestIV);
|
||||
byte[] actual = cipher.ProcessBytes(TestPattern);
|
||||
return actual.EqualsExactly(ExpectedDevKeyX0x1B);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate a possible KeyX0x25 value
|
||||
/// </summary>
|
||||
/// <param name="key">Key to test</param>
|
||||
/// <returns>True if the key was valid, false otherwise</returns>
|
||||
public bool ValidateKeyX0x25(byte[]? key)
|
||||
{
|
||||
// Missing key data is considered invalid
|
||||
if (key is null || key.Length == 0)
|
||||
return false;
|
||||
|
||||
// Validate the key data
|
||||
var cipher = AESCTR.CreateEncryptionCipher(key, TestIV);
|
||||
byte[] actual = cipher.ProcessBytes(TestPattern);
|
||||
return actual.EqualsExactly(ExpectedKeyX0x25);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate a possible DevKeyX0x25 value
|
||||
/// </summary>
|
||||
/// <param name="key">Key to test</param>
|
||||
/// <returns>True if the key was valid, false otherwise</returns>
|
||||
public bool ValidateDevKeyX0x25(byte[]? key)
|
||||
{
|
||||
// Missing key data is considered invalid
|
||||
if (key is null || key.Length == 0)
|
||||
return false;
|
||||
|
||||
// Validate the key data
|
||||
var cipher = AESCTR.CreateEncryptionCipher(key, TestIV);
|
||||
byte[] actual = cipher.ProcessBytes(TestPattern);
|
||||
return actual.EqualsExactly(ExpectedDevKeyX0x25);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate a possible KeyX0x2C value
|
||||
/// </summary>
|
||||
/// <param name="key">Key to test</param>
|
||||
/// <returns>True if the key was valid, false otherwise</returns>
|
||||
public bool ValidateKeyX0x2C(byte[]? key)
|
||||
{
|
||||
// Missing key data is considered invalid
|
||||
if (key is null || key.Length == 0)
|
||||
return false;
|
||||
|
||||
// Validate the key data
|
||||
var cipher = AESCTR.CreateEncryptionCipher(key, TestIV);
|
||||
byte[] actual = cipher.ProcessBytes(TestPattern);
|
||||
return actual.EqualsExactly(ExpectedKeyX0x2C);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate a possible DevKeyX0x2C value
|
||||
/// </summary>
|
||||
/// <param name="key">Key to test</param>
|
||||
/// <returns>True if the key was valid, false otherwise</returns>
|
||||
public bool ValidateDevKeyX0x2C(byte[]? key)
|
||||
{
|
||||
// Missing key data is considered invalid
|
||||
if (key is null || key.Length == 0)
|
||||
return false;
|
||||
|
||||
// Validate the key data
|
||||
var cipher = AESCTR.CreateEncryptionCipher(key, TestIV);
|
||||
byte[] actual = cipher.ProcessBytes(TestPattern);
|
||||
return actual.EqualsExactly(ExpectedDevKeyX0x2C);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user