Added payload reset on PayloadManager level
This commit is contained in:
parent
48abeedc53
commit
5eb8e5a34f
|
@ -47,7 +47,7 @@ type CreateCommunity struct {
|
|||
Tags []string `json:"tags,omitempty"`
|
||||
}
|
||||
|
||||
func adaptIdentityImageToProtobuf(img *userimages.IdentityImage) *protobuf.IdentityImage {
|
||||
func adaptIdentityImageToProtobuf(img userimages.IdentityImage) *protobuf.IdentityImage {
|
||||
return &protobuf.IdentityImage{
|
||||
Payload: img.Payload,
|
||||
SourceType: protobuf.IdentityImage_RAW_PAYLOAD,
|
||||
|
@ -103,8 +103,8 @@ func (c *CreateCommunity) ToCommunityDescription() (*protobuf.CommunityDescripti
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, img := range imgs {
|
||||
ciis[img.Name] = adaptIdentityImageToProtobuf(&img)
|
||||
for i := range imgs {
|
||||
ciis[imgs[i].Name] = adaptIdentityImageToProtobuf(imgs[i])
|
||||
}
|
||||
}
|
||||
if c.Banner.ImagePath != "" {
|
||||
|
@ -113,7 +113,7 @@ func (c *CreateCommunity) ToCommunityDescription() (*protobuf.CommunityDescripti
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ciis[img.Name] = adaptIdentityImageToProtobuf(img)
|
||||
ciis[img.Name] = adaptIdentityImageToProtobuf(*img)
|
||||
}
|
||||
ci.Images = ciis
|
||||
log.Info("set images", "images", ci)
|
||||
|
|
|
@ -13,12 +13,12 @@ import (
|
|||
|
||||
type PairingClient struct {
|
||||
*http.Client
|
||||
PayloadManager
|
||||
|
||||
baseAddress *url.URL
|
||||
certPEM []byte
|
||||
privateKey *ecdsa.PrivateKey
|
||||
serverMode Mode
|
||||
PayloadManager PayloadManager
|
||||
baseAddress *url.URL
|
||||
certPEM []byte
|
||||
privateKey *ecdsa.PrivateKey
|
||||
serverMode Mode
|
||||
}
|
||||
|
||||
func NewPairingClient(c *ConnectionParams, config *PairingPayloadManagerConfig) (*PairingClient, error) {
|
||||
|
|
|
@ -145,3 +145,7 @@ func (m *MockEncryptOnlyPayloadManager) ToSend() []byte {
|
|||
func (m *MockEncryptOnlyPayloadManager) Received() []byte {
|
||||
return m.pem.Received()
|
||||
}
|
||||
|
||||
func (m *MockEncryptOnlyPayloadManager) ResetPayload() {
|
||||
m.pem.ResetPayload()
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ type PayloadManager interface {
|
|||
Receive(data []byte) error
|
||||
ToSend() []byte
|
||||
Received() []byte
|
||||
ResetPayload()
|
||||
}
|
||||
|
||||
// PairingPayloadManagerConfig represents the initialisation parameters required for a PairingPayloadManager
|
||||
|
@ -35,6 +36,7 @@ type PairingPayloadManagerConfig struct {
|
|||
|
||||
// PairingPayloadManager is responsible for the whole lifecycle of a PairingPayload
|
||||
type PairingPayloadManager struct {
|
||||
pp *PairingPayload
|
||||
pem *PayloadEncryptionManager
|
||||
ppm *PairingPayloadMarshaller
|
||||
ppr PayloadRepository
|
||||
|
@ -51,6 +53,7 @@ func NewPairingPayloadManager(pk *ecdsa.PrivateKey, config *PairingPayloadManage
|
|||
p := new(PairingPayload)
|
||||
|
||||
return &PairingPayloadManager{
|
||||
pp: p,
|
||||
pem: pem,
|
||||
ppm: NewPairingPayloadMarshaller(p),
|
||||
ppr: NewPairingPayloadRepository(p, config),
|
||||
|
@ -97,6 +100,12 @@ func (ppm *PairingPayloadManager) Received() []byte {
|
|||
return ppm.pem.Received()
|
||||
}
|
||||
|
||||
// ResetPayload resets all payload state managed by the PairingPayloadManager
|
||||
func (ppm *PairingPayloadManager) ResetPayload() {
|
||||
ppm.pp.ResetPayload()
|
||||
ppm.pem.ResetPayload()
|
||||
}
|
||||
|
||||
// EncryptionPayload represents the plain text and encrypted text of payload data
|
||||
type EncryptionPayload struct {
|
||||
plain []byte
|
||||
|
@ -161,6 +170,10 @@ type PairingPayload struct {
|
|||
password string
|
||||
}
|
||||
|
||||
func (pp *PairingPayload) ResetPayload() {
|
||||
*pp = PairingPayload{}
|
||||
}
|
||||
|
||||
// PairingPayloadMarshaller is responsible for marshalling and unmarshalling PairingServer payload data
|
||||
type PairingPayloadMarshaller struct {
|
||||
*PairingPayload
|
||||
|
|
|
@ -9,10 +9,10 @@ import (
|
|||
|
||||
type PairingServer struct {
|
||||
Server
|
||||
PayloadManager
|
||||
|
||||
pk *ecdsa.PrivateKey
|
||||
mode Mode
|
||||
PayloadManager PayloadManager
|
||||
pk *ecdsa.PrivateKey
|
||||
mode Mode
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
|
|
|
@ -35,7 +35,7 @@ func (s *PairingServerSuite) TestPairingServer_StartPairing() {
|
|||
s.PS.mode = m
|
||||
|
||||
if m == Sending {
|
||||
err := s.PS.PayloadManager.Mount()
|
||||
err := s.PS.Mount()
|
||||
s.Require().NoError(err)
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,7 @@ func (s *PairingServerSuite) TestPairingServer_StartPairing() {
|
|||
s.Require().NoError(err)
|
||||
|
||||
if m == Receiving {
|
||||
err := c.PayloadManager.Mount()
|
||||
err := c.Mount()
|
||||
s.Require().NoError(err)
|
||||
}
|
||||
|
||||
|
@ -73,18 +73,18 @@ func (s *PairingServerSuite) TestPairingServer_StartPairing() {
|
|||
|
||||
switch m {
|
||||
case Receiving:
|
||||
s.Require().Equal(c.PayloadManager.(*MockEncryptOnlyPayloadManager).pem.toSend.plain, s.PS.PayloadManager.Received())
|
||||
s.Require().Equal(c.PayloadManager.(*MockEncryptOnlyPayloadManager).pem.toSend.plain, s.PS.Received())
|
||||
s.Require().Equal(s.PS.PayloadManager.(*MockEncryptOnlyPayloadManager).pem.received.encrypted, c.PayloadManager.(*MockEncryptOnlyPayloadManager).pem.toSend.encrypted)
|
||||
s.Require().Nil(s.PS.PayloadManager.ToSend())
|
||||
s.Require().Nil(c.PayloadManager.Received())
|
||||
s.Require().Nil(s.PS.ToSend())
|
||||
s.Require().Nil(c.Received())
|
||||
case Sending:
|
||||
s.Require().Equal(c.PayloadManager.Received(), s.PS.PayloadManager.(*MockEncryptOnlyPayloadManager).pem.toSend.plain)
|
||||
s.Require().Equal(c.Received(), s.PS.PayloadManager.(*MockEncryptOnlyPayloadManager).pem.toSend.plain)
|
||||
s.Require().Equal(c.PayloadManager.(*MockEncryptOnlyPayloadManager).pem.received.encrypted, s.PS.PayloadManager.(*MockEncryptOnlyPayloadManager).pem.toSend.encrypted)
|
||||
s.Require().Nil(c.PayloadManager.ToSend())
|
||||
s.Require().Nil(s.PS.PayloadManager.Received())
|
||||
s.Require().Nil(c.ToSend())
|
||||
s.Require().Nil(s.PS.Received())
|
||||
}
|
||||
|
||||
// Reset the server's PayloadEncryptionManager
|
||||
s.PS.PayloadManager.(*MockEncryptOnlyPayloadManager).pem.ResetPayload()
|
||||
s.PS.PayloadManager.(*MockEncryptOnlyPayloadManager).ResetPayload()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue