Skip to content

Commit

Permalink
fix: Update @available for iOS, watchOS and tvOS (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew-Lees11 authored Jul 2, 2019
1 parent 710321b commit 4a1b8ac
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Sources/SwiftJWT/BlueECDSA.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import LoggerAPI
import Foundation

// Class for ECDSA signing using BlueECC
@available(OSX 10.13, *)
@available(OSX 10.13, iOS 11, tvOS 11.0, watchOS 4.0, *)
class BlueECSigner: SignerAlgorithm {
let name: String = "ECDSA"

Expand Down Expand Up @@ -58,7 +58,7 @@ class BlueECSigner: SignerAlgorithm {
}

// Class for ECDSA verifying using BlueECC
@available(OSX 10.13, *)
@available(OSX 10.13, iOS 11, tvOS 11.0, watchOS 4.0, *)
class BlueECVerifier: VerifierAlgorithm {

let name: String = "ECDSA"
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftJWT/BlueRSA.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class BlueRSA: SignerAlgorithm, VerifierAlgorithm {
}

func sign(_ data: Data) throws -> Data {
guard #available(macOS 10.12, iOS 10.0, *) else {
guard #available(macOS 10.12, iOS 10.3, tvOS 12.0, watchOS 3.3, *) else {
Log.error("macOS 10.12.0 (Sierra) or higher or iOS 10.0 or higher is required by CryptorRSA")
throw JWTError.osVersionToLow
}
Expand Down Expand Up @@ -76,7 +76,7 @@ class BlueRSA: SignerAlgorithm, VerifierAlgorithm {
}

func verify(signature: Data, for data: Data) -> Bool {
guard #available(macOS 10.12, iOS 10.0, *) else {
guard #available(macOS 10.12, iOS 10.3, tvOS 12.0, watchOS 3.3, *) else {
return false
}
do {
Expand Down
6 changes: 3 additions & 3 deletions Sources/SwiftJWT/JWTSigner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,21 +122,21 @@ public struct JWTSigner {

/// Initialize a JWTSigner using the ECDSA SHA256 algorithm and the provided privateKey.
/// - Parameter privateKey: The UTF8 encoded PEM private key, with either a "BEGIN EC PRIVATE KEY" or "BEGIN PRIVATE KEY" header.
@available(OSX 10.13, *)
@available(OSX 10.13, iOS 11, tvOS 11.0, watchOS 4.0, *)
public static func es256(privateKey: Data) -> JWTSigner {
return JWTSigner(name: "ES256", signerAlgorithm: BlueECSigner(key: privateKey, curve: .prime256v1))
}

/// Initialize a JWTSigner using the ECDSA SHA384 algorithm and the provided privateKey.
/// - Parameter privateKey: The UTF8 encoded PEM private key, with either a "BEGIN EC PRIVATE KEY" or "BEGIN PRIVATE KEY" header.
@available(OSX 10.13, *)
@available(OSX 10.13, iOS 11, tvOS 11.0, watchOS 4.0, *)
public static func es384(privateKey: Data) -> JWTSigner {
return JWTSigner(name: "ES384", signerAlgorithm: BlueECSigner(key: privateKey, curve: .secp384r1))
}

/// Initialize a JWTSigner using the ECDSA SHA512 algorithm and the provided privateKey.
/// - Parameter privateKey: The UTF8 encoded PEM private key, with either a "BEGIN EC PRIVATE KEY" or "BEGIN PRIVATE KEY" header.
@available(OSX 10.13, *)
@available(OSX 10.13, iOS 11, tvOS 11.0, watchOS 4.0, *)
public static func es512(privateKey: Data) -> JWTSigner {
return JWTSigner(name: "ES512", signerAlgorithm: BlueECSigner(key: privateKey, curve: .secp521r1))
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/SwiftJWT/JWTVerifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,21 +128,21 @@ public struct JWTVerifier {

/// Initialize a JWTVerifier using the ECDSA SHA 256 algorithm and the provided public key.
/// - Parameter publicKey: The UTF8 encoded PEM public key, with a "BEGIN PUBLIC KEY" header.
@available(OSX 10.13, *)
@available(OSX 10.13, iOS 11, tvOS 11.0, watchOS 4.0, *)
public static func es256(publicKey: Data) -> JWTVerifier {
return JWTVerifier(verifierAlgorithm: BlueECVerifier(key: publicKey, curve: .prime256v1))
}

/// Initialize a JWTVerifier using the ECDSA SHA 384 algorithm and the provided public key.
/// - Parameter publicKey: The UTF8 encoded PEM public key, with a "BEGIN PUBLIC KEY" header.
@available(OSX 10.13, *)
@available(OSX 10.13, iOS 11, tvOS 11.0, watchOS 4.0, *)
public static func es384(publicKey: Data) -> JWTVerifier {
return JWTVerifier(verifierAlgorithm: BlueECVerifier(key: publicKey, curve: .secp384r1))
}

/// Initialize a JWTVerifier using the ECDSA SHA 512 algorithm and the provided public key.
/// - Parameter publicKey: The UTF8 encoded PEM public key, with a "BEGIN PUBLIC KEY" header.
@available(OSX 10.13, *)
@available(OSX 10.13, iOS 11, tvOS 11.0, watchOS 4.0, *)
public static func es512(publicKey: Data) -> JWTVerifier {
return JWTVerifier(verifierAlgorithm: BlueECVerifier(key: publicKey, curve: .secp521r1))
}
Expand Down
10 changes: 5 additions & 5 deletions Tests/SwiftJWTTests/TestJWT.swift
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class TestJWT: XCTestCase {
}

func testSignAndVerifyECDSA() {
if #available(OSX 10.13, *) {
if #available(OSX 10.13, iOS 11, tvOS 11.0, watchOS 4.0, *) {
do {
try signAndVerify(signer: .es256(privateKey: ecdsaPrivateKey), verifier: .es256(publicKey: ecdsaPublicKey))
} catch {
Expand Down Expand Up @@ -231,7 +231,7 @@ class TestJWT: XCTestCase {
}

func testSignAndVerifyECDSA384() {
if #available(OSX 10.13, *) {
if #available(OSX 10.13, iOS 11, tvOS 11.0, watchOS 4.0, *) {
do {
try signAndVerify(signer: .es384(privateKey: ec384PrivateKey), verifier: .es384(publicKey: ec384PublicKey))
} catch {
Expand All @@ -249,7 +249,7 @@ class TestJWT: XCTestCase {
}

func testSignAndVerifyRSAPSS512() {
if #available(OSX 10.13, *) {
if #available(OSX 10.13, iOS 11, *) {
do {
try signAndVerify(signer: .ps512(privateKey: rsaPrivateKey), verifier: .ps512(publicKey: rsaPublicKey))
} catch {
Expand All @@ -276,7 +276,7 @@ class TestJWT: XCTestCase {
}

func testSignAndVerifyECDSA512() {
if #available(OSX 10.13, *) {
if #available(OSX 10.13, iOS 11, tvOS 11.0, *) {
do {
try signAndVerify(signer: .es512(privateKey: ec512PrivateKey), verifier: .es512(publicKey: ec512PublicKey))
} catch {
Expand Down Expand Up @@ -554,7 +554,7 @@ class TestJWT: XCTestCase {

// Test using a JWT generated from jwt.io using es256 with `ecdsaPrivateKey` for interoperability.
func testJWTUsingECDSA() {
if #available(OSX 10.13, *) {
if #available(OSX 10.13, iOS 11, tvOS 11.0, *) {
let ok = JWT<TestClaims>.verify(ecdsaEncodedTestClaimJWT, using: .es256(publicKey: ecdsaPublicKey))
XCTAssertTrue(ok, "Verification failed")

Expand Down

0 comments on commit 4a1b8ac

Please sign in to comment.