From feaf46d3a4c3fe80d9e42df7a383e7aafb1f3f39 Mon Sep 17 00:00:00 2001 From: Patrick Pan Date: Mon, 25 Nov 2024 10:32:51 +1100 Subject: [PATCH] add Index constructor Signed-off-by: Patrick Pan --- src/OrasProject.Oras/Content/Digest.cs | 1 + src/OrasProject.Oras/Oci/Index.cs | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/OrasProject.Oras/Content/Digest.cs b/src/OrasProject.Oras/Content/Digest.cs index 15febfb..374fa35 100644 --- a/src/OrasProject.Oras/Content/Digest.cs +++ b/src/OrasProject.Oras/Content/Digest.cs @@ -46,6 +46,7 @@ internal static string Validate(string? digest) return digest; } + /// /// Generates a SHA-256 digest from a byte array. /// diff --git a/src/OrasProject.Oras/Oci/Index.cs b/src/OrasProject.Oras/Oci/Index.cs index dc81f8d..918588d 100644 --- a/src/OrasProject.Oras/Oci/Index.cs +++ b/src/OrasProject.Oras/Oci/Index.cs @@ -12,6 +12,7 @@ // limitations under the License. using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Text; using System.Text.Json; using System.Text.Json.Serialization; @@ -43,14 +44,19 @@ public class Index : Versioned [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public IDictionary? Annotations { get; set; } + public Index() {} + + [SetsRequiredMembers] + public Index(IList manifests) + { + Manifests = manifests; + MediaType = Oci.MediaType.ImageIndex; + SchemaVersion = 2; + } + internal static (Descriptor, byte[]) GenerateIndex(IList manifests) { - var index = new Index() - { - Manifests = manifests, - MediaType = Oci.MediaType.ImageIndex, - SchemaVersion = 2 - }; + var index = new Index(manifests); var indexContent = JsonSerializer.SerializeToUtf8Bytes(index); return (Descriptor.Create(indexContent, Oci.MediaType.ImageIndex), indexContent); }