-
-
Notifications
You must be signed in to change notification settings - Fork 63
Add SSH key type detection feature #109
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
Conversation
Co-authored-by: Copilot <[email protected]>
Joannis
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
|
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
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.