Skip to content

Commit

Permalink
Add OciDigestAlgorithm parameter to OciDataDescriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtSilvio committed Jul 10, 2024
1 parent 35cdd0e commit ad71b1e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ internal data class OciDescriptorImpl(
internal class OciDataDescriptor(
override val mediaType: String,
val data: ByteArray,
digestAlgorithm: OciDigestAlgorithm,
override val annotations: SortedMap<String, String>,
) : OciDescriptor {
override val digest = data.calculateOciDigest(OciDigestAlgorithm.SHA_256)
override val digest = data.calculateOciDigest(digestAlgorithm)
override val size get() = data.size.toLong()
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ internal fun createConfig(platform: Platform, variants: List<OciVariant>): 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<OciVariant>): OciDataDescriptor {
Expand All @@ -100,7 +105,12 @@ internal fun createManifest(configDescriptor: OciDescriptor, variants: List<OciV
addString("mediaType", MANIFEST_MEDIA_TYPE)
addNumber("schemaVersion", 2)
}.toByteArray()
return OciDataDescriptor(MANIFEST_MEDIA_TYPE, data, lastVariantMetadata.manifestDescriptorAnnotations) // TODO lastVariantMetadata?
return OciDataDescriptor(
MANIFEST_MEDIA_TYPE,
data,
OciDigestAlgorithm.SHA_256,
lastVariantMetadata.manifestDescriptorAnnotations, // TODO lastVariantMetadata?
)
}

internal fun createIndex(platformToImage: Map<Platform, OciImage>): OciDataDescriptor {
Expand All @@ -124,7 +134,7 @@ internal fun createIndex(platformToImage: Map<Platform, OciImage>): 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) {
Expand Down

0 comments on commit ad71b1e

Please sign in to comment.