From ad71b1e0d178b33914b30135d186afd3648dc3e9 Mon Sep 17 00:00:00 2001 From: Silvio Giebl Date: Wed, 10 Jul 2024 11:43:03 +0200 Subject: [PATCH] Add OciDigestAlgorithm parameter to OciDataDescriptor --- .../gradle/oci/metadata/OciDescriptor.kt | 3 ++- .../gradle/oci/metadata/OciMetadataFiles.kt | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/metadata/OciDescriptor.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/metadata/OciDescriptor.kt index fe680496..b2691997 100644 --- a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/metadata/OciDescriptor.kt +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/metadata/OciDescriptor.kt @@ -22,8 +22,9 @@ internal data class OciDescriptorImpl( internal class OciDataDescriptor( override val mediaType: String, val data: ByteArray, + digestAlgorithm: OciDigestAlgorithm, override val annotations: SortedMap, ) : OciDescriptor { - override val digest = data.calculateOciDigest(OciDigestAlgorithm.SHA_256) + override val digest = data.calculateOciDigest(digestAlgorithm) override val size get() = data.size.toLong() } diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/metadata/OciMetadataFiles.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/metadata/OciMetadataFiles.kt index d2fbed53..c784c748 100644 --- a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/metadata/OciMetadataFiles.kt +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/metadata/OciMetadataFiles.kt @@ -81,7 +81,12 @@ internal fun createConfig(platform: Platform, variants: List): OciDa } addStringIfNotEmpty("variant", platform.variant) }.toByteArray() - return OciDataDescriptor(CONFIG_MEDIA_TYPE, data, lastVariantMetadata.configDescriptorAnnotations) // TODO lastVariantMetadata? + return OciDataDescriptor( + CONFIG_MEDIA_TYPE, + data, + OciDigestAlgorithm.SHA_256, + lastVariantMetadata.configDescriptorAnnotations, // TODO lastVariantMetadata? + ) } internal fun createManifest(configDescriptor: OciDescriptor, variants: List): OciDataDescriptor { @@ -100,7 +105,12 @@ internal fun createManifest(configDescriptor: OciDescriptor, variants: List): OciDataDescriptor { @@ -124,7 +134,7 @@ internal fun createIndex(platformToImage: Map): OciDataDescr addString("mediaType", INDEX_MEDIA_TYPE) addNumber("schemaVersion", 2) }.toByteArray() - return OciDataDescriptor(INDEX_MEDIA_TYPE, data, TreeMap()) + return OciDataDescriptor(INDEX_MEDIA_TYPE, data, OciDigestAlgorithm.SHA_256, TreeMap()) } private fun JsonObjectStringBuilder.encodeOciDescriptor(descriptor: OciDescriptor) {