Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
feat: Enforce EDV document ID format in EDVFormatProvider
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Trider <Derek.Trider@securekey.com>
  • Loading branch information
Derek Trider committed Oct 26, 2020
1 parent f8f6921 commit b51ab9a
Show file tree
Hide file tree
Showing 16 changed files with 391 additions and 154 deletions.
2 changes: 1 addition & 1 deletion component/storage/jsindexeddb/jsindexeddb.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (s *store) Delete(k string) error {
}

// TODO #2229 - implement query method.
func (s *store) Query(query string) (storage.StoreIterator, error) {
func (s *store) Query(name, value string) (storage.StoreIterator, error) {
return nil, storage.ErrQueryingNotSupported
}

Expand Down
2 changes: 1 addition & 1 deletion component/storage/leveldb/leveldb_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ type leveldbStore struct {
}

// TODO #2227 - implement query method.
func (s *leveldbStore) Query(_ string) (storage.StoreIterator, error) {
func (s *leveldbStore) Query(name, value string) (storage.StoreIterator, error) {
return nil, storage.ErrQueryingNotSupported
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/didcomm/protocol/didexchange/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ type mockStore struct {
put func(string, []byte) error
get func(string) ([]byte, error)
delete func(string) error
query func(string) (storage.StoreIterator, error)
query func(string, string) (storage.StoreIterator, error)
}

// Put stores the key and the record.
Expand All @@ -734,8 +734,8 @@ func (m *mockStore) Delete(k string) error {
return m.delete(k)
}

func (m *mockStore) Query(query string) (storage.StoreIterator, error) {
return m.query(query)
func (m *mockStore) Query(name, value string) (storage.StoreIterator, error) {
return m.query(name, value)
}

// Search returns storage iterator.
Expand Down
2 changes: 1 addition & 1 deletion pkg/didcomm/protocol/outofband/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,7 @@ func (s *stubStore) Delete(k string) error {
panic("implement me")
}

func (s *stubStore) Query(query string) (storage.StoreIterator, error) {
func (s *stubStore) Query(name, value string) (storage.StoreIterator, error) {
panic("implement me")
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/internal/gomocks/storage/mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/mock/storage/mock_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (s *MockStore) Delete(k string) error {
}

// Query returns a mocked store iterator and error value.
func (s *MockStore) Query(_ string) (storage.StoreIterator, error) {
func (s *MockStore) Query(indexKey, indexValue string) (storage.StoreIterator, error) {
return s.QueryReturnValue, s.ErrQuery
}

Expand Down
8 changes: 5 additions & 3 deletions pkg/storage/edv/documentprocessor/documentprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ func New(jweEncrypter jose.Encrypter, jweDecrypter jose.Decrypter) *DocumentProc
}

// Encrypt creates a new encrypted document based off of the given structured document.
func (a *DocumentProcessor) Encrypt(structuredDocument *edv.StructuredDocument) (*edv.EncryptedDocument, error) {
func (a *DocumentProcessor) Encrypt(structuredDocument *edv.StructuredDocument,
indexedAttributes []edv.IndexedAttributeCollection) (*edv.EncryptedDocument, error) {
structuredDocumentBytes, err := a.marshal(structuredDocument)
if err != nil {
return nil, fmt.Errorf(failMarshalStructuredDocument, err)
Expand All @@ -60,8 +61,9 @@ func (a *DocumentProcessor) Encrypt(structuredDocument *edv.StructuredDocument)
}

encryptedDoc := edv.EncryptedDocument{
ID: structuredDocument.ID,
JWE: []byte(serializedJWE),
ID: structuredDocument.ID,
IndexedAttributeCollections: indexedAttributes,
JWE: []byte(serializedJWE),
}

return &encryptedDoc, nil
Expand Down
6 changes: 3 additions & 3 deletions pkg/storage/edv/documentprocessor/documentprocessor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ func TestAriesDocumentProcessor_Encrypt(t *testing.T) {
documentProcessor := DocumentProcessor{marshal: failingMarshal}
require.NotNil(t, documentProcessor)

encryptedDocument, err := documentProcessor.Encrypt(nil)
encryptedDocument, err := documentProcessor.Encrypt(nil, nil)
require.EqualError(t, err, fmt.Errorf(failMarshalStructuredDocument, errFailingMarshal).Error())
require.Nil(t, encryptedDocument)
})
t.Run("Fail to encrypt structured document", func(t *testing.T) {
documentProcessor := New(&failingEncrypter{}, nil)
require.NotNil(t, documentProcessor)

encryptedDocument, err := documentProcessor.Encrypt(createStructuredDocument())
encryptedDocument, err := documentProcessor.Encrypt(createStructuredDocument(), nil)
require.EqualError(t, err, fmt.Errorf(failEncryptStructuredDocument, errFailingEncrypter).Error())
require.Nil(t, encryptedDocument)
})
Expand Down Expand Up @@ -145,7 +145,7 @@ func createStructuredDocument() *edv.StructuredDocument {
func createEncryptedDocument(t *testing.T, documentProcessor *DocumentProcessor) *edv.EncryptedDocument {
structuredDocument := createStructuredDocument()

encryptedDocument, err := documentProcessor.Encrypt(structuredDocument)
encryptedDocument, err := documentProcessor.Encrypt(structuredDocument, nil)
require.NoError(t, err)
require.NotNil(t, encryptedDocument)

Expand Down
Loading

0 comments on commit b51ab9a

Please sign in to comment.