Skip to content
Snippets Groups Projects
Commit 6fb5ba62 authored by Jono Wenger's avatar Jono Wenger Committed by Richard T. Carback III
Browse files

Delete Fact, FactList, and FactType from interfaces/contact and fix all usages...

Delete Fact, FactList, and FactType from interfaces/contact and fix all usages to use the new objects in primitives
parent 2988fb0f
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@ import (
"gitlab.com/elixxir/client/interfaces"
"gitlab.com/elixxir/client/interfaces/contact"
"gitlab.com/elixxir/client/storage/e2e"
"gitlab.com/elixxir/primitives/fact"
"gitlab.com/xx_network/primitives/id"
)
......@@ -110,6 +111,6 @@ func (c *Client) MakePrecannedContact(precannedID uint) contact.Contact {
ID: precanned.ID,
DhPubKey: partnerPubKey,
OwnershipProof: nil,
Facts: make([]contact.Fact, 0),
Facts: make([]fact.Fact, 0),
}
}
\ No newline at end of file
......@@ -11,6 +11,7 @@ import (
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/diffieHellman"
cAuth "gitlab.com/elixxir/crypto/e2e/auth"
"gitlab.com/elixxir/primitives/fact"
"gitlab.com/elixxir/primitives/format"
"strings"
)
......@@ -148,7 +149,7 @@ func (m *Manager) handleRequest(cmixMsg format.Message,
}
//process the inner payload
facts, msg, err := contact.UnstringifyFactList(
facts, msg, err := fact.UnstringifyFactList(
string(requestFmt.msgPayload))
if err != nil {
jww.WARN.Printf("failed to parse facts and message "+
......@@ -264,7 +265,7 @@ func (m *Manager) doConfirm(sr *auth.SentRequest, grp *cyclic.Group,
ID: sr.GetPartner().DeepCopy(),
DhPubKey: partnerPubKey.DeepCopy(),
OwnershipProof: copySlice(ownershipProof),
Facts: make([]contact.Fact, 0),
Facts: make([]fact.Fact, 0),
}
// fixme: if a crash occurs before or during the calls, the notification
......
......@@ -3,11 +3,12 @@ package bindings
import (
"errors"
"gitlab.com/elixxir/client/interfaces/contact"
"gitlab.com/elixxir/primitives/fact"
)
/* fact object*/
type Fact struct {
f *contact.Fact
f *fact.Fact
}
func (f *Fact) Get() string {
......@@ -61,13 +62,13 @@ func (fl *FactList) Get(i int) Fact {
return Fact{f: &(fl.c.Facts)[i]}
}
func (fl *FactList) Add(fact string, factType int) error {
ft := contact.FactType(factType)
func (fl *FactList) Add(factData string, factType int) error {
ft := fact.FactType(factType)
if !ft.IsValid() {
return errors.New("Invalid fact type")
}
fl.c.Facts = append(fl.c.Facts, contact.Fact{
Fact: fact,
fl.c.Facts = append(fl.c.Facts, fact.Fact{
Fact: factData,
T: ft,
})
return nil
......
......@@ -20,7 +20,7 @@ require (
gitlab.com/elixxir/comms v0.0.3
gitlab.com/elixxir/crypto v0.0.5-0.20201109234712-7e64de16970d
gitlab.com/elixxir/ekv v0.1.3
gitlab.com/elixxir/primitives v0.0.2
gitlab.com/elixxir/primitives v0.0.3-0.20201116174806-97f190989704
gitlab.com/xx_network/comms v0.0.3
gitlab.com/xx_network/crypto v0.0.4
gitlab.com/xx_network/primitives v0.0.2
......
......@@ -258,10 +258,6 @@ gitlab.com/elixxir/crypto v0.0.3 h1:znCt/x2bL4y8czTPaaFkwzdgSgW3BJc/1+dxyf1jqVw=
gitlab.com/elixxir/crypto v0.0.3/go.mod h1:ZNgBOblhYToR4m8tj4cMvJ9UsJAUKq+p0gCp07WQmhA=
gitlab.com/elixxir/crypto v0.0.4 h1:8eWjvUepCU2PiqZM2NFYo6rFg1w8KWO1hMDwMNFEqoI=
gitlab.com/elixxir/crypto v0.0.4/go.mod h1:ZNgBOblhYToR4m8tj4cMvJ9UsJAUKq+p0gCp07WQmhA=
gitlab.com/elixxir/crypto v0.0.5-0.20201109195944-c4a4090b258a h1:SnZm8bO8Cw4j7FDGqzt4kfP58peuNE3z1Q3NqifXwns=
gitlab.com/elixxir/crypto v0.0.5-0.20201109195944-c4a4090b258a/go.mod h1:ZNgBOblhYToR4m8tj4cMvJ9UsJAUKq+p0gCp07WQmhA=
gitlab.com/elixxir/crypto v0.0.5-0.20201109203841-ba162a25be6e h1:rkT8Pzjgo9oF3uS8ExHGNUQoJX/22qK3lU+vU8QsOCY=
gitlab.com/elixxir/crypto v0.0.5-0.20201109203841-ba162a25be6e/go.mod h1:ZNgBOblhYToR4m8tj4cMvJ9UsJAUKq+p0gCp07WQmhA=
gitlab.com/elixxir/crypto v0.0.5-0.20201109234712-7e64de16970d h1:9Peb/peftTVeO5gYqi37sZycMEiu05+2VZ/j8d5lldI=
gitlab.com/elixxir/crypto v0.0.5-0.20201109234712-7e64de16970d/go.mod h1:ZNgBOblhYToR4m8tj4cMvJ9UsJAUKq+p0gCp07WQmhA=
gitlab.com/elixxir/ekv v0.1.3 h1:OE+LBMIhjGUMwc6hHJzYvEPNJQV7t1vMnJyIgxUMUo8=
......@@ -273,6 +269,8 @@ gitlab.com/elixxir/primitives v0.0.1 h1:q61anawANlNAExfkeQEE1NCsNih6vNV1FFLoUQX6
gitlab.com/elixxir/primitives v0.0.1/go.mod h1:kNp47yPqja2lHSiS4DddTvFpB/4D9dB2YKnw5c+LJCE=
gitlab.com/elixxir/primitives v0.0.2 h1:PvyOOp/A6tCtmU7YnGhCCPRdmEogEzCi0Li/WfiVjGo=
gitlab.com/elixxir/primitives v0.0.2/go.mod h1:3fxFHSlQhkV4vs+S0dZEz3Om3m+40WX8L806yvSnNFc=
gitlab.com/elixxir/primitives v0.0.3-0.20201116174806-97f190989704 h1:JkFREumz8skDqkCjjzZnlf5tg+PBiMB9kfVn9z0VEfE=
gitlab.com/elixxir/primitives v0.0.3-0.20201116174806-97f190989704/go.mod h1:3fxFHSlQhkV4vs+S0dZEz3Om3m+40WX8L806yvSnNFc=
gitlab.com/xx_network/comms v0.0.0-20200805174823-841427dd5023/go.mod h1:owEcxTRl7gsoM8c3RQ5KAm5GstxrJp5tn+6JfQ4z5Hw=
gitlab.com/xx_network/comms v0.0.3 h1:ch1eJI4WXUE/Kz0Kp9uDWX16B+hfVFmdHY+EOai4Wzc=
gitlab.com/xx_network/comms v0.0.3/go.mod h1:YViGbRj7FjJYoaO4NpALGEd9dK/l8uUT000FEBbUTL8=
......
......@@ -4,6 +4,7 @@ import (
"encoding/json"
"github.com/pkg/errors"
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/primitives/fact"
"gitlab.com/xx_network/primitives/id"
)
......@@ -18,7 +19,7 @@ type Contact struct {
ID *id.ID
DhPubKey *cyclic.Int
OwnershipProof []byte
Facts FactList
Facts fact.FactList
}
func (c Contact) Marshal() ([]byte, error) {
......
package contact
type Fact struct {
Fact string
T FactType
}
func NewFact(ft FactType, fact string) (Fact, error) {
//todo: filter the fact string
return Fact{
Fact: fact,
T: ft,
}, nil
}
// marshal is for transmission for UDB, not a part of the fact interface
func (f Fact) Stringify() string {
return f.T.Stringify() + f.Fact
}
func UnstringifyFact(s string) (Fact, error) {
ft, err := UnstringifyFactType(s)
if err != nil {
return Fact{}, err
}
return NewFact(ft, s)
}
package contact
import (
"github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman"
"strings"
)
type FactList []Fact
func (fl FactList) Stringify() string {
stringList := make([]string, len(fl))
for index, f := range fl {
stringList[index] = f.Stringify()
}
return strings.Join(stringList, factDelimiter) + factBreak
}
// unstrignifys facts followed by a facts break and with arbatrary data
// atttached at the end
func UnstringifyFactList(s string) ([]Fact, string, error) {
parts := strings.SplitN(s, factBreak, 2)
if len(parts) != 2 {
return nil, "", errors.New("Invalid fact string passed")
}
factStrings := strings.Split(parts[0], factDelimiter)
var factList []Fact
for _, fString := range factStrings {
fact, err := UnstringifyFact(fString)
if err != nil {
jww.WARN.Printf("Fact failed to unstringify, dropped: %s",
err)
} else {
factList = append(factList, fact)
}
}
return factList, parts[1], nil
}
package contact
import (
"fmt"
"github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman"
)
type FactType uint8
const (
Username FactType = 0
Email FactType = 1
Phone FactType = 2
)
func (t FactType) String() string {
switch t {
case Username:
return "Username"
case Email:
return "Email"
case Phone:
return "Phone"
default:
return fmt.Sprintf("Unknown Fact FactType: %d", t)
}
}
func (t FactType) Stringify() string {
switch t {
case Username:
return "U"
case Email:
return "E"
case Phone:
return "P"
}
jww.FATAL.Panicf("Unknown Fact FactType: %d", t)
return "error"
}
func UnstringifyFactType(s string) (FactType, error) {
switch s {
case "U":
return Username, nil
case "E":
return Email, nil
case "P":
return Phone, nil
}
return 3, errors.Errorf("Unknown Fact FactType: %s", s)
}
func (t FactType) IsValid() bool {
return t == Username || t == Email || t == Phone
}
......@@ -3,6 +3,7 @@ package user
import (
"gitlab.com/elixxir/client/interfaces/contact"
"gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/primitives/fact"
"gitlab.com/xx_network/crypto/signature/rsa"
"gitlab.com/xx_network/primitives/id"
)
......@@ -27,6 +28,6 @@ func (u User) GetContact() contact.Contact {
return contact.Contact{
ID: u.ID.DeepCopy(),
DhPubKey: u.E2eDhPublicKey,
Facts: make([]contact.Fact, 0),
Facts: make([]fact.Fact, 0),
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment