From d0d790a5cec4f52ccf31710aedbf8032684cf6a6 Mon Sep 17 00:00:00 2001 From: Dynesshely Date: Wed, 6 Mar 2024 08:11:26 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=BE=20Feat:=20Try=20to=20connect=20to?= =?UTF-8?q?=20remote=20device=20and=20get=20token.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../KitX.Shared.CSharp/Device/DeviceKey.cs | 16 ++++++++++++++++ .../KitX.Shared.CSharp/Device/DeviceLocator.cs | 7 +++++++ 2 files changed, 23 insertions(+) diff --git a/KitX Shared/KitX.Shared.CSharp/Device/DeviceKey.cs b/KitX Shared/KitX.Shared.CSharp/Device/DeviceKey.cs index f6fc580..c5078f4 100644 --- a/KitX Shared/KitX.Shared.CSharp/Device/DeviceKey.cs +++ b/KitX Shared/KitX.Shared.CSharp/Device/DeviceKey.cs @@ -12,3 +12,19 @@ public class DeviceKey public string? RsaPrivateKeyD { get; set; } } + +public static class DeviceKeyExtensions +{ + public static bool IsSameKey(this DeviceKey key, DeviceKey other) + { + var result = true; + + if (key.RsaPublicKeyExponent is not null && key.RsaPublicKeyModulus is not null) + result = result && key.RsaPublicKeyExponent == other.RsaPublicKeyExponent && key.RsaPublicKeyModulus == other.RsaPublicKeyModulus; + + if (key.RsaPrivateKeyD is not null && key.RsaPrivateKeyModulus is not null) + result = result && key.RsaPrivateKeyD == other.RsaPrivateKeyD && key.RsaPrivateKeyModulus == other.RsaPrivateKeyModulus; + + return result && key.Device.IsSameDevice(other.Device); + } +} diff --git a/KitX Shared/KitX.Shared.CSharp/Device/DeviceLocator.cs b/KitX Shared/KitX.Shared.CSharp/Device/DeviceLocator.cs index 97e5042..9c8940c 100644 --- a/KitX Shared/KitX.Shared.CSharp/Device/DeviceLocator.cs +++ b/KitX Shared/KitX.Shared.CSharp/Device/DeviceLocator.cs @@ -52,3 +52,10 @@ public override bool Equals(object obj) public override int GetHashCode() => base.GetHashCode(); } + +public static class DeviceLocatorExtensions +{ + public static bool IsSameDevice(this DeviceLocator current, DeviceLocator target) + => current.DeviceName.Equals(target.DeviceName) + && current.MacAddress.Equals(target.MacAddress); +}