Skip to content

Commit

Permalink
Merge pull request #15 from tonkeeper/fixes/bitstring
Browse files Browse the repository at this point in the history
Bitstring - fix incorrect bounds check
  • Loading branch information
grishamsc authored Jul 28, 2024
2 parents 2f8737e + 8f572c7 commit fe4f967
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
8 changes: 8 additions & 0 deletions Example/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@ target 'ton-swift-example' do
pod 'TonSwift', :path => '../', :testspecs => ['Tests']

end

post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings["IPHONEOS_DEPLOYMENT_TARGET"] = "11.0"
end
end
end
10 changes: 5 additions & 5 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
PODS:
- BigInt (5.2.0)
- TonSwift (0.0.1):
- TonSwift (1.0.3):
- BigInt
- TweetNacl
- TonSwift/Tests (0.0.1):
- TonSwift/Tests (1.0.3):
- BigInt
- TweetNacl
- TweetNacl (1.0.2)
Expand All @@ -23,9 +23,9 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
BigInt: f668a80089607f521586bbe29513d708491ef2f7
TonSwift: 72bbfc1d924a4eebac87c8651afea7d2323771c6
TonSwift: 8263886e6a34c81a721cde1674cc70229a1d0d44
TweetNacl: 3abf4d1d2082b0114e7a67410e300892448951e6

PODFILE CHECKSUM: 4414c00005d2c10cd52b412b3080f767ee316ec4
PODFILE CHECKSUM: adb693e82e588cc090eb72c366a3aff89a95e709

COCOAPODS: 1.12.0
COCOAPODS: 1.15.2
2 changes: 1 addition & 1 deletion Source/TonSwift/Cells/Bitstring.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public struct Bitstring: Hashable {
- returns true if the bit is set, false otherwise
*/
public func at(_ index: Int) throws -> Bit {
guard index <= _length && index >= 0 else {
guard index < _length && index >= 0 else {
throw TonError.indexOutOfBounds(index)
}

Expand Down
2 changes: 1 addition & 1 deletion Source/TonSwift/Util/TonError.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

public enum TonError: Error {
public enum TonError: Error, Equatable {
case indexOutOfBounds(Int)
case offsetOutOfBounds(Int)
case custom(String)
Expand Down
16 changes: 16 additions & 0 deletions Tests/TonSwiftTests/Cells/BitStringTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,20 @@ final class BitStringTest: XCTestCase {
XCTAssertEqual(r.toString(), hex)
}
}

func testCorrectBoundsCheckForBitAccess() throws {
let dataHexString = "00240000000054657374205152207369676e6572"
let offset = 16
let length = 144

let bitstring = try Bitstring(
data: Data(hex: dataHexString)!,
offset: offset,
length: length
)

XCTAssertThrowsError(try bitstring.at(144)) { error in
XCTAssertEqual(error as! TonError, TonError.indexOutOfBounds(144))
}
}
}

0 comments on commit fe4f967

Please sign in to comment.