Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions pkg/handlers/nano-tdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,23 @@ package handlers
import (
"bytes"
"io"

"github.com/opentdf/platform/sdk"
)

func (h Handler) EncryptNanoBytes(b []byte, values []string, kasUrlPath string, ecdsaBinding bool) (*bytes.Buffer, error) {
var encrypted []byte
enc := bytes.NewBuffer(encrypted)

nanoTDFConfig, err := h.sdk.NewNanoTDFConfig()
if err != nil {
return nil, err
}

err = nanoTDFConfig.SetKasURL(h.platformEndpoint + kasUrlPath)
if err != nil {
return nil, err
}
err = nanoTDFConfig.SetAttributes(values)
if err != nil {
return nil, err
options := []sdk.NanoTDFOption{
sdk.WithKasURL(h.platformEndpoint + kasUrlPath),
sdk.WithNanoDataAttributes(values),
}
if ecdsaBinding {
nanoTDFConfig.EnableECDSAPolicyBinding()
options = append(options, sdk.WithECDSAPolicyBinding())
}
Comment on lines +14 to 20
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to remove the need for the extra module inclusion of github.com/opentdf/platform/sdk by using the handler wrapped sdk? Something like:

options := []h.sdk.NanoTDFOption{
	h.sdk.WithKasURL(h.platformEndpoint + kasUrlPath),
	h.sdk.WithNanoDataAttributes(values),
}

if ecdsaBinding {
	options = append(options, h.sdk.WithECDSAPolicyBinding())
}


// TODO: validate values are FQNs or return an error [https://github.com/opentdf/platform/issues/515]
_, err = h.sdk.CreateNanoTDF(enc, bytes.NewReader(b), *nanoTDFConfig)
_, err := h.sdk.CreateNanoTDF(enc, bytes.NewReader(b), options...)
if err != nil {
return nil, err
}
Expand Down