Skip to content
Merged
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
12 changes: 6 additions & 6 deletions sdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ func (t TdfType) String() string {
return string(t)
}

// String method to make the custom type printable
// GetTdfType returns the type of TDF based on the reader.
// Reader is reset after the check.
func GetTdfType(reader io.ReadSeeker) TdfType {
isValidNanoTdf, _ := IsValidNanoTdf(reader)

Expand Down Expand Up @@ -348,13 +349,12 @@ func IsValidTdf(reader io.ReadSeeker) (bool, error) {
return true, nil
}

// IsValidNanoTdf detects whether, or not the reader is a valid Nano TDF.
// Reader is reset after the check.
func IsValidNanoTdf(reader io.ReadSeeker) (bool, error) {
_, _, err := NewNanoTDFHeaderFromReader(reader)
if err != nil {
return false, err
}

return true, nil
_, _ = reader.Seek(0, io.SeekStart) // Ignore the error as we're just checking if it's a valid nano TDF
return err == nil, err
}

func fetchPlatformConfiguration(platformEndpoint string, dialOptions []grpc.DialOption) (PlatformConfiguration, error) {
Expand Down
12 changes: 12 additions & 0 deletions sdk/sdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ func TestNew_ShouldValidateGoodNanoTdf(t *testing.T) {
require.NoError(t, err)

assert.True(t, isValid)

// Try again to see if the reader has been reset
isValid, err = sdk.IsValidNanoTdf(in)
require.NoError(t, err)

assert.True(t, isValid)
}

func TestNew_ShouldNotValidateBadNanoTdf(t *testing.T) {
Expand All @@ -169,6 +175,12 @@ func TestNew_ShouldValidateStandardTdf(t *testing.T) {
require.NoError(t, err)

assert.True(t, isValid)

// Try again to see if the reader has been reset
isValid, err = sdk.IsValidTdf(in)
require.NoError(t, err)

assert.True(t, isValid)
}

func TestNew_ShouldNotValidateBadStandardTdf(t *testing.T) {
Expand Down
Loading