Skip to content

Commit

Permalink
Add availability checks to support macOS 10.15 and equivalent version…
Browse files Browse the repository at this point in the history
…s of other Apple platforms
  • Loading branch information
stackotter committed Sep 1, 2024
1 parent 7a3fbb7 commit d589995
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PackageDescription

let package:Package = .init(
name: "swift-hash",
platforms: [.macOS("13.3"), .iOS("16.4"), .tvOS("16.4"), .watchOS("9.4")],
platforms: [.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6)],
products: [
.library(name: "Base16", targets: ["Base16"]),
.library(name: "Base64", targets: ["Base64"]),
Expand Down
29 changes: 22 additions & 7 deletions Sources/InlineBuffer/InlineBuffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ extension InlineBuffer:RandomAccessCollection, MutableCollection
}
}
}
@available(macOS 13.3, iOS 16.4, macCatalyst 16.4, tvOS 16.4, visionOS 1, watchOS 9.4, *)
extension InlineBuffer:ExpressibleByIntegerLiteral
{
@inlinable public
Expand Down Expand Up @@ -153,18 +154,32 @@ extension InlineBuffer:CustomStringConvertible
@inlinable public
var description:String
{
.init(unsafeUninitializedCapacity: 2 * self.count)
func hex(remainder:UInt8) -> UInt8
{
func hex(remainder:UInt8) -> UInt8
(remainder < 10 ? 0x30 : 0x61 - 10) &+ remainder
}
if #available(macOS 11, iOS 14, macCatalyst 14, tvOS 14, visionOS 1, watchOS 7, *)
{
return .init(unsafeUninitializedCapacity: 2 * self.count)
{
(remainder < 10 ? 0x30 : 0x61 - 10) &+ remainder
for (i, byte):(Int, UInt8) in self.enumerated()
{
$0[2 * i ] = hex(remainder: byte >> 4)
$0[2 * i + 1] = hex(remainder: byte & 0x0f)
}
return 2 * self.count
}
for (i, byte):(Int, UInt8) in self.enumerated()
}
else
{
var description:String = ""
description.reserveCapacity(2 * self.count)
for byte:UInt8 in self
{
$0[2 * i ] = hex(remainder: byte >> 4)
$0[2 * i + 1] = hex(remainder: byte & 0x0f)
description.append(Character.init(.init(hex(remainder: byte >> 4))))
description.append(Character.init(.init(hex(remainder: byte & 0x0f))))
}
return 2 * self.count
return description
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Sources/MD5/MD5.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ extension MD5:LosslessStringConvertible
}
}
}
@available(macOS 13.3, iOS 16.4, macCatalyst 16.4, tvOS 16.4, visionOS 1, watchOS 9.4, *)
extension MD5:ExpressibleByIntegerLiteral
{
@inlinable public
Expand Down
14 changes: 14 additions & 0 deletions Sources/MD5Tests/Main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ enum Main:TestMain, TestBattery
static
func run(tests:TestGroup)
{
guard #available(
macOS 13.3,
iOS 16.4,
macCatalyst 16.4,
tvOS 16.4,
visionOS 1.0,
watchOS 9.4,
*
)
else
{
fatalError("MD5Tests requires macOS 13.3+, iOS 16.4+, tvOS 16.4+, visionOS 1.0+, or watchOS 9.4+")
}

if let tests:TestGroup = tests / "Strings"
{
let string:String = "d41d8cd98f00b204e9800998ecf8427e"
Expand Down
1 change: 1 addition & 0 deletions Sources/SHA1/SHA1.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ extension SHA1:LosslessStringConvertible
}
}
}
@available(macOS 13.3, iOS 16.4, macCatalyst 16.4, tvOS 16.4, visionOS 1, watchOS 9.4, *)
extension SHA1:ExpressibleByIntegerLiteral
{
@inlinable public
Expand Down

0 comments on commit d589995

Please sign in to comment.