Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
client
Commits
933c3a26
Commit
933c3a26
authored
Jul 29, 2022
by
Josh Brooks
Browse files
Options
Downloads
Patches
Plain Diff
Clean up IdList in bindings
parent
be881be5
No related branches found
No related tags found
2 merge requests
!510
Release
,
!302
Restore BackupReport to original glory
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
bindings/backup.go
+1
-7
1 addition, 7 deletions
bindings/backup.go
bindings/e2eHandler.go
+1
-10
1 addition, 10 deletions
bindings/e2eHandler.go
bindings/identity.go
+60
-26
60 additions, 26 deletions
bindings/identity.go
with
62 additions
and
43 deletions
bindings/backup.go
+
1
−
7
View file @
933c3a26
...
...
@@ -68,15 +68,9 @@ func NewCmixFromBackup(ndfJSON, storageDir, backupPassphrase string,
return
nil
,
err
}
// Serialize list of IDs into bytes
serializedIdList
:=
make
([][]
byte
,
len
(
backupIdList
))
for
i
,
partnerId
:=
range
backupIdList
{
serializedIdList
[
i
]
=
partnerId
.
Marshal
()
}
// Construct report
report
:=
BackupReport
{
RestoredContacts
:
IdList
{
Ids
:
serialized
IdList
}
,
RestoredContacts
:
make
IdList
(
backup
IdList
)
,
Params
:
backupParams
,
}
...
...
This diff is collapsed.
Click to expand it.
bindings/e2eHandler.go
+
1
−
10
View file @
933c3a26
...
...
@@ -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.
...
...
This diff is collapsed.
Click to expand it.
bindings/identity.go
+
60
−
26
View file @
933c3a26
...
...
@@ -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
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment