Skip to content
Snippets Groups Projects
Commit 65365b4b authored by Jake Taylor's avatar Jake Taylor :lips:
Browse files

Merge branch 'Josh/BackupBindingsPart3' into 'release'

Restore BackupReport to original glory

See merge request !302
parents 3d2f4b0f 933c3a26
No related branches found
No related tags found
2 merge requests!510Release,!302Restore BackupReport to original glory
......@@ -26,13 +26,13 @@ type Backup struct {
// NewCmixFromBackup.
//
// Example BackupReport:
// {"BackupIdListJson":"WyJPRHRRTTA4ZERpV3lXaE0wWUhjanRHWnZQcHRSa1JOZ1pHR2FkTG10dE9BRCJd","BackupParams":""}
//{"RestoredContacts":["0AeVYBe87SV45A2UI4AtIe6H4AIyZSLPBPrT6eTBLycD"],"Params":""}
type BackupReport struct {
// The JSON encoded list of E2E partner IDs
BackupIdListJson []byte
// The list of restored E2E partner IDs
RestoredContacts IdList
// The backup parameters found within the backup file
BackupParams string
Params string
}
// UpdateBackupFunc contains a function callback that returns new backups.
......@@ -68,19 +68,13 @@ func NewCmixFromBackup(ndfJSON, storageDir, backupPassphrase string,
return nil, err
}
// Marshal ID List
backupIdListJson, err := json.Marshal(backupIdList)
if err != nil {
return nil, err
}
// Construct report
report := BackupReport{
BackupIdListJson: backupIdListJson,
BackupParams: backupParams,
RestoredContacts: makeIdList(backupIdList),
Params: backupParams,
}
// Marshal report
// JSON marshal report
return json.Marshal(report)
}
......
......@@ -19,11 +19,6 @@ import (
"gitlab.com/xx_network/primitives/id"
)
// IdList is a wrapper for a list of marshalled id.ID objects.
type IdList struct {
Ids [][]byte
}
// E2ESendReport is the bindings' representation of the return values of
// SendE2E.
//
......@@ -52,11 +47,7 @@ func (e *E2e) GetReceptionID() []byte {
// - []byte - the marshalled bytes of the IdList object.
func (e *E2e) GetAllPartnerIDs() ([]byte, error) {
partnerIds := e.api.GetE2E().GetAllPartnerIDs()
convertedIds := make([][]byte, len(partnerIds))
for i, partnerId := range partnerIds {
convertedIds[i] = partnerId.Marshal()
}
return json.Marshal(IdList{Ids: convertedIds})
return json.Marshal(makeIdList(partnerIds))
}
// PayloadSize returns the max payload size for a partitionable E2E message.
......
......@@ -9,12 +9,17 @@ package bindings
import (
"encoding/json"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/elixxir/client/xxdk"
"gitlab.com/elixxir/crypto/contact"
"gitlab.com/elixxir/primitives/fact"
)
////////////////////////////////////////////////////////////////////////////////
// ReceptionIdentity //
////////////////////////////////////////////////////////////////////////////////
// ReceptionIdentity struct.
//
// JSON example:
......@@ -31,6 +36,37 @@ type ReceptionIdentity struct {
DHKeyPrivate []byte // DH Private key
}
// StoreReceptionIdentity stores the given identity in Cmix storage with the
// given key. This is the ideal way to securely store identities, as the caller
// of this function is only required to store the given key separately rather
// than the keying material.
func StoreReceptionIdentity(key string, identity []byte, cmixId int) error {
cmix, err := cmixTrackerSingleton.get(cmixId)
if err != nil {
return err
}
receptionIdentity, err := xxdk.UnmarshalReceptionIdentity(identity)
if err != nil {
return err
}
return xxdk.StoreReceptionIdentity(key, receptionIdentity, cmix.api)
}
// LoadReceptionIdentity loads the given identity in Cmix storage with the given
// key.
func LoadReceptionIdentity(key string, cmixId int) ([]byte, error) {
cmix, err := cmixTrackerSingleton.get(cmixId)
if err != nil {
return nil, err
}
storageObj, err := cmix.api.GetStorage().Get(key)
if err != nil {
return nil, err
}
return storageObj.Data, nil
}
// MakeReceptionIdentity generates a new cryptographic identity for receiving
// messages.
func (c *Cmix) MakeReceptionIdentity() ([]byte, error) {
......@@ -53,6 +89,10 @@ func (c *Cmix) MakeLegacyReceptionIdentity() ([]byte, error) {
return ident.Marshal()
}
////////////////////////////////////////////////////////////////////////////////
// Contact Functions //
////////////////////////////////////////////////////////////////////////////////
// GetIDFromContact accepts a marshalled contact.Contact object and returns a
// marshalled id.ID object.
func GetIDFromContact(marshaled []byte) ([]byte, error) {
......@@ -75,6 +115,10 @@ func GetPubkeyFromContact(marshaled []byte) ([]byte, error) {
return json.Marshal(cnt.DhPubKey)
}
////////////////////////////////////////////////////////////////////////////////
// Fact Functions //
////////////////////////////////////////////////////////////////////////////////
// Fact is an internal fact type for use in the bindings layer.
//
// JSON example:
......@@ -140,33 +184,23 @@ func GetFactsFromContact(marshaled []byte) ([]byte, error) {
return factsListMarshaled, nil
}
// StoreReceptionIdentity stores the given identity in Cmix storage with the
// given key. This is the ideal way to securely store identities, as the caller
// of this function is only required to store the given key separately rather
// than the keying material.
func StoreReceptionIdentity(key string, identity []byte, cmixId int) error {
cmix, err := cmixTrackerSingleton.get(cmixId)
if err != nil {
return err
}
receptionIdentity, err := xxdk.UnmarshalReceptionIdentity(identity)
if err != nil {
return err
}
return xxdk.StoreReceptionIdentity(key, receptionIdentity, cmix.api)
}
////////////////////////////////////////////////////////////////////////////////
// IdList Functions //
////////////////////////////////////////////////////////////////////////////////
// LoadReceptionIdentity loads the given identity in Cmix storage with the given
// key.
func LoadReceptionIdentity(key string, cmixId int) ([]byte, error) {
cmix, err := cmixTrackerSingleton.get(cmixId)
if err != nil {
return nil, err
}
storageObj, err := cmix.api.GetStorage().Get(key)
if err != nil {
return nil, err
// IdList is a wrapper for a list of marshalled id.ID objects.
type IdList struct {
Ids [][]byte
}
return storageObj.Data, nil
// makeIdList is a helper function which creates an IdList object
// given a list of id.ID's. It serializes each element of the
// given list of id.ID's, places that into a list of []byte's (ie [][]byte)
// and places that in the IdList.
func makeIdList(ids []*id.ID) IdList {
convertedIds := make([][]byte, len(ids))
for i, partnerId := range ids {
convertedIds[i] = partnerId.Marshal()
}
return IdList{Ids: convertedIds}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment