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

feat: Packager now holds multiple Packers for runtime format selection #717

Merged
merged 2 commits into from
Nov 8, 2019
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
14 changes: 14 additions & 0 deletions pkg/didcomm/common/transport/envelope.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0
*/

package transport

// Envelope contain msg, FromVerKey and ToVerKeys
type Envelope struct {
Message []byte
FromVerKey string
ToVerKeys []string
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,11 @@ Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package envelope
package transport

// Package envelope manages the handling of DIDComm raw messages in JWE compliant envelopes.
// The aim of this package is build these envelopes and parse them. They are mainly used as
// wire-level wrappers of 'payloads' used in DID Exchange flows.

// PackagerCreator method to create new outbound dispatcher service
type PackagerCreator func(prov Provider) (Packager, error)

// Packager provide methods to pack and unpack msg
// Packager manages the handling, building and parsing of DIDComm raw messages in JSON envelopes.
//
// These envelopes are used as wire-level wrappers of messages sent in Aries agent-agent communication.
type Packager interface {
// PackMessage Pack a message for one or more recipients.
//
Expand Down Expand Up @@ -41,10 +36,3 @@ type Packager interface {
// error: error
UnpackMessage(encMessage []byte) (*Envelope, error)
}

// Envelope contain msg, FromVerKey and ToVerKeys
type Envelope struct {
Message []byte
FromVerKey string
ToVerKeys []string
}
90 changes: 0 additions & 90 deletions pkg/didcomm/crypto/jwe/authcrypt/decrypt_jwk_test.go

This file was deleted.

4 changes: 2 additions & 2 deletions pkg/didcomm/dispatcher/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package dispatcher

import (
"github.com/hyperledger/aries-framework-go/pkg/didcomm/common/service"
"github.com/hyperledger/aries-framework-go/pkg/didcomm/envelope"
commontransport "github.com/hyperledger/aries-framework-go/pkg/didcomm/common/transport"
"github.com/hyperledger/aries-framework-go/pkg/didcomm/transport"
)

Expand All @@ -26,7 +26,7 @@ type Outbound interface {

// Provider interface for outbound ctx
type Provider interface {
Packager() envelope.Packager
Packager() commontransport.Packager
OutboundTransports() []transport.OutboundTransport
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/didcomm/dispatcher/outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import (
"fmt"

"github.com/hyperledger/aries-framework-go/pkg/didcomm/common/service"
"github.com/hyperledger/aries-framework-go/pkg/didcomm/envelope"
commontransport "github.com/hyperledger/aries-framework-go/pkg/didcomm/common/transport"
"github.com/hyperledger/aries-framework-go/pkg/didcomm/transport"
)

// OutboundDispatcher dispatch msgs to destination
type OutboundDispatcher struct {
outboundTransports []transport.OutboundTransport
packager envelope.Packager
packager commontransport.Packager
}

// NewOutbound return new dispatcher outbound instance
Expand All @@ -39,7 +39,7 @@ func (o *OutboundDispatcher) Send(msg interface{}, senderVerKey string, des *ser
}

packedMsg, err := o.packager.PackMessage(
&envelope.Envelope{Message: bytes, FromVerKey: senderVerKey, ToVerKeys: des.RecipientKeys})
&commontransport.Envelope{Message: bytes, FromVerKey: senderVerKey, ToVerKeys: des.RecipientKeys})
if err != nil {
return fmt.Errorf("failed to pack msg: %w", err)
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/didcomm/dispatcher/outbound_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,37 @@ import (
"github.com/stretchr/testify/require"

"github.com/hyperledger/aries-framework-go/pkg/didcomm/common/service"
"github.com/hyperledger/aries-framework-go/pkg/didcomm/envelope"
commontransport "github.com/hyperledger/aries-framework-go/pkg/didcomm/common/transport"
"github.com/hyperledger/aries-framework-go/pkg/didcomm/transport"
mockdidcomm "github.com/hyperledger/aries-framework-go/pkg/internal/mock/didcomm"
mockpackager "github.com/hyperledger/aries-framework-go/pkg/internal/mock/didcomm/envelope"
mockpackager "github.com/hyperledger/aries-framework-go/pkg/internal/mock/didcomm/packager"
)

func TestOutboundDispatcher_Send(t *testing.T) {
t.Run("test success", func(t *testing.T) {
o := NewOutbound(&provider{packagerValue: &mockpackager.BasePackager{},
o := NewOutbound(&provider{packagerValue: &mockpackager.Packager{},
outboundTransportsValue: []transport.OutboundTransport{&mockdidcomm.MockOutboundTransport{AcceptValue: true}}})
require.NoError(t, o.Send("data", "", &service.Destination{ServiceEndpoint: "url"}))
})

t.Run("test no outbound transport found", func(t *testing.T) {
o := NewOutbound(&provider{packagerValue: &mockpackager.BasePackager{},
o := NewOutbound(&provider{packagerValue: &mockpackager.Packager{},
outboundTransportsValue: []transport.OutboundTransport{&mockdidcomm.MockOutboundTransport{AcceptValue: false}}})
err := o.Send("data", "", &service.Destination{ServiceEndpoint: "url"})
require.Error(t, err)
require.Contains(t, err.Error(), "no outbound transport found for serviceEndpoint: url")
})

t.Run("test pack msg failure", func(t *testing.T) {
o := NewOutbound(&provider{packagerValue: &mockpackager.BasePackager{PackErr: fmt.Errorf("pack error")},
o := NewOutbound(&provider{packagerValue: &mockpackager.Packager{PackErr: fmt.Errorf("pack error")},
outboundTransportsValue: []transport.OutboundTransport{&mockdidcomm.MockOutboundTransport{AcceptValue: true}}})
err := o.Send("data", "", &service.Destination{ServiceEndpoint: "url"})
require.Error(t, err)
require.Contains(t, err.Error(), "pack error")
})

t.Run("test outbound send failure", func(t *testing.T) {
o := NewOutbound(&provider{packagerValue: &mockpackager.BasePackager{},
o := NewOutbound(&provider{packagerValue: &mockpackager.Packager{},
outboundTransportsValue: []transport.OutboundTransport{
&mockdidcomm.MockOutboundTransport{AcceptValue: true, SendErr: fmt.Errorf("send error")}}})
err := o.Send("data", "", &service.Destination{ServiceEndpoint: "url"})
Expand All @@ -53,11 +53,11 @@ func TestOutboundDispatcher_Send(t *testing.T) {
}

type provider struct {
packagerValue envelope.Packager
packagerValue commontransport.Packager
outboundTransportsValue []transport.OutboundTransport
}

func (p *provider) Packager() envelope.Packager {
func (p *provider) Packager() commontransport.Packager {
return p.packagerValue
}

Expand Down
Loading