fix: added error from error module

This commit is contained in:
mayur.popli
2025-04-03 13:35:49 +05:30
parent a2c27b4fbf
commit a955949857
5 changed files with 25 additions and 24 deletions

View File

@@ -9,6 +9,8 @@ import (
"fmt"
"github.com/zenazn/pkcs7pad"
"github.com/beckn/beckn-onix/pkg/model"
)
// decrypter implements the Decrypter interface and handles the decryption process.
@@ -24,18 +26,18 @@ func New(ctx context.Context) (*decrypter, func() error, error) {
func (d *decrypter) Decrypt(ctx context.Context, encryptedData, privateKeyBase64, publicKeyBase64 string) (string, error) {
privateKeyBytes, err := base64.StdEncoding.DecodeString(privateKeyBase64)
if err != nil {
return "", fmt.Errorf("invalid private key: %w", err)
return "", model.NewBadReqErr(err)
}
publicKeyBytes, err := base64.StdEncoding.DecodeString(publicKeyBase64)
if err != nil {
return "", fmt.Errorf("invalid public key: %w", err)
return "", model.NewBadReqErr(err)
}
// Decode the Base64 encoded encrypted data.
messageByte, err := base64.StdEncoding.DecodeString(encryptedData)
if err != nil {
return "", fmt.Errorf("failed to decode encrypted data: %w", err)
return "", model.NewBadReqErr(err)
}
aesCipher, err := createAESCipher(privateKeyBytes, publicKeyBytes)