mirror of
https://github.com/ente-io/ente.git
synced 2025-07-04 14:36:53 +00:00
25 lines
770 B
Go
25 lines
770 B
Go
package mapper
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"github.com/ente-io/cli/internal/api/models"
|
|
eCrypto "github.com/ente-io/cli/internal/crypto"
|
|
)
|
|
|
|
func MapRemoteAuthEntityToString(ctx context.Context, authEntity models.AuthEntity, authKey []byte) (*string, error) {
|
|
_, decrypted, err := eCrypto.DecryptChaChaBase64Auth(*authEntity.EncryptedData, authKey, *authEntity.Header)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to decrypt auth enityt %s: %v", authEntity.ID, err)
|
|
}
|
|
decryptedStr := string(decrypted)
|
|
// json decode the string
|
|
var jsonDecodedStr string
|
|
err = json.Unmarshal([]byte(decryptedStr), &jsonDecodedStr)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to decode json %s: %v", decryptedStr, err)
|
|
}
|
|
return &jsonDecodedStr, nil
|
|
}
|