Skip to content

Commit e9885ff

Browse files
committed
cleanup
1 parent c310739 commit e9885ff

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
@@ -423,23 +423,11 @@ extension Base64 {
423423

424424
extension Base64 {
425425

426-
struct DecodingError: Error, Equatable {
427-
fileprivate enum _Internal: Error, Equatable {
428-
case invalidLength
429-
case invalidCharacter(UInt8)
430-
case unexpectedPaddingCharacter
431-
case unexpectedEnd
432-
}
433-
434-
fileprivate let value: _Internal
435-
fileprivate init(_ value: _Internal) {
436-
self.value = value
437-
}
438-
439-
static var invalidLength: Self { .init(.invalidLength) }
440-
static func invalidCharacter(_ character: UInt8) -> Self { .init(.invalidCharacter(character)) }
441-
static var unexpectedPaddingCharacter: Self { .init(.unexpectedPaddingCharacter) }
442-
static var unexpectedEnd: Self { .init(.unexpectedEnd) }
426+
enum DecodingError: Error, Equatable {
427+
case invalidLength
428+
case invalidCharacter(UInt8)
429+
case unexpectedPaddingCharacter
430+
case unexpectedEnd
443431
}
444432

445433
static func decode(string encoded: String, options: Data.Base64DecodingOptions = []) throws(DecodingError) -> Data {
@@ -726,15 +714,20 @@ extension Base64 {
726714
assert(decoding2.count == 256)
727715
assert(decoding3.count == 256)
728716

729-
return try decoding0.withUnsafeBufferPointer { d0 throws(E) -> R in
730-
try decoding1.withUnsafeBufferPointer { d1 throws(E) -> R in
731-
try decoding2.withUnsafeBufferPointer { d2 throws(E) -> R in
732-
try decoding3.withUnsafeBufferPointer { d3 throws(E) -> R in
733-
try body(d0, d1, d2, d3)
717+
// Workaround that `withUnsafeBufferPointer` started to support typed throws in Swift 6.1
718+
let result = decoding0.withUnsafeBufferPointer { d0 -> Result<R, E> in
719+
decoding1.withUnsafeBufferPointer { d1 -> Result<R, E> in
720+
decoding2.withUnsafeBufferPointer { d2 -> Result<R, E> in
721+
decoding3.withUnsafeBufferPointer { d3 -> Result<R, E> in
722+
Result { () throws(E) -> R in
723+
try body(d0, d1, d2, d3)
724+
}
734725
}
735726
}
736727
}
737728
}
729+
730+
return try result.get()
738731
}
739732

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

0 commit comments

Comments
 (0)