Skip to content

Commit

Permalink
allow nil checksums
Browse files Browse the repository at this point in the history
  • Loading branch information
leogdion committed Jan 18, 2024
1 parent a2117b5 commit e4ad292
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
8 changes: 8 additions & 0 deletions Sources/IPSWDownloads/Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,12 @@ extension Data {

self = data
}

Check notice on line 48 in Sources/IPSWDownloads/Data.swift

View check run for this annotation

codefactor.io / CodeFactor

Sources/IPSWDownloads/Data.swift#L48

Lines should not have trailing whitespace. (trailing_whitespace)
internal init?(hexString: String, emptyIsNil: Bool) throws {
if emptyIsNil, hexString.isEmpty {
return nil
}

Check notice on line 53 in Sources/IPSWDownloads/Data.swift

View check run for this annotation

codefactor.io / CodeFactor

Sources/IPSWDownloads/Data.swift#L53

Lines should not have trailing whitespace. (trailing_whitespace)
try self.init(hexString: hexString)
}
}
12 changes: 6 additions & 6 deletions Sources/IPSWDownloads/Firmware.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ public struct Firmware {
public let buildid: String

/// The SHA-1 checksum of the firmware.
public let sha1sum: Data
public let sha1sum: Data?

/// The MD5 checksum of the firmware.
public let md5sum: Data
public let md5sum: Data?

/// The size of the firmware file in bytes.
public let filesize: Int
Expand Down Expand Up @@ -78,8 +78,8 @@ public struct Firmware {
identifier: String,
version: OperatingSystemVersion,
buildid: String,
sha1sum: Data,
md5sum: Data,
sha1sum: Data?,
md5sum: Data?,
filesize: Int,
url: URL,
releasedate: Date,
Expand Down Expand Up @@ -110,8 +110,8 @@ extension Firmware {
identifier: component.identifier,
version: OperatingSystemVersion(string: component.version),
buildid: component.buildid,
sha1sum: Data(hexString: component.sha1sum),
md5sum: Data(hexString: component.md5sum),
sha1sum: Data(hexString: component.sha1sum, emptyIsNil: true),
md5sum: Data(hexString: component.md5sum, emptyIsNil: true),
filesize: component.filesize,
url: URL(validatingURL: component.url),
releasedate: component.releasedate,
Expand Down
6 changes: 6 additions & 0 deletions Tests/IPSWDownloadsTests/DataTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public class DataTests: XCTestCase {

for value in values {
_ = try Data(hexString: value)
try XCTAssertNotNil(Data(hexString: value, emptyIsNil: true))
try XCTAssertNotNil(Data(hexString: value, emptyIsNil: false))
}
}

Expand All @@ -80,4 +82,8 @@ public class DataTests: XCTestCase {
XCTAssertEqual(string, actual)
}
}

func testInitStringEmpty() throws {
try XCTAssertNil(Data(hexString: "", emptyIsNil: true))
}
}

0 comments on commit e4ad292

Please sign in to comment.