From 9a5bab8524bb9aa029eea4e3552b85cd11661c00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20=C3=85hall?= Date: Mon, 9 Jun 2025 09:00:30 +0200 Subject: [PATCH] Return error type when parsing keys to differentiate between public/private error --- pkg.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/pkg.go b/pkg.go index bcb7009..d154201 100644 --- a/pkg.go +++ b/pkg.go @@ -38,6 +38,15 @@ type Manager struct { Initialized bool } +type KeyError struct { + Err error + KeyType string // PUBLIC or PRIVATE +} + +func (kerr KeyError) Error() string { + return fmt.Sprintf("%s [%s]", kerr.Err.Error(), kerr.KeyType) +} + func NewManager(keyType KeyType, private, public string, expireDays int) (mngr Manager, err error) { // {{{ var errPriv, errPub error mngr.KeyType = keyType @@ -61,12 +70,18 @@ func NewManager(keyType KeyType, private, public string, expireDays int) (mngr M } if errPriv != nil { - err = errPriv + err = KeyError{ + errPriv, + "PRIVATE", + } return } if errPub != nil { - err = errPub + err = KeyError { + errPub, + "PUBLIC", + } return }