Skip to content

Commit

Permalink
Add (back) VerifiableGet function.
Browse files Browse the repository at this point in the history
Used if you need access to the underlying data used for verification.
  • Loading branch information
SimoneLazzaris committed Oct 23, 2023
1 parent a80c309 commit cba0a86
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions embedded/sql/type_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ func getConverter(src, dst SQLValueType) (converterFunc, error) {
str := val.RawValue().(string)

var supportedTimeFormats = []string{
"2006-01-02 15:04:05 MST",
"2006-01-02 15:04:05 -0700",
"2006-01-02 15:04:05.999999",
"2006-01-02 15:04:05",
"2006-01-02 15:04",
"2006-01-02",
}
Expand Down
13 changes: 13 additions & 0 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,12 @@ type ImmuClient interface {
// If verification does not succeed the store.ErrCorruptedData error is returned.
VerifiedGetAtRevision(ctx context.Context, key []byte, rev int64) (*schema.Entry, error)

// VerifiableGet reads value for a given key, and returs internal data used to perform
// the verification.
//
// You can use this function if you want to have visibility on the verification data
VerifiableGet(ctx context.Context, in *schema.VerifiableGetRequest, opts ...grpc.CallOption) (*schema.VerifiableEntry, error)

// History returns history for a single key.
History(ctx context.Context, req *schema.HistoryRequest) (*schema.Entries, error)

Expand Down Expand Up @@ -2311,3 +2317,10 @@ func (c *immuClient) TruncateDatabase(ctx context.Context, db string, retentionP

return err
}

// VerifiableGet
func (c *immuClient) VerifiableGet(ctx context.Context, in *schema.VerifiableGetRequest, opts ...grpc.CallOption) (*schema.VerifiableEntry, error) {
result, err := c.ServiceClient.VerifiableGet(ctx, in, opts...)

return result, err
}
6 changes: 6 additions & 0 deletions pkg/client/clienttest/immuclient_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type ImmuClientMock struct {
VerifiedGetF func(context.Context, []byte, ...client.GetOption) (*schema.Entry, error)
VerifiedGetAtF func(context.Context, []byte, uint64) (*schema.Entry, error)
VerifiedSetF func(context.Context, []byte, []byte) (*schema.TxHeader, error)
VerifiableGetF func(context.Context, *schema.VerifiableGetRequest, ...grpc.CallOption) (*schema.VerifiableEntry, error)
SetF func(context.Context, []byte, []byte) (*schema.TxHeader, error)
SetAllF func(context.Context, *schema.SetRequest) (*schema.TxHeader, error)
SetReferenceF func(context.Context, []byte, []byte, uint64) (*schema.TxHeader, error)
Expand Down Expand Up @@ -129,6 +130,11 @@ func (icm *ImmuClientMock) VerifiedSet(ctx context.Context, key []byte, value []
return icm.VerifiedSetF(ctx, key, value)
}

// VerifiedSet ...
func (icm *ImmuClientMock) VerifiableGet(ctx context.Context, in *schema.VerifiableGetRequest, opts ...grpc.CallOption) (*schema.VerifiableEntry, error) {
return icm.VerifiableGetF(ctx, in, opts...)
}

// Set ...
func (icm *ImmuClientMock) Set(ctx context.Context, key []byte, value []byte) (*schema.TxHeader, error) {
return icm.SetF(ctx, key, value)
Expand Down
7 changes: 7 additions & 0 deletions pkg/client/clienttest/immuclient_mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func TestImmuClientMock(t *testing.T) {
errLogout := errors.New("LogoutF got called")
errVerifiedGet := errors.New("VerifiedGetF got called")
errVerifiedSet := errors.New("VerifiedSetF got called")
errVerifiableGet := errors.New("VerifiableGetF got called")
errSet := errors.New("SetF got called")
errVerifiedReference := errors.New("VerifiedReferenceF got called")
errVerifiedZAdd := errors.New("VerifiedZAddF got called")
Expand Down Expand Up @@ -66,6 +67,9 @@ func TestImmuClientMock(t *testing.T) {
VerifiedSetF: func(context.Context, []byte, []byte) (*schema.TxHeader, error) {
return nil, errVerifiedSet
},
VerifiableGetF: func(ctx context.Context, in *schema.VerifiableGetRequest, opts ...grpc.CallOption) (*schema.VerifiableEntry, error) {
return nil, errVerifiableGet
},
SetF: func(context.Context, []byte, []byte) (*schema.TxHeader, error) {
return nil, errSet
},
Expand Down Expand Up @@ -107,6 +111,9 @@ func TestImmuClientMock(t *testing.T) {
_, err = icm.VerifiedSet(context.Background(), nil, nil)
require.ErrorIs(t, err, errVerifiedSet)

_, err = icm.VerifiableGet(context.Background(), nil, nil)
require.ErrorIs(t, err, errVerifiableGet)

_, err = icm.Set(context.Background(), nil, nil)
require.ErrorIs(t, err, errSet)

Expand Down

0 comments on commit cba0a86

Please sign in to comment.