Skip to content

Fixes #22 #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/ExtrasBase64/Chromium.swift
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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