Add SSH key type detection feature#109
Merged
Joannis merged 7 commits intoorlandos-nl:mainfrom Jun 23, 2025
Merged
Conversation
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Joannis
reviewed
Jun 20, 2025
Member
Joannis
left a comment
There was a problem hiding this comment.
A very cool PR, thank you! Just two comments and one nit. Please re-request a review if you push an update so I get an email
Member
|
Very cool stuff |
…ithms-down-the-line Refactor SSHKeyType to a struct for improved E&M
* Enhance SSHKeyDetectionError with detailed error descriptions and additional cases * Enhance SSHKeyDetectionError equality by including associated values for better error handling * Fix SSHKeyDetectionError comparison by removing associated value for invalidKeyFormat * Improve error description for unsupported key type in SSHKeyDetectionError
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds a new SSH key type detection feature to the Citadel module and comprehensive unit tests to validate it.
- Introduces
SSHKeyDetectionwith support for detecting public and OpenSSH private key types and related error handling. - Adds
SSHKeyDetectionErrorenum for granular error cases. - Covers detection logic with extensive unit tests in
KeyTests.swift.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| Sources/Citadel/SSHKeyTypeDetection.swift | New utility for detecting SSH public/private key types and parsing logic. |
| Tests/CitadelTests/KeyTests.swift | New unit tests covering valid key detection, whitespace handling, and error scenarios. |
Comments suppressed due to low confidence (5)
Tests/CitadelTests/KeyTests.swift:178
- Assert that the error thrown for an empty public key string is specifically
SSHKeyDetectionError.invalidKeyFormatto ensure the correct error case is reported.
XCTAssertThrowsError(try SSHKeyDetection.detectPublicKeyType(from: ""))
Tests/CitadelTests/KeyTests.swift:182
- Add an assertion inside this block to verify the thrown error is
SSHKeyDetectionError.invalidKeyFormatwhen the key prefix is present but no content follows.
XCTAssertThrowsError(try SSHKeyDetection.detectPublicKeyType(from: emptyKey))
Tests/CitadelTests/KeyTests.swift:177
- [nitpick] Consider adding a test case for an unsupported public key algorithm (e.g., "ssh-dss AAAA...") to check that
SSHKeyDetection.detectPublicKeyTypethrowsSSHKeyDetectionError.unsupportedKeyType.
// Test empty string
Tests/CitadelTests/KeyTests.swift:284
- [nitpick] The variable name
ecdsa256PrivateKeyis inconsistent with the public key tests (ecdsaP256PublicKey). Rename toecdsaP256PrivateKeyfor clarity and consistency.
let ecdsa256PrivateKey = """
Tests/CitadelTests/KeyTests.swift:295
- [nitpick] Rename
ecdsa256KeyTypetoecdsaP256KeyTypeto match theSSHKeyType.ecdsaP256enum case and maintain consistency with other test variable names.
let ecdsa256KeyType = try SSHKeyDetection.detectPrivateKeyType(from: ecdsa256PrivateKey)
Joannis
approved these changes
Jun 23, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces a comprehensive SSH key type detection feature in the
Citadelmodule, along with extensive unit tests to ensure the reliability and correctness of the implementation. The key changes include the addition of anSSHKeyDetectionutility for detecting SSH key types, new error handling for invalid or unsupported key formats, and test cases to validate both public and private key detection.SSH Key Type Detection Feature:
Sources/Citadel/SSHKeyTypeDetection.swift: Added theSSHKeyDetectionutility to detect SSH key types from their string representations. This includes support for public keys (ssh-rsa,ssh-ed25519,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521) and private keys in OpenSSH format. The utility introduces error handling via theSSHKeyDetectionErrorenum for invalid or malformed key formats.Unit Tests for SSH Key Detection:
Tests/CitadelTests/KeyTests.swift: Added multiple test cases to validate the functionality ofSSHKeyDetection. These include:ssh-ed25519,ssh-rsa,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384, andecdsa-sha2-nistp521.