From 527fef6228c3ce8a46ebf63e631bd60adf6c4d21 Mon Sep 17 00:00:00 2001 From: Paul Toffoloni <69189821+ptoffy@users.noreply.github.com> Date: Mon, 22 Sep 2025 13:02:42 +0200 Subject: [PATCH] Remove useless `try` to fix warnings (#412) `getKeyPrimitives` is marked as throws but is not actually throwing errors and this is yielding warnings. This fixes the warnings. ### Checklist - [x] I've run tests to see all new and existing tests pass - [x] I've followed the code style of the rest of the project - [x] I've read the [Contribution Guidelines](CONTRIBUTING.md) - [x] I've updated the documentation if necessary #### If you've made changes to `gyb` files - [N/A] I've run `./scripts/generate_boilerplate_files_with_gyb.sh` and included updated generated files in a commit of this pull request ### Motivation: Currently there's a warning ``` /swift-crypto/Sources/_CryptoExtras/RSA/RSA_boring.swift:67:9: warning: no calls to throwing functions occur within 'try' expression ``` because we're using `try` on a non throwing function. This escalates to all of the functions that use it. I'm not sure if removing `throws` from a non-actually-throwing public function is breaking, as using `try` on a non throwing function only yields a warning (if not in warnings-as-errors mode) but it actively is a signature change so it might still be breaking. In case we don't want to merge this as is, the warning can be removed by simply removing useless `try`s and we can wait for the next major version to remove the false-throwers. ### Modifications: Remove the useless `try` and `throws` where they're not needed. ### Result: The warning is gone. --- Sources/_CryptoExtras/RSA/RSA+BlindSigning.swift | 2 +- Sources/_CryptoExtras/RSA/RSA.swift | 4 ++-- Sources/_CryptoExtras/RSA/RSA_boring.swift | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Sources/_CryptoExtras/RSA/RSA+BlindSigning.swift b/Sources/_CryptoExtras/RSA/RSA+BlindSigning.swift index a0af9182..fc69ea7e 100644 --- a/Sources/_CryptoExtras/RSA/RSA+BlindSigning.swift +++ b/Sources/_CryptoExtras/RSA/RSA+BlindSigning.swift @@ -132,7 +132,7 @@ extension _RSA.BlindSigning { } public func getKeyPrimitives() throws -> Primitives { - let (n, e) = try self.backing.getKeyPrimitives() + let (n, e) = self.backing.getKeyPrimitives() return Primitives(modulus: n, publicExponent: e) } } diff --git a/Sources/_CryptoExtras/RSA/RSA.swift b/Sources/_CryptoExtras/RSA/RSA.swift index 642236bf..88f33398 100644 --- a/Sources/_CryptoExtras/RSA/RSA.swift +++ b/Sources/_CryptoExtras/RSA/RSA.swift @@ -142,7 +142,7 @@ extension _RSA.Signing { } public func getKeyPrimitives() throws -> Primitives { - let (n, e) = try self.backing.getKeyPrimitives() + let (n, e) = self.backing.getKeyPrimitives() return Primitives(modulus: n, publicExponent: e) } } @@ -539,7 +539,7 @@ extension _RSA.Encryption { fileprivate init(_ backing: BackingPublicKey) { self.backing = backing } public func getKeyPrimitives() throws -> Primitives { - let (n, e) = try self.backing.getKeyPrimitives() + let (n, e) = self.backing.getKeyPrimitives() return Primitives(modulus: n, publicExponent: e) } } diff --git a/Sources/_CryptoExtras/RSA/RSA_boring.swift b/Sources/_CryptoExtras/RSA/RSA_boring.swift index 3c6eebbb..f43c2191 100644 --- a/Sources/_CryptoExtras/RSA/RSA_boring.swift +++ b/Sources/_CryptoExtras/RSA/RSA_boring.swift @@ -63,8 +63,8 @@ internal struct BoringSSLRSAPublicKey: Sendable { self.backing = backing } - func getKeyPrimitives() throws -> (n: Data, e: Data) { - try self.backing.getKeyPrimitives() + func getKeyPrimitives() -> (n: Data, e: Data) { + self.backing.getKeyPrimitives() } }