♻️ Move the keys store out of the publisher meta

This commit is contained in:
2025-12-30 01:44:05 +08:00
parent 777c0c089a
commit 6a360fe697
6 changed files with 2774 additions and 13 deletions

View File

@@ -161,20 +161,24 @@ public class ActivityPubSignatureService(
private string? GetPublisherKey(SnPublisher publisher, string keyName)
{
if (publisher.Meta == null)
return null;
var metadata = publisher.Meta as Dictionary<string, object>;
return metadata?.GetValueOrDefault(keyName)?.ToString();
return keyName switch
{
"private_key" => publisher.PrivateKeyPem,
"public_key" => publisher.PublicKeyPem,
_ => null
};
}
private void SavePublisherKey(SnPublisher publisher, string keyName, string keyValue)
{
publisher.Meta ??= new Dictionary<string, object>();
var metadata = publisher.Meta as Dictionary<string, object>;
if (metadata != null)
switch (keyName)
{
metadata[keyName] = keyValue;
case "private_key":
publisher.PrivateKeyPem = keyValue;
break;
case "public_key":
publisher.PublicKeyPem = keyValue;
break;
}
}