mirror of
https://github.com/bitwarden/server
synced 2026-01-02 16:43:25 +00:00
fix(auth-validator): [PM-22975] Client Version Validator - Minor touchups to baserequest validator.
This commit is contained in:
@@ -10,36 +10,19 @@ public static class EncryptionParsing
|
||||
/// </summary>
|
||||
public static EncryptionType GetEncryptionType(string encString)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(encString))
|
||||
{
|
||||
throw new ArgumentException("Encrypted string cannot be null or empty.", nameof(encString));
|
||||
}
|
||||
|
||||
var parts = encString.Split('.');
|
||||
if (parts.Length == 1)
|
||||
{
|
||||
// No header detected; assume AES CBC variants based on number of pieces
|
||||
var splitParts = encString.Split('|');
|
||||
if (splitParts.Length == 3)
|
||||
{
|
||||
return EncryptionType.AesCbc128_HmacSha256_B64;
|
||||
}
|
||||
|
||||
return EncryptionType.AesCbc256_B64;
|
||||
throw new ArgumentException("Invalid encryption type string.");
|
||||
}
|
||||
|
||||
// Try parse header as numeric, then as enum name, else fail
|
||||
if (byte.TryParse(parts[0], out var encryptionTypeNumber))
|
||||
{
|
||||
return (EncryptionType)encryptionTypeNumber;
|
||||
if (Enum.IsDefined(typeof(EncryptionType), encryptionTypeNumber))
|
||||
{
|
||||
return (EncryptionType)encryptionTypeNumber;
|
||||
}
|
||||
}
|
||||
|
||||
if (Enum.TryParse(parts[0], out EncryptionType parsed))
|
||||
{
|
||||
return parsed;
|
||||
}
|
||||
|
||||
throw new ArgumentException("Invalid encryption type header.", nameof(encString));
|
||||
throw new ArgumentException("Invalid encryption type string.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user