Skip to content

Commit

Permalink
Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
dopey committed Feb 1, 2022
1 parent 3c468c0 commit f1189f2
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions pemutil/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"crypto/rsa"
"encoding/binary"
"encoding/pem"
"fmt"
"math/big"

"github.com/pkg/errors"
Expand Down Expand Up @@ -81,20 +80,8 @@ func ParseOpenSSHPrivateKey(pemBytes []byte, opts ...Options) (crypto.PrivateKey
var err error
var key crypto.PrivateKey
if w.KdfName != "none" || w.CipherName != "none" {
var password []byte
if len(ctx.password) > 0 {
password = ctx.password
} else if ctx.passwordPrompter != nil {
password, err = ctx.passwordPrompter(ctx.passwordPrompt)
if err != nil {
return nil, err
}
} else if PromptPassword != nil {
password, err = PromptPassword(fmt.Sprintf("Please enter the password to decrypt %s", ctx.filename))
if err != nil {
return nil, err
}
} else {
password, err := ctx.promptPassword()
if err != nil {
return nil, errors.Errorf("error decoding %s: file is password protected", ctx.filename)
}
key, err = ssh.ParseRawPrivateKeyWithPassphrase(pemBytes, password)
Expand Down

0 comments on commit f1189f2

Please sign in to comment.