Ionite
1 year ago
8 changed files with 206 additions and 150 deletions
@ -1,11 +0,0 @@ |
|||||||
using System.Text.Json.Serialization; |
|
||||||
|
|
||||||
namespace StabilityMatrix.Core.Models.Update; |
|
||||||
|
|
||||||
public record UpdateCollection ( |
|
||||||
[property: JsonPropertyName("win-x64")] |
|
||||||
UpdateInfo? WindowsX64, |
|
||||||
|
|
||||||
[property: JsonPropertyName("linux-x64")] |
|
||||||
UpdateInfo? LinuxX64 |
|
||||||
); |
|
@ -1,37 +1,58 @@ |
|||||||
using System.Diagnostics.CodeAnalysis; |
using System.Globalization; |
||||||
using System.Text.Json.Serialization; |
using System.Text.Json.Serialization; |
||||||
using Semver; |
using Semver; |
||||||
using StabilityMatrix.Core.Converters.Json; |
using StabilityMatrix.Core.Converters.Json; |
||||||
|
using StabilityMatrix.Core.Extensions; |
||||||
|
|
||||||
namespace StabilityMatrix.Core.Models.Update; |
namespace StabilityMatrix.Core.Models.Update; |
||||||
|
|
||||||
[SuppressMessage("ReSharper", "ClassNeverInstantiated.Global")] |
public record UpdateInfo |
||||||
public record UpdateInfo( |
{ |
||||||
[property: JsonPropertyName("version"), JsonConverter(typeof(SemVersionJsonConverter))] |
[JsonConverter(typeof(SemVersionJsonConverter))] |
||||||
SemVersion Version, |
public required SemVersion Version { get; init; } |
||||||
|
|
||||||
[property: JsonPropertyName("releaseDate")] |
public required DateTimeOffset ReleaseDate { get; init; } |
||||||
DateTimeOffset ReleaseDate, |
|
||||||
|
public UpdateChannel Channel { get; init; } |
||||||
[property: JsonPropertyName("channel")] |
|
||||||
UpdateChannel Channel, |
public UpdateType Type { get; init; } |
||||||
|
|
||||||
[property: JsonPropertyName("type")] |
public required Uri Url { get; init; } |
||||||
UpdateType Type, |
|
||||||
|
public required Uri Changelog { get; init; } |
||||||
[property: JsonPropertyName("url")] |
|
||||||
string DownloadUrl, |
/// <summary> |
||||||
|
/// Blake3 hash of the file |
||||||
[property: JsonPropertyName("changelog")] |
/// </summary> |
||||||
string ChangelogUrl, |
public required string HashBlake3 { get; init; } |
||||||
|
|
||||||
// Blake3 hash of the file |
/// <summary> |
||||||
[property: JsonPropertyName("hashBlake3")] |
/// ED25519 signature of the semicolon seperated string: |
||||||
string HashBlake3, |
/// "version + releaseDate + channel + type + url + changelog + hash_blake3" |
||||||
|
/// verifiable using our stored public key |
||||||
// ED25519 signature of the semicolon seperated string: |
/// </summary> |
||||||
// "version + releaseDate + channel + type + url + changelog + hash_blake3" |
public required string Signature { get; init; } |
||||||
// verifiable using our stored public key |
|
||||||
[property: JsonPropertyName("signature")] |
/// <summary> |
||||||
string Signature |
/// Data for use in signature verification. |
||||||
|
/// Semicolon separated string of fields: |
||||||
|
/// "version, releaseDate, channel, type, url, changelog, hashBlake3" |
||||||
|
/// </summary> |
||||||
|
public string GetSignedData() |
||||||
|
{ |
||||||
|
var channel = Channel.GetStringValue().ToLowerInvariant(); |
||||||
|
var date = FormatDateTimeOffsetInvariant(ReleaseDate); |
||||||
|
return $"{Version};{date};{channel};" + $"{(int)Type};{Url};{Changelog};" + $"{HashBlake3}"; |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary> |
||||||
|
/// Format a DatetimeOffset to a culture invariant string for use in signature verification. |
||||||
|
/// </summary> |
||||||
|
private static string FormatDateTimeOffsetInvariant(DateTimeOffset dateTimeOffset) |
||||||
|
{ |
||||||
|
return dateTimeOffset.ToString( |
||||||
|
@"yyyy-MM-ddTHH\:mm\:ss.ffffffzzz", |
||||||
|
CultureInfo.InvariantCulture |
||||||
); |
); |
||||||
|
} |
||||||
|
} |
||||||
|
@ -0,0 +1,17 @@ |
|||||||
|
using System.Text.Json.Serialization; |
||||||
|
|
||||||
|
namespace StabilityMatrix.Core.Models.Update; |
||||||
|
|
||||||
|
[JsonSerializable(typeof(UpdateManifest))] |
||||||
|
public record UpdateManifest |
||||||
|
{ |
||||||
|
public required Dictionary<UpdateChannel, UpdatePlatforms> Updates { get; init; } |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
// TODO: Bugged in .NET 7 but we can use in 8 https://github.com/dotnet/runtime/pull/79828 |
||||||
|
/*[JsonSourceGenerationOptions(PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)] |
||||||
|
[JsonSerializable(typeof(UpdateManifest))] |
||||||
|
public partial class UpdateManifestContext : JsonSerializerContext |
||||||
|
{ |
||||||
|
}*/ |
@ -0,0 +1,28 @@ |
|||||||
|
using System.Text.Json.Serialization; |
||||||
|
using StabilityMatrix.Core.Helper; |
||||||
|
|
||||||
|
namespace StabilityMatrix.Core.Models.Update; |
||||||
|
|
||||||
|
public record UpdatePlatforms |
||||||
|
{ |
||||||
|
[JsonPropertyName("win-x64")] |
||||||
|
public UpdateInfo? WindowsX64 { get; init; } |
||||||
|
|
||||||
|
[JsonPropertyName("linux-x64")] |
||||||
|
public UpdateInfo? LinuxX64 { get; init; } |
||||||
|
|
||||||
|
public UpdateInfo? GetInfoForCurrentPlatform() |
||||||
|
{ |
||||||
|
if (Compat.IsWindows) |
||||||
|
{ |
||||||
|
return WindowsX64; |
||||||
|
} |
||||||
|
|
||||||
|
if (Compat.IsLinux) |
||||||
|
{ |
||||||
|
return LinuxX64; |
||||||
|
} |
||||||
|
|
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue