From c2613aab129c8d1d5aba3b7ed02609059a826c84 Mon Sep 17 00:00:00 2001 From: Rory& Date: Wed, 16 Jul 2025 19:00:05 +0200 Subject: Federation tuff --- LibMatrix/Abstractions/VersionedKeyId.cs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 LibMatrix/Abstractions/VersionedKeyId.cs (limited to 'LibMatrix/Abstractions/VersionedKeyId.cs') diff --git a/LibMatrix/Abstractions/VersionedKeyId.cs b/LibMatrix/Abstractions/VersionedKeyId.cs new file mode 100644 index 0000000..0a6d651 --- /dev/null +++ b/LibMatrix/Abstractions/VersionedKeyId.cs @@ -0,0 +1,24 @@ +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; + +namespace LibMatrix.Abstractions; + +[DebuggerDisplay("{Algorithm}:{KeyId}")] +[SuppressMessage("ReSharper", "NonReadonlyMemberInGetHashCode")] +public class VersionedKeyId { + public required string Algorithm { get; set; } + public required string KeyId { get; set; } + + public static implicit operator VersionedKeyId(string key) { + var parts = key.Split(':', 2); + if (parts.Length != 2) throw new ArgumentException("Invalid key format. Expected 'algorithm:keyId'.", nameof(key)); + return new VersionedKeyId { Algorithm = parts[0], KeyId = parts[1] }; + } + + public static implicit operator string(VersionedKeyId key) => $"{key.Algorithm}:{key.KeyId}"; + public static implicit operator (string, string)(VersionedKeyId key) => (key.Algorithm, key.KeyId); + public static implicit operator VersionedKeyId((string algorithm, string keyId) key) => (key.algorithm, key.keyId); + + public override bool Equals(object? obj) => obj is VersionedKeyId other && Algorithm == other.Algorithm && KeyId == other.KeyId; + public override int GetHashCode() => HashCode.Combine(Algorithm, KeyId); +} \ No newline at end of file -- cgit 1.5.1