Files
Nebula-Auth/SteamLibForked/Utility/MafileSerialization/MafileSerializer_Validate.cs
T
achiez 8ff960189e 1.5.6 Bug fixes and code clean-ups
- Update: Added "Copy Password" to Mafile context menu (if available)
- Update: "Save Password" now pre-fills the current password in the "Login Again" dialog when encryption is enabled
- Fix: Prevented overlapping confirmation cycles in AutoConfirmer
- Fix: Added a Snackbar notification when a confirmation cycle is skipped due to a too frequent timer interval
- Fix: Fixed a rare bug where the previous proxy was used instead of the current one during session refresh
- Fix: Corrected "Session Permanently Expired" message showing on unrelated errors (e.g. network issues)
- UI-Fix: Fixed visual glitch where proxy input appeared non-empty when switching to a mafile-specific proxy
- Cleanup: Refactored and cleaned up codebase, improved styling and formatting via ReSharper
2025-05-02 23:29:24 +03:00

72 lines
2.5 KiB
C#

using System.Diagnostics.CodeAnalysis;
using Newtonsoft.Json.Linq;
using SteamLib.Account;
using SteamLib.Authentication;
namespace SteamLib.Utility.MafileSerialization;
public partial class MafileSerializer //Validate
{
private static class Validate
{
public static void NotNull(string name, [NotNull] object? o)
{
if (o == null)
{
throw new ArgumentNullException(name, $"{name} is null");
}
}
public static void NotNull(string name, [NotNull] JToken? o)
{
if (o == null || o.Type == JTokenType.Null)
{
throw new ArgumentNullException(name, $"{name} is null");
}
}
public static void NotNullOrEmpty(string name, [NotNull] string? s)
{
if (string.IsNullOrWhiteSpace(s))
{
throw new ArgumentException($"{name} is null or empty");
}
}
public static void IsValidBase64(string name, string base64)
{
var buffer = new Span<byte>(new byte[base64.Length]);
if (Convert.TryFromBase64String(base64, buffer, out _) == false)
throw new ArgumentException($"{name} is not valid base64 string");
}
public static MobileSessionData? ValidateMobileData(MobileData data,
out DeserializedMafileSessionResult sessionResult)
{
NotNullOrEmpty(nameof(data.SharedSecret), data.SharedSecret);
NotNullOrEmpty(nameof(data.IdentitySecret), data.IdentitySecret);
NotNullOrEmpty(nameof(data.DeviceId), data.DeviceId);
IsValidBase64(nameof(data.SharedSecret), data.SharedSecret);
IsValidBase64(nameof(data.IdentitySecret), data.IdentitySecret);
sessionResult = DeserializedMafileSessionResult.Missing;
if (data is MobileDataExtended d)
{
NotNullOrEmpty(nameof(MobileDataExtended.AccountName), d.AccountName);
NotNullOrEmpty(nameof(MobileDataExtended.RevocationCode), d.RevocationCode);
if (d.SessionData == null) return null;
sessionResult = DeserializedMafileSessionResult.Invalid;
d.SessionData.IsValid = SessionDataValidator.Validate(null, d.SessionData).Succeeded;
if (d.SessionData.IsValid == false) return null;
sessionResult = DeserializedMafileSessionResult.Valid;
return d.SessionData;
}
return null;
}
}
}