Skip to content

Commit

Permalink
Fixes decoding (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
JBosecker committed Jan 10, 2021
1 parent bf6706e commit 778e00d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/ExtrasBase64/Chromium.swift
Expand Up @@ -341,7 +341,7 @@ extension Base64 {
}

// inIndex is the first index in the last chunk
let inIndex = fullchunks > 1 ? fullchunks * 4 : 0
let inIndex = fullchunks * 4
let a0 = inBuffer[inIndex]
let a1 = inBuffer[inIndex + 1]
var a2: UInt8?
Expand Down
24 changes: 24 additions & 0 deletions Tests/ExtrasBase64Tests/ChromiumTests.swift
Expand Up @@ -86,6 +86,30 @@ class ChromiumTests: XCTestCase {
}
}

func testBase64DecodingOneTwoThreeFour() {
let base64 = "AQIDBA=="
let bytes: [UInt8] = [1, 2, 3, 4]

XCTAssertEqual(Base64.encodeString(bytes: bytes), base64)
XCTAssertEqual(try Base64.decode(string: base64), bytes)
}

func testBase64DecodingOneTwoThreeFourFive() {
let base64 = "AQIDBAU="
let bytes: [UInt8] = [1, 2, 3, 4, 5]

XCTAssertEqual(Base64.encodeString(bytes: bytes), base64)
XCTAssertEqual(try Base64.decode(string: base64), bytes)
}

func testBase64DecodingOneTwoThreeFourFiveSix() {
let base64 = "AQIDBAUG"
let bytes: [UInt8] = [1, 2, 3, 4, 5, 6]

XCTAssertEqual(Base64.encodeString(bytes: bytes), base64)
XCTAssertEqual(try Base64.decode(string: base64), bytes)
}

func testBase64DecodingWithInvalidLength() {
XCTAssertThrowsError(_ = try Base64.decode(bytes: "AAAAA".utf8)) { error in
XCTAssertEqual(error as? DecodingError, .invalidLength)
Expand Down

0 comments on commit 778e00d

Please sign in to comment.