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 Semver; |
||||
using StabilityMatrix.Core.Converters.Json; |
||||
using StabilityMatrix.Core.Extensions; |
||||
|
||||
namespace StabilityMatrix.Core.Models.Update; |
||||
|
||||
[SuppressMessage("ReSharper", "ClassNeverInstantiated.Global")] |
||||
public record UpdateInfo( |
||||
[property: JsonPropertyName("version"), JsonConverter(typeof(SemVersionJsonConverter))] |
||||
SemVersion Version, |
||||
|
||||
[property: JsonPropertyName("releaseDate")] |
||||
DateTimeOffset ReleaseDate, |
||||
|
||||
[property: JsonPropertyName("channel")] |
||||
UpdateChannel Channel, |
||||
|
||||
[property: JsonPropertyName("type")] |
||||
UpdateType Type, |
||||
|
||||
[property: JsonPropertyName("url")] |
||||
string DownloadUrl, |
||||
|
||||
[property: JsonPropertyName("changelog")] |
||||
string ChangelogUrl, |
||||
|
||||
// Blake3 hash of the file |
||||
[property: JsonPropertyName("hashBlake3")] |
||||
string HashBlake3, |
||||
|
||||
// ED25519 signature of the semicolon seperated string: |
||||
// "version + releaseDate + channel + type + url + changelog + hash_blake3" |
||||
// verifiable using our stored public key |
||||
[property: JsonPropertyName("signature")] |
||||
string Signature |
||||
public record UpdateInfo |
||||
{ |
||||
[JsonConverter(typeof(SemVersionJsonConverter))] |
||||
public required SemVersion Version { get; init; } |
||||
|
||||
public required DateTimeOffset ReleaseDate { get; init; } |
||||
|
||||
public UpdateChannel Channel { get; init; } |
||||
|
||||
public UpdateType Type { get; init; } |
||||
|
||||
public required Uri Url { get; init; } |
||||
|
||||
public required Uri Changelog { get; init; } |
||||
|
||||
/// <summary> |
||||
/// Blake3 hash of the file |
||||
/// </summary> |
||||
public required string HashBlake3 { get; init; } |
||||
|
||||
/// <summary> |
||||
/// ED25519 signature of the semicolon seperated string: |
||||
/// "version + releaseDate + channel + type + url + changelog + hash_blake3" |
||||
/// verifiable using our stored public key |
||||
/// </summary> |
||||
public required string Signature { get; init; } |
||||
|
||||
/// <summary> |
||||
/// 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