expose secretbox, notably for the GenerateKey() function that should be public
This commit is contained in:
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package crypto
|
package secretbox
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package crypto
|
package secretbox
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
Reference in New Issue
Block a user