Rename functions from encode to encrypt

to better reflect reality

Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
This commit is contained in:
Dimitris Karakasilis 2023-01-19 16:01:50 +02:00
parent 18d63f3a8c
commit 3fa97128ef
No known key found for this signature in database
GPG Key ID: 286DCAFD2C97DDE3
2 changed files with 8 additions and 8 deletions

View File

@ -12,8 +12,8 @@ import (
"github.com/pkg/errors"
)
// DecodeBlob decodes a blob using a key stored in the TPM
func DecodeBlob(blob []byte, opts ...TPMOption) ([]byte, error) {
// DecryptBlob decrypts a blob using a key stored in the TPM
func DecryptBlob(blob []byte, opts ...TPMOption) ([]byte, error) {
o, err := DefaultTPMOption(opts...)
if err != nil {
return []byte{}, err
@ -35,7 +35,7 @@ func DecodeBlob(blob []byte, opts ...TPMOption) ([]byte, error) {
return private.Decrypt(rand.Reader, blob, &rsa.OAEPOptions{Hash: o.hash})
}
func EncodeBlob(blob []byte, opts ...TPMOption) ([]byte, error) {
func EncryptBlob(blob []byte, opts ...TPMOption) ([]byte, error) {
o, err := DefaultTPMOption(opts...)
if err != nil {
return []byte{}, err

View File

@ -9,14 +9,14 @@ import (
var _ = Describe("TPM Encryption", func() {
Context("Blob", func() {
It("encrypts a blob", func() {
var encodedBlob []byte
var encryptedBlob []byte
var err error
By("Encoding the blob", func() {
encodedBlob, err = EncodeBlob([]byte("foo"), EmulatedTPM)
By("Encrypting the blob", func() {
encryptedBlob, err = EncryptBlob([]byte("foo"), EmulatedTPM)
Expect(err).ToNot(HaveOccurred())
})
By("Decoding the blob", func() {
foo, err := DecodeBlob(encodedBlob, EmulatedTPM)
By("Decrypting the blob", func() {
foo, err := DecryptBlob(encryptedBlob, EmulatedTPM)
Expect(err).ToNot(HaveOccurred())
Expect(foo).To(Equal([]byte("foo")))
})