change error print method

used specific for errors function
this one also stops program
This commit is contained in:
akulij 2025-02-26 18:32:31 +00:00
parent 6c40441f70
commit 721e68a64e

View File

@ -4,6 +4,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"log"
"os" "os"
"time" "time"
"unsafe" "unsafe"
@ -23,7 +24,7 @@ type X25519Identity struct {
func main() { func main() {
passbytes, err := getPasswordBytes() passbytes, err := getPasswordBytes()
if err != nil { if err != nil {
fmt.Printf("Failed to get password, error: %s\n", err) errorf("Failed to get password, error: %s\n", err)
} }
sum := sha256.Sum256(passbytes) sum := sha256.Sum256(passbytes)
@ -31,7 +32,7 @@ func main() {
k, err := newX25519IdentityFromScalar(sum[:]) k, err := newX25519IdentityFromScalar(sum[:])
if err != nil { if err != nil {
fmt.Printf("internal error: %v", err) errorf("internal error: %v", err)
} }
fmt.Printf("Public key: %s\n", k.Recipient()) fmt.Printf("Public key: %s\n", k.Recipient())
@ -64,3 +65,7 @@ func newX25519IdentityFromScalar(secretKey []byte) (*age.X25519Identity, error)
i.ourPublicKey, _ = curve25519.X25519(i.secretKey, curve25519.Basepoint) i.ourPublicKey, _ = curve25519.X25519(i.secretKey, curve25519.Basepoint)
return (*age.X25519Identity)(unsafe.Pointer(i)), nil return (*age.X25519Identity)(unsafe.Pointer(i)), nil
} }
func errorf(format string, v ...interface{}) {
log.Fatalf("age-gen-passphrase ERROR: "+format, v...)
}