allow again the push

This commit is contained in:
Paul Schneider 2026-07-05 21:44:49 +01:00
commit a78847dbc9
5 changed files with 94 additions and 7 deletions

View file

@ -9,24 +9,56 @@ namespace isnd.Helpers
{
private const byte LegacyDelta = 145;
public static string UnprotectWithFallback(IDataProtector protector, string protectedValue)
public static string TryUnprotectKey(IDataProtector protector, string protectedValue)
{
if (string.IsNullOrWhiteSpace(protectedValue))
{
return protectedValue;
}
if (TryUnprotect(protector, protectedValue, out var unprotected))
{
return unprotected;
}
if (TryUnprotectLegacy(protectedValue, out unprotected))
{
return unprotected;
}
return protectedValue;
}
private static bool TryUnprotect(IDataProtector protector, string protectedValue, out string unprotected)
{
try
{
return protector.Unprotect(protectedValue);
unprotected = protector.Unprotect(protectedValue);
return true;
}
catch (CryptographicException)
{
return UnprotectLegacy(protectedValue);
unprotected = null;
return false;
}
catch (FormatException)
{
return UnprotectLegacy(protectedValue);
unprotected = null;
return false;
}
}
private static bool TryUnprotectLegacy(string protectedValue, out string unprotected)
{
try
{
unprotected = UnprotectLegacy(protectedValue);
return true;
}
catch (FormatException)
{
unprotected = null;
return false;
}
}