File tree Expand file tree Collapse file tree 2 files changed +30
-14
lines changed
Sources/ContainerRegistry Expand file tree Collapse file tree 2 files changed +30
-14
lines changed Original file line number Diff line number Diff line change 1414
1515import Foundation
1616import HTTPTypes
17- import struct Crypto. SHA256
18-
19- /// Calculates the digest of a blob of data.
20- /// - Parameter data: Blob of data to digest.
21- /// - Returns: The blob's digest, in the format expected by the distribution protocol.
22- public func digest< D: DataProtocol > ( of data: D ) -> ImageReference . Digest {
23- // SHA256 is required; some registries might also support SHA512
24- let hash = SHA256 . hash ( data: data)
25- let digest = hash. compactMap { String ( format: " %02x " , $0) } . joined ( )
26- return try ! ImageReference . Digest ( " sha256: " + digest)
27- }
2817
2918extension RegistryClient {
3019 // Internal helper method to initiate a blob upload in 'two shot' mode
@@ -61,9 +50,6 @@ extension RegistryClient {
6150 }
6251}
6352
64- // The spec says that Docker- prefix headers are no longer to be used, but also specifies that the registry digest is returned in this header.
65- extension HTTPField . Name { static let dockerContentDigest = Self ( " Docker-Content-Digest " ) ! }
66-
6753public extension RegistryClient {
6854 func blobExists( repository: ImageReference . Repository , digest: ImageReference . Digest ) async throws -> Bool {
6955 do {
Original file line number Diff line number Diff line change 1+ //===----------------------------------------------------------------------===//
2+ //
3+ // This source file is part of the SwiftContainerPlugin open source project
4+ //
5+ // Copyright (c) 2025 Apple Inc. and the SwiftContainerPlugin project authors
6+ // Licensed under Apache License v2.0
7+ //
8+ // See LICENSE.txt for license information
9+ // See CONTRIBUTORS.txt for the list of SwiftContainerPlugin project authors
10+ //
11+ // SPDX-License-Identifier: Apache-2.0
12+ //
13+ //===----------------------------------------------------------------------===//
14+
15+ import Foundation
16+ import HTTPTypes
17+ import struct Crypto. SHA256
18+
19+ // The spec says that Docker- prefix headers are no longer to be used, but also specifies that the registry digest is returned in this header.
20+ extension HTTPField . Name { static let dockerContentDigest = Self ( " Docker-Content-Digest " ) ! }
21+
22+ /// Calculates the digest of a blob of data.
23+ /// - Parameter data: Blob of data to digest.
24+ /// - Returns: The blob's digest, in the format expected by the distribution protocol.
25+ public func digest( of data: any DataProtocol ) -> ImageReference . Digest {
26+ // SHA256 is required; some registries might also support SHA512
27+ let hash = SHA256 . hash ( data: data)
28+ let digest = hash. compactMap { String ( format: " %02x " , $0) } . joined ( )
29+ return try ! ImageReference . Digest ( " sha256: " + digest)
30+ }
You can’t perform that action at this time.
0 commit comments