diff --git a/src/OrasProject.Oras/Content/Digest.cs b/src/OrasProject.Oras/Content/Digest.cs index 15febfb..2e8c035 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. /// @@ -58,4 +59,4 @@ internal static string ComputeSHA256(byte[] content) var output = $"sha256:{BitConverter.ToString(hash).Replace("-", "")}"; return output.ToLower(); } -} +} \ No newline at end of file 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); }