MCPcopy Create free account
hub / github.com/coder/envbuilder / ReadPrivateKey

Function ReadPrivateKey

git/git.go:175–190  ·  view source on GitHub ↗

ReadPrivateKey attempts to read an SSH private key from path and returns an ssh.Signer.

(path string)

Source from the content-addressed store, hash-verified

173// ReadPrivateKey attempts to read an SSH private key from path
174// and returns an ssh.Signer.
175func ReadPrivateKey(path string) (gossh.Signer, error) {
176 f, err := os.Open(path)
177 if err != nil {
178 return nil, fmt.Errorf("open private key file: %w", err)
179 }
180 defer f.Close()
181 bs, err := io.ReadAll(f)
182 if err != nil {
183 return nil, fmt.Errorf("read private key file: %w", err)
184 }
185 k, err := gossh.ParsePrivateKey(bs)
186 if err != nil {
187 return nil, fmt.Errorf("parse private key file: %w", err)
188 }
189 return k, nil
190}
191
192// DecodeBase64PrivateKey attempts to decode a base64 encoded private
193// key and returns an ssh.Signer

Callers 1

SetupRepoAuthFunction · 0.85

Calls 1

CloseMethod · 0.80

Tested by

no test coverage detected