goldwarden/agent/systemauth/pinentry/keybase-pinentry.go

51 lines
1.0 KiB
Go
Raw Normal View History

2024-02-04 00:17:19 +03:00
//go:build windows || darwin
package pinentry
import (
"errors"
"github.com/keybase/client/go/logger"
"github.com/keybase/client/go/protocol/keybase1"
2024-02-04 00:55:49 +03:00
pinentry "github.com/quexten/goldwarden/agent/systemauth/pinentry/keybase-pinentry"
2024-02-04 00:17:19 +03:00
)
func GetPassword(title string, description string) (string, error) {
pinentryInstance := pinentry.New("", logger.New(""), "")
result, err := pinentryInstance.Get(keybase1.SecretEntryArg{
Prompt: title,
Desc: description,
})
if err != nil {
return "", err
}
if result.Canceled {
return "", errors.New("Cancelled")
}
return result.Text, nil
}
func GetApproval(title string, description string) (bool, error) {
pinentryInstance := pinentry.New("", logger.New(""), "")
result, err := pinentryInstance.Get(keybase1.SecretEntryArg{
Prompt: title,
Desc: description,
Cancel: "Decline",
Ok: "Approve",
ShowTyping: true,
})
if err != nil {
return false, err
}
if result.Canceled {
return false, errors.New("Cancelled")
}
return true, nil
}