Skip to content

Commit cdd28e8

Browse files
committed
cleanup
1 parent 2fb0ff4 commit cdd28e8

File tree

1 file changed

+15
-22
lines changed

1 file changed

+15
-22
lines changed

Sources/FoundationEssentials/Data/Data+Base64.swift

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -412,23 +412,11 @@ extension Base64 {
412412

413413
extension Base64 {
414414

415-
struct DecodingError: Error, Equatable {
416-
fileprivate enum _Internal: Error, Equatable {
417-
case invalidLength
418-
case invalidCharacter(UInt8)
419-
case unexpectedPaddingCharacter
420-
case unexpectedEnd
421-
}
422-
423-
fileprivate let value: _Internal
424-
fileprivate init(_ value: _Internal) {
425-
self.value = value
426-
}
427-
428-
static var invalidLength: Self { .init(.invalidLength) }
429-
static func invalidCharacter(_ character: UInt8) -> Self { .init(.invalidCharacter(character)) }
430-
static var unexpectedPaddingCharacter: Self { .init(.unexpectedPaddingCharacter) }
431-
static var unexpectedEnd: Self { .init(.unexpectedEnd) }
415+
enum DecodingError: Error, Equatable {
416+
case invalidLength
417+
case invalidCharacter(UInt8)
418+
case unexpectedPaddingCharacter
419+
case unexpectedEnd
432420
}
433421

434422
static func decode(string encoded: String, options: Data.Base64DecodingOptions = []) throws(DecodingError) -> Data {
@@ -715,15 +703,20 @@ extension Base64 {
715703
assert(decoding2.count == 256)
716704
assert(decoding3.count == 256)
717705

718-
return try decoding0.withUnsafeBufferPointer { d0 throws(E) -> R in
719-
try decoding1.withUnsafeBufferPointer { d1 throws(E) -> R in
720-
try decoding2.withUnsafeBufferPointer { d2 throws(E) -> R in
721-
try decoding3.withUnsafeBufferPointer { d3 throws(E) -> R in
722-
try body(d0, d1, d2, d3)
706+
// Workaround that `withUnsafeBufferPointer` started to support typed throws in Swift 6.1
707+
let result = decoding0.withUnsafeBufferPointer { d0 -> Result<R, E> in
708+
decoding1.withUnsafeBufferPointer { d1 -> Result<R, E> in
709+
decoding2.withUnsafeBufferPointer { d2 -> Result<R, E> in
710+
decoding3.withUnsafeBufferPointer { d3 -> Result<R, E> in
711+
Result { () throws(E) -> R in
712+
try body(d0, d1, d2, d3)
713+
}
723714
}
724715
}
725716
}
726717
}
718+
719+
return try result.get()
727720
}
728721

729722
static func isValidBase64Byte(_ byte: UInt8, options: Data.Base64DecodingOptions) -> Bool {

0 commit comments

Comments
 (0)