expose secretbox, notably for the GenerateKey() function that should be public

This commit is contained in:
Michael Muré
2024-12-12 16:04:31 +01:00
parent 47156a8ad6
commit 8bb3a4f4d0
3 changed files with 7 additions and 7 deletions

View File

@@ -10,8 +10,8 @@ import (
"github.com/ipld/go-ipld-prime" "github.com/ipld/go-ipld-prime"
"github.com/ipld/go-ipld-prime/printer" "github.com/ipld/go-ipld-prime/printer"
"github.com/ucan-wg/go-ucan/pkg/meta/internal/crypto"
"github.com/ucan-wg/go-ucan/pkg/policy/literal" "github.com/ucan-wg/go-ucan/pkg/policy/literal"
"github.com/ucan-wg/go-ucan/pkg/secretbox"
) )
var ErrNotFound = errors.New("key not found in meta") var ErrNotFound = errors.New("key not found in meta")
@@ -63,7 +63,7 @@ func (m *Meta) GetEncryptedString(key string, encryptionKey []byte) (string, err
return "", err return "", err
} }
decrypted, err := crypto.DecryptStringWithKey(v, encryptionKey) decrypted, err := secretbox.DecryptStringWithKey(v, encryptionKey)
if err != nil { if err != nil {
return "", err return "", err
} }
@@ -111,7 +111,7 @@ func (m *Meta) GetEncryptedBytes(key string, encryptionKey []byte) ([]byte, erro
return nil, err return nil, err
} }
decrypted, err := crypto.DecryptStringWithKey(v, encryptionKey) decrypted, err := secretbox.DecryptStringWithKey(v, encryptionKey)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -157,12 +157,12 @@ func (m *Meta) AddEncrypted(key string, val any, encryptionKey []byte) error {
switch val := val.(type) { switch val := val.(type) {
case string: case string:
encrypted, err = crypto.EncryptWithKey([]byte(val), encryptionKey) encrypted, err = secretbox.EncryptWithKey([]byte(val), encryptionKey)
if err != nil { if err != nil {
return err return err
} }
case []byte: case []byte:
encrypted, err = crypto.EncryptWithKey(val, encryptionKey) encrypted, err = secretbox.EncryptWithKey(val, encryptionKey)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -1,4 +1,4 @@
package crypto package secretbox
import ( import (
"crypto/rand" "crypto/rand"

View File

@@ -1,4 +1,4 @@
package crypto package secretbox
import ( import (
"bytes" "bytes"