Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(sdk): Only do a minor bump; #1534

Open
wants to merge 2 commits into
base: fix/nanotdf-fix-function-signature
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions examples/cmd/encrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ func encrypt(cmd *cobra.Command, args []string) error {
}
cmd.Println(string(manifestJSON))
} else {
_, err = client.CreateNanoTDF(out, in,
sdk.WithNanoDataAttributes(dataAttributes),
_, err = client.CreateNanoTDFOptions(out, in,
sdk.WithNanoDataAttributes(dataAttributes...),
sdk.WithECDSAPolicyBinding(),
sdk.WithKasURL(fmt.Sprintf("http://%s/kas", platformEndpoint)))
if err != nil {
Expand Down
9 changes: 7 additions & 2 deletions sdk/nanotdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -662,12 +662,17 @@ func NewNanoTDFHeaderFromReader(reader io.Reader) (NanoTDFHeader, uint32, error)
// ============================================================================================================

// CreateNanoTDF - reads plain text from the given reader and saves it to the writer, subject to the given options
func (s SDK) CreateNanoTDF(writer io.Writer, reader io.Reader, opts ...NanoTDFOption) (uint32, error) {
func (s SDK) CreateNanoTDFOptions(writer io.Writer, reader io.Reader, opts ...NanoTDFOption) (uint32, error) {
config, err := newNanoTDFConfig(opts...)
if err != nil {
return 0, fmt.Errorf("NanoTDFOption failed: %w", err)
}
return s.CreateNanoTDF(writer, reader, *config)
}

// CreateNanoTDF - reads plain text from the given reader and saves it to the writer, subject to the given options
// Deprecated: Use CreateNanoTDFOptions
func (s SDK) CreateNanoTDF(writer io.Writer, reader io.Reader, config NanoTDFConfig) (uint32, error) {
if writer == nil {
return 0, fmt.Errorf("writer is nil")
}
Expand Down Expand Up @@ -715,7 +720,7 @@ func (s SDK) CreateNanoTDF(writer io.Writer, reader io.Reader, opts ...NanoTDFOp
}

// Create nano tdf header
key, totalSize, err := writeNanoTDFHeader(writer, *config)
key, totalSize, err := writeNanoTDFHeader(writer, config)
if err != nil {
return 0, fmt.Errorf("writeNanoTDFHeader failed:%w", err)
}
Expand Down
50 changes: 44 additions & 6 deletions sdk/nanotdf_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ type NanoTDFConfig struct {

type NanoTDFOption func(*NanoTDFConfig) error

// newNanoTDFConfig - Create a new instance of a nanoTDF config
func newNanoTDFConfig(opt ...NanoTDFOption) (*NanoTDFConfig, error) {
// Deprecated: Prefer CreateNanoTDFOptions
func (s SDK) NewNanoTDFConfig() (*NanoTDFConfig, error) {
return defaultNanoTDFConfig()
}

func defaultNanoTDFConfig() (*NanoTDFConfig, error) {
newECKeyPair, err := ocrypto.NewECKeyPair(ocrypto.ECCModeSecp256r1)
if err != nil {
return nil, fmt.Errorf("ocrypto.NewRSAKeyPair failed: %w", err)
Expand All @@ -50,6 +54,15 @@ func newNanoTDFConfig(opt ...NanoTDFOption) (*NanoTDFConfig, error) {
cipher: cipherModeAes256gcm96Bit,
},
}
return c, nil
}

// newNanoTDFConfig - Create a new instance of a nanoTDF config
func newNanoTDFConfig(opt ...NanoTDFOption) (*NanoTDFConfig, error) {
c, err := defaultNanoTDFConfig()
if err != nil {
return nil, fmt.Errorf("ocrypto.NewRSAKeyPair failed: %w", err)
}

for _, o := range opt {
err := o(c)
Expand All @@ -61,6 +74,32 @@ func newNanoTDFConfig(opt ...NanoTDFOption) (*NanoTDFConfig, error) {
return c, nil
}

// SetKasURL - set the default URL of the KAS endpoint to be used for this nanoTDF
// Deprecated: Use WithKasURL
func (config *NanoTDFConfig) SetKasURL(url string) error {
return config.kasURL.setURL(url)
}

// SetAttributes - set the attributes to be used for this nanoTDF
// Deprecated: Use WithDataAttributes
func (config *NanoTDFConfig) SetAttributes(attributes []string) error {
config.attributes = make([]AttributeValueFQN, len(attributes))
for i, a := range attributes {
v, err := NewAttributeValueFQN(a)
if err != nil {
return err
}
config.attributes[i] = v
}
return nil
}

// EnableECDSAPolicyBinding enable ecdsa policy binding
// Deprecated: Use WithECDSAPolicyBinding
func (config *NanoTDFConfig) EnableECDSAPolicyBinding() {
config.bindCfg.useEcdsaBinding = true
}

// WithKasURL - set the URL of the KAS endpoint to be used for this nanoTDF
func WithKasURL(url string) NanoTDFOption {
return func(c *NanoTDFConfig) error {
Expand All @@ -76,15 +115,14 @@ func WithKasURLAndIdentifier(url string, identifier string) NanoTDFOption {
}

// WithNanoDataAttributes appends the given data attributes to the bound policyq
func WithNanoDataAttributes(attributes []string) NanoTDFOption {
func WithNanoDataAttributes(attributes ...string) NanoTDFOption {
return func(c *NanoTDFConfig) error {
c.attributes = make([]AttributeValueFQN, len(attributes))
for i, a := range attributes {
for _, a := range attributes {
v, err := NewAttributeValueFQN(a)
if err != nil {
return err
}
c.attributes[i] = v
c.attributes = append(c.attributes, v)
}
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions sdk/nanotdf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func NotTestNanoTDFEncryptFile(t *testing.T) {
}

var kasURL = "https://kas.virtru.com/kas"
outSize, err := s.CreateNanoTDF(io.Writer(outfile), io.ReadSeeker(infile), WithKasURL(kasURL))
outSize, err := s.CreateNanoTDFOptions(io.Writer(outfile), io.ReadSeeker(infile), WithKasURL(kasURL))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -221,7 +221,7 @@ func NotTestCreateNanoTDF(t *testing.T) {
}

var kasURL = "https://kas.virtru.com/kas"
_, err = s.CreateNanoTDF(io.Writer(outfile), io.ReadSeeker(infile), WithKasURL(kasURL))
_, err = s.CreateNanoTDFOptions(io.Writer(outfile), io.ReadSeeker(infile), WithKasURL(kasURL))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -293,7 +293,7 @@ func TestCreateNanoTDF(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var s SDK
_, err := s.CreateNanoTDF(tt.writer, tt.reader, tt.config...)
_, err := s.CreateNanoTDFOptions(tt.writer, tt.reader, tt.config...)
if err != nil {
if tt.expectedError == nil {
t.Errorf("unexpected error: %v", err)
Expand Down
Loading