Skip to content

Add support for importing RSA private keys and enhance OpenSSH serialization#14

Merged
nedithgar merged 5 commits intomainfrom
fix/investigate-passphrase
Oct 12, 2025
Merged

Add support for importing RSA private keys and enhance OpenSSH serialization#14
nedithgar merged 5 commits intomainfrom
fix/investigate-passphrase

Conversation

@nedithgar
Copy link
Copy Markdown
Owner

Introduce support for importing RSA private keys from legacy encrypted PKCS#1 PEM. Enhance OpenSSH private key serialization with type-safe encryption ciphers and improved validation. Update the version to 0.1.2.

Copilot AI review requested due to automatic review settings October 12, 2025 11:50
@nedithgar nedithgar merged commit 7307bd1 into main Oct 12, 2025
4 checks passed
@nedithgar nedithgar deleted the fix/investigate-passphrase branch October 12, 2025 11:50
Copy link
Copy Markdown

Copilot AI left a 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 support for importing RSA private keys from legacy encrypted PKCS#1 PEM format and enhances OpenSSH private key serialization with type-safe encryption ciphers. The changes improve API safety by replacing string-based cipher parameters with a typed EncryptionCipher enum while maintaining backward compatibility through raw value initialization.

  • Introduces type-safe EncryptionCipher wrapper for OpenSSH cipher names
  • Updates all OpenSSH serialization calls to use enum values instead of strings
  • Enhances CLI cipher validation with friendly error messages
  • Updates version to 0.1.2 and documentation

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
Sources/SwiftKeyGen/Formats/OpenSSH/OpenSSHPrivateKey.swift Adds EncryptionCipher type and updates serialize method signature
Sources/SwiftKeyGenCLI/main.swift Updates version and adds cipher validation with enum mapping
Tests/SwiftKeyGenTests/Formats/OpenSSH/OpenSSHPrivateKeyUnitTests.swift Updates test cases to use typed cipher enum values
Tests/SwiftKeyGenTests/Cryptography/Ciphers/AES/AESGCMIntegrationTests.swift Updates test to use typed cipher array
README.md Adds documentation for new OpenSSH serialization API and updates feature list

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.


if let passphrase = passphrase, !passphrase.isEmpty {
cipherName = cipher ?? DEFAULT_CIPHER
cipherName = (cipher ?? .default).rawValue
Copy link

Copilot AI Oct 12, 2025

Choose a reason for hiding this comment

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

The .default property is computed and calls Cipher.defaultCipher on every access. Consider caching this value or making it a static let to avoid repeated computation when no cipher is specified.

Copilot uses AI. Check for mistakes.
var selectedCipher: OpenSSHPrivateKey.EncryptionCipher? = nil
if let c = cipher {
// Validate against known ciphers for a friendly error
if !OpenSSHPrivateKey.EncryptionCipher.known.contains(where: { $0.rawValue == c }) {
Copy link

Copilot AI Oct 12, 2025

Choose a reason for hiding this comment

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

The known array is computed on every validation and uses linear search with closure. Consider creating a static Set of raw values for O(1) lookup performance.

Copilot uses AI. Check for mistakes.
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.

2 participants