@@ -423,23 +423,11 @@ extension Base64 {
423
423
424
424
extension Base64 {
425
425
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
443
431
}
444
432
445
433
static func decode( string encoded: String , options: Data . Base64DecodingOptions = [ ] ) throws ( DecodingError) -> Data {
@@ -726,15 +714,20 @@ extension Base64 {
726
714
assert ( decoding2. count == 256 )
727
715
assert ( decoding3. count == 256 )
728
716
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
+ }
734
725
}
735
726
}
736
727
}
737
728
}
729
+
730
+ return try result. get ( )
738
731
}
739
732
740
733
static func isValidBase64Byte( _ byte: UInt8 , options: Data . Base64DecodingOptions ) -> Bool {
0 commit comments