Skip to content

Swift 6 #106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 3, 2025
Merged

Swift 6 #106

merged 3 commits into from
Feb 3, 2025

Conversation

dimitribouniol
Copy link
Collaborator

Made Swift 6 the default, and combed through the codebase to adopt the latest language features.

I would have liked to adopt more typed throws, but for now I limited it to non-public members. We can have a separate discussion as to whether it's useful to wrap the CBOR, decoding, and cert-related errors or not (ostensibly, none of them would be the user's fault, as they are receiving them from things like the browser, so I'd argue that in many cases we should wrap them? Either way, for another PR).

@dimitribouniol dimitribouniol self-assigned this Feb 2, 2025
Comment on lines 22 to 45
case algES256 = -7
/// AlgES384 ECDSA with SHA-384
case algES384 = -35
/// AlgES512 ECDSA with SHA-512
case algES512 = -36
case algES256 = -7
/// AlgES384 ECDSA with SHA-384
case algES384 = -35
/// AlgES512 ECDSA with SHA-512
case algES512 = -36

// We don't support RSA yet
// We don't support RSA yet

// /// AlgRS1 RSASSA-PKCS1-v1_5 with SHA-1
// case algRS1 = -65535
// /// AlgRS256 RSASSA-PKCS1-v1_5 with SHA-256
// case algRS256 = -257
// /// AlgRS384 RSASSA-PKCS1-v1_5 with SHA-384
// case algRS384 = -258
// /// AlgRS512 RSASSA-PKCS1-v1_5 with SHA-512
// case algRS512 = -259
// /// AlgPS256 RSASSA-PSS with SHA-256
// case algPS256 = -37
// /// AlgPS384 RSASSA-PSS with SHA-384
// case algPS384 = -38
// /// AlgPS512 RSASSA-PSS with SHA-512
// case algPS512 = -39
// // AlgEdDSA EdDSA
// case algEdDSA = -8
// /// AlgRS1 RSASSA-PKCS1-v1_5 with SHA-1
// case algRS1 = -65535
// /// AlgRS256 RSASSA-PKCS1-v1_5 with SHA-256
// case algRS256 = -257
// /// AlgRS384 RSASSA-PKCS1-v1_5 with SHA-384
// case algRS384 = -258
// /// AlgRS512 RSASSA-PKCS1-v1_5 with SHA-512
// case algRS512 = -259
// /// AlgPS256 RSASSA-PSS with SHA-256
// case algPS256 = -37
// /// AlgPS384 RSASSA-PSS with SHA-384
// case algPS384 = -38
// /// AlgPS512 RSASSA-PSS with SHA-512
// case algPS512 = -39
// // AlgEdDSA EdDSA
// case algEdDSA = -8
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were all tabs 🤪

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha yeah this got picked up in #88

Comment on lines -105 to +110
/// Assuming valid CBOR, verify the public key's length by decoding the next CBOR item.
/// Assuming valid CBOR, verify the public key's length by decoding the next CBOR item, and checking how much data is left on the stream.
let inputStream = ByteInputStream(data[credentialIDEndIndex...])
let decoder = CBORDecoder(stream: inputStream, options: CBOROptions(maximumDepth: 16))
_ = try decoder.decodeItem()
do {
let decoder = CBORDecoder(stream: inputStream, options: CBOROptions(maximumDepth: 16))
_ = try decoder.decodeItem()
} catch { throw .invalidPublicKeyLength }
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took a chance to define a new error case for this and clarify what is happening.

@dimitribouniol dimitribouniol requested a review from 0xTim February 2, 2025 13:21
@dimitribouniol dimitribouniol enabled auto-merge (rebase) February 2, 2025 13:24
@dimitribouniol dimitribouniol linked an issue Feb 2, 2025 that may be closed by this pull request
Copy link
Member

@0xTim 0xTim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments

Overall, most of the changes here are stylistic rather then related to Swift 6 so I suggest we split out the Swift 6 changes into a separate PR and have this PR as a formatting PR, integrating swift-format at the same time to keep everything consistent going forward (with the relevant CI checks)

throw WebAuthnError.authDataTooShort
}
guard bytes.count >= minAuthDataLength
else { throw .authDataTooShort }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am not a fan of else being on a separate line 😆 we should get swift format integrated with an agreed style first

Copy link
Collaborator Author

@dimitribouniol dimitribouniol Feb 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here I was being consistent with all my recent commits adhering to this style 🤣
Joking aside, I think this style is much more readable than the assembly of variants I replaced, as conditions can all be aligned, and the else clearly represents a one-line return or throw. When the else case has multiple statements, I agree that it looks better joined to the condition though. Either way, I've undone these fixes and will re-propose them in the context of a format PR 😄

Comment on lines 22 to 45
case algES256 = -7
/// AlgES384 ECDSA with SHA-384
case algES384 = -35
/// AlgES512 ECDSA with SHA-512
case algES512 = -36
case algES256 = -7
/// AlgES384 ECDSA with SHA-384
case algES384 = -35
/// AlgES512 ECDSA with SHA-512
case algES512 = -36

// We don't support RSA yet
// We don't support RSA yet

// /// AlgRS1 RSASSA-PKCS1-v1_5 with SHA-1
// case algRS1 = -65535
// /// AlgRS256 RSASSA-PKCS1-v1_5 with SHA-256
// case algRS256 = -257
// /// AlgRS384 RSASSA-PKCS1-v1_5 with SHA-384
// case algRS384 = -258
// /// AlgRS512 RSASSA-PKCS1-v1_5 with SHA-512
// case algRS512 = -259
// /// AlgPS256 RSASSA-PSS with SHA-256
// case algPS256 = -37
// /// AlgPS384 RSASSA-PSS with SHA-384
// case algPS384 = -38
// /// AlgPS512 RSASSA-PSS with SHA-512
// case algPS512 = -39
// // AlgEdDSA EdDSA
// case algEdDSA = -8
// /// AlgRS1 RSASSA-PKCS1-v1_5 with SHA-1
// case algRS1 = -65535
// /// AlgRS256 RSASSA-PKCS1-v1_5 with SHA-256
// case algRS256 = -257
// /// AlgRS384 RSASSA-PKCS1-v1_5 with SHA-384
// case algRS384 = -258
// /// AlgRS512 RSASSA-PKCS1-v1_5 with SHA-512
// case algRS512 = -259
// /// AlgPS256 RSASSA-PSS with SHA-256
// case algPS256 = -37
// /// AlgPS384 RSASSA-PSS with SHA-384
// case algPS384 = -38
// /// AlgPS512 RSASSA-PSS with SHA-512
// case algPS512 = -39
// // AlgEdDSA EdDSA
// case algEdDSA = -8
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha yeah this got picked up in #88

@dimitribouniol
Copy link
Collaborator Author

so I suggest we split out the Swift 6 changes into a separate PR and have this PR as a formatting PR, integrating swift-format at the same time to keep everything consistent going forward (with the relevant CI checks)

I was actually prepping a separate format PR, but was waiting for in progress PRs to finish so I don't cause merge conflicts for everyone haha. I've simplified this PR to only Swift 6 features, which includes the manifest, explicit any, and typed throws where it doesn't involve much lift.

@dimitribouniol dimitribouniol requested a review from 0xTim February 2, 2025 16:52
@dimitribouniol dimitribouniol merged commit 0e13155 into main Feb 3, 2025
15 checks passed
@dimitribouniol dimitribouniol deleted the dimitri/swift-6 branch February 3, 2025 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Drop Swift 5 Support
2 participants