Skip to content

Commit 3cd1ffd

Browse files
authored
Preparing for base32 (#15)
1 parent 1767a56 commit 3cd1ffd

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

Sources/Base64Kit/Base64.swift

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,6 @@ extension Base64 {
145145
public static let base64UrlAlphabet = DecodingOptions(rawValue: UInt(1 << 0))
146146
}
147147

148-
public enum DecodingError: Error, Equatable {
149-
case invalidLength
150-
case invalidCharacter(UInt8)
151-
case unexpectedPaddingCharacter
152-
case unexpectedEnd
153-
}
154-
155148
@inlinable
156149
public static func decode<Buffer: Collection>(encoded: Buffer, options: DecodingOptions = [])
157150
throws -> [UInt8] where Buffer.Element == UInt8 {
@@ -304,10 +297,10 @@ extension IteratorProtocol where Self.Element == UInt8 {
304297
}
305298

306299
if value == Base64.paddingCharacter {
307-
throw Base64.DecodingError.unexpectedPaddingCharacter
300+
throw DecodingError.unexpectedPaddingCharacter
308301
}
309302

310-
throw Base64.DecodingError.invalidCharacter(ascii)
303+
throw DecodingError.invalidCharacter(ascii)
311304
}
312305

313306
@inlinable mutating func nextValueOrEmpty(alphabet: [UInt8]) throws -> UInt8? {
@@ -323,7 +316,7 @@ extension IteratorProtocol where Self.Element == UInt8 {
323316
return nil
324317
}
325318

326-
throw Base64.DecodingError.invalidCharacter(ascii)
319+
throw DecodingError.invalidCharacter(ascii)
327320
}
328321
}
329322

Sources/Base64Kit/DecodingError.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
public enum DecodingError: Error, Equatable {
3+
case invalidLength
4+
case invalidCharacter(UInt8)
5+
case unexpectedPaddingCharacter
6+
case unexpectedEnd
7+
}

Tests/Base64KitTests/DecodingTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ class DecodingTests: XCTestCase {
3737

3838
func testBase64DecodingWithPoop() {
3939
XCTAssertThrowsError(_ = try "💩".base64decoded()) { error in
40-
XCTAssertEqual(error as? Base64.DecodingError, .invalidCharacter(240))
40+
XCTAssertEqual(error as? DecodingError, .invalidCharacter(240))
4141
}
4242
}
4343

4444
func testBase64DecodingWithInvalidLength() {
4545
XCTAssertThrowsError(_ = try "AAAAA".base64decoded()) { error in
46-
XCTAssertEqual(error as? Base64.DecodingError, .invalidLength)
46+
XCTAssertEqual(error as? DecodingError, .invalidLength)
4747
}
4848
}
4949

0 commit comments

Comments
 (0)