@@ -412,23 +412,11 @@ extension Base64 {
412
412
413
413
extension Base64 {
414
414
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
432
420
}
433
421
434
422
static func decode( string encoded: String , options: Data . Base64DecodingOptions = [ ] ) throws ( DecodingError) -> Data {
@@ -715,15 +703,20 @@ extension Base64 {
715
703
assert ( decoding2. count == 256 )
716
704
assert ( decoding3. count == 256 )
717
705
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
+ }
723
714
}
724
715
}
725
716
}
726
717
}
718
+
719
+ return try result. get ( )
727
720
}
728
721
729
722
static func isValidBase64Byte( _ byte: UInt8 , options: Data . Base64DecodingOptions ) -> Bool {
0 commit comments