From 66f20598c2a1611c430f19d5529ec2d3af56ea82 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Sun, 24 Sep 2023 10:33:59 +0530 Subject: [PATCH] Documentation --- pkg/secrets/key_holder.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/secrets/key_holder.go b/pkg/secrets/key_holder.go index d224f7469..3ceb5c779 100644 --- a/pkg/secrets/key_holder.go +++ b/pkg/secrets/key_holder.go @@ -21,6 +21,10 @@ func NewKeyHolder() *KeyHolder { } } +// LoadSecrets loads the secrets for a given account using the provided CLI key. +// It decrypts the token key, master key, and secret key using the CLI key. +// The decrypted keys and the decoded public key are stored in the AccountSecrets map using the account key as the map key. +// It returns the account secret information or an error if the decryption fails. func (k *KeyHolder) LoadSecrets(account model.Account, cliKey []byte) (*model.AccSecretInfo, error) { tokenKey := account.Token.MustDecrypt(cliKey) masterKey := account.MasterKey.MustDecrypt(cliKey) @@ -39,6 +43,11 @@ func (k *KeyHolder) GetAccountSecretInfo(ctx context.Context) *model.AccSecretIn return k.AccountSecrets[accountKey] } +// GetCollectionKey retrieves the key for a given collection. +// It first fetches the account secret information from the context. +// If the collection owner's ID matches the user ID from the context, it decrypts the collection key using the master key. +// If the collection is shared (i.e., the owner's ID does not match the user ID), it decrypts the collection key using the public and secret keys. +// It returns the decrypted collection key or an error if the decryption fails. func (k *KeyHolder) GetCollectionKey(ctx context.Context, collection api.Collection) ([]byte, error) { accSecretInfo := k.GetAccountSecretInfo(ctx) userID := ctx.Value("user_id").(int64)