Files
zeekay 765c3d0aa1 hanzo-ds/native: de-branded native protocol lib (fork of clickhouse ch-go v0.71.0)
Module path, package names, and identifiers de-branded to native/proto/compress/
pool/tracing. Server wire-protocol strings preserved. Vendored codec surface used
by hanzo-ds/go (proto + compress).
2026-07-10 13:10:07 -07:00

31 lines
762 B
Go

package ssh
import (
"fmt"
"os"
"golang.org/x/crypto/ssh"
)
// LoadPrivateKeyFromFile loads an SSH private key from a file and returns a signer.
// Supports passphrase-protected keys for RSA, ECDSA, and Ed25519 key types.
func LoadPrivateKeyFromFile(filename, passphrase string) (ssh.Signer, error) {
if filename == "" {
return nil, fmt.Errorf("filename cannot be empty")
}
if _, err := os.Stat(filename); err != nil {
return nil, fmt.Errorf("failed to access file: %w", err)
}
data, err := os.ReadFile(filename) //nolint:gosec
if err != nil {
return nil, fmt.Errorf("failed to read SSH key file: %w", err)
}
if passphrase != "" {
return ssh.ParsePrivateKeyWithPassphrase(data, []byte(passphrase))
}
return ssh.ParsePrivateKey(data)
}