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 { ...@@ -26,13 +26,13 @@ type Backup struct {
// NewCmixFromBackup. // NewCmixFromBackup.
// //
// Example BackupReport: // Example BackupReport:
// {"BackupIdListJson":"WyJPRHRRTTA4ZERpV3lXaE0wWUhjanRHWnZQcHRSa1JOZ1pHR2FkTG10dE9BRCJd","BackupParams":""} //{"RestoredContacts":["0AeVYBe87SV45A2UI4AtIe6H4AIyZSLPBPrT6eTBLycD"],"Params":""}
type BackupReport struct { type BackupReport struct {
// The JSON encoded list of E2E partner IDs // The list of restored E2E partner IDs
BackupIdListJson []byte RestoredContacts IdList
// The backup parameters found within the backup file // The backup parameters found within the backup file
BackupParams string Params string
} }
// UpdateBackupFunc contains a function callback that returns new backups. // UpdateBackupFunc contains a function callback that returns new backups.
...@@ -68,19 +68,13 @@ func NewCmixFromBackup(ndfJSON, storageDir, backupPassphrase string, ...@@ -68,19 +68,13 @@ func NewCmixFromBackup(ndfJSON, storageDir, backupPassphrase string,
return nil, err return nil, err
} }
// Marshal ID List
backupIdListJson, err := json.Marshal(backupIdList)
if err != nil {
return nil, err
}
// Construct report // Construct report
report := BackupReport{ report := BackupReport{
BackupIdListJson: backupIdListJson, RestoredContacts: makeIdList(backupIdList),
BackupParams: backupParams, Params: backupParams,
} }
// Marshal report // JSON marshal report
return json.Marshal(report) return json.Marshal(report)
} }
......
...@@ -19,11 +19,6 @@ import ( ...@@ -19,11 +19,6 @@ import (
"gitlab.com/xx_network/primitives/id" "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 // E2ESendReport is the bindings' representation of the return values of
// SendE2E. // SendE2E.
// //
...@@ -52,11 +47,7 @@ func (e *E2e) GetReceptionID() []byte { ...@@ -52,11 +47,7 @@ func (e *E2e) GetReceptionID() []byte {
// - []byte - the marshalled bytes of the IdList object. // - []byte - the marshalled bytes of the IdList object.
func (e *E2e) GetAllPartnerIDs() ([]byte, error) { func (e *E2e) GetAllPartnerIDs() ([]byte, error) {
partnerIds := e.api.GetE2E().GetAllPartnerIDs() partnerIds := e.api.GetE2E().GetAllPartnerIDs()
convertedIds := make([][]byte, len(partnerIds)) return json.Marshal(makeIdList(partnerIds))
for i, partnerId := range partnerIds {
convertedIds[i] = partnerId.Marshal()
}
return json.Marshal(IdList{Ids: convertedIds})
} }
// PayloadSize returns the max payload size for a partitionable E2E message. // PayloadSize returns the max payload size for a partitionable E2E message.
......
...@@ -9,12 +9,17 @@ package bindings ...@@ -9,12 +9,17 @@ package bindings
import ( import (
"encoding/json" "encoding/json"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/elixxir/client/xxdk" "gitlab.com/elixxir/client/xxdk"
"gitlab.com/elixxir/crypto/contact" "gitlab.com/elixxir/crypto/contact"
"gitlab.com/elixxir/primitives/fact" "gitlab.com/elixxir/primitives/fact"
) )
////////////////////////////////////////////////////////////////////////////////
// ReceptionIdentity //
////////////////////////////////////////////////////////////////////////////////
// ReceptionIdentity struct. // ReceptionIdentity struct.
// //
// JSON example: // JSON example:
...@@ -31,6 +36,37 @@ type ReceptionIdentity struct { ...@@ -31,6 +36,37 @@ type ReceptionIdentity struct {
DHKeyPrivate []byte // DH Private key 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 // MakeReceptionIdentity generates a new cryptographic identity for receiving
// messages. // messages.
func (c *Cmix) MakeReceptionIdentity() ([]byte, error) { func (c *Cmix) MakeReceptionIdentity() ([]byte, error) {
...@@ -53,6 +89,10 @@ func (c *Cmix) MakeLegacyReceptionIdentity() ([]byte, error) { ...@@ -53,6 +89,10 @@ func (c *Cmix) MakeLegacyReceptionIdentity() ([]byte, error) {
return ident.Marshal() return ident.Marshal()
} }
////////////////////////////////////////////////////////////////////////////////
// Contact Functions //
////////////////////////////////////////////////////////////////////////////////
// GetIDFromContact accepts a marshalled contact.Contact object and returns a // GetIDFromContact accepts a marshalled contact.Contact object and returns a
// marshalled id.ID object. // marshalled id.ID object.
func GetIDFromContact(marshaled []byte) ([]byte, error) { func GetIDFromContact(marshaled []byte) ([]byte, error) {
...@@ -75,6 +115,10 @@ func GetPubkeyFromContact(marshaled []byte) ([]byte, error) { ...@@ -75,6 +115,10 @@ func GetPubkeyFromContact(marshaled []byte) ([]byte, error) {
return json.Marshal(cnt.DhPubKey) return json.Marshal(cnt.DhPubKey)
} }
////////////////////////////////////////////////////////////////////////////////
// Fact Functions //
////////////////////////////////////////////////////////////////////////////////
// Fact is an internal fact type for use in the bindings layer. // Fact is an internal fact type for use in the bindings layer.
// //
// JSON example: // JSON example:
...@@ -140,33 +184,23 @@ func GetFactsFromContact(marshaled []byte) ([]byte, error) { ...@@ -140,33 +184,23 @@ func GetFactsFromContact(marshaled []byte) ([]byte, error) {
return factsListMarshaled, nil 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 // IdList Functions //
// 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 // IdList is a wrapper for a list of marshalled id.ID objects.
// key. type IdList struct {
func LoadReceptionIdentity(key string, cmixId int) ([]byte, error) { Ids [][]byte
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 // 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