diff --git a/client/identity.go b/client/identity.go index 24f49ed..e47d7b6 100644 --- a/client/identity.go +++ b/client/identity.go @@ -84,7 +84,7 @@ func (id *Identity) CheckInvitation(ReceivedContact *meowlib.ContactCard) (isAns func (id *Identity) AnswerInvitation(MyName string, ContactName string, MessageServerIdxs []int, ReceivedContact *meowlib.ContactCard) *Peer { var peer Peer - var myContactCard meowlib.ContactCard + //var myContactCard meowlib.ContactCard peer.MyIdentity = meowlib.NewKeyPair() peer.MyEncryptionKp = meowlib.NewKeyPair() peer.MyLookupKp = meowlib.NewKeyPair() @@ -96,14 +96,14 @@ func (id *Identity) AnswerInvitation(MyName string, ContactName string, MessageS peer.Contact = *ReceivedContact for _, i := range MessageServerIdxs { srv := id.MessageServers.Servers[i].ServerData - myContactCard.PullServers = append(myContactCard.PullServers, &srv) + peer.MyContact.PullServers = append(peer.MyContact.PullServers, &srv) } - myContactCard.Name = MyName - myContactCard.ContactPublicKey = peer.MyIdentity.Public - myContactCard.EncryptionPublicKey = peer.MyEncryptionKp.Public - myContactCard.LookupPublicKey = peer.MyLookupKp.Public - myContactCard.InvitationId = ReceivedContact.InvitationId - + peer.MyContact.Name = MyName + peer.MyContact.ContactPublicKey = peer.MyIdentity.Public + peer.MyContact.EncryptionPublicKey = peer.MyEncryptionKp.Public + peer.MyContact.LookupPublicKey = peer.MyLookupKp.Public + peer.MyContact.InvitationId = ReceivedContact.InvitationId + peer.InvitationId = ReceivedContact.InvitationId id.Peers = append(id.Peers, peer) return &peer diff --git a/contactcard_test.go b/contactcard_test.go index 1939655..9ca34f8 100644 --- a/contactcard_test.go +++ b/contactcard_test.go @@ -1,12 +1,13 @@ package meowlib import ( + "encoding/json" "testing" "github.com/stretchr/testify/assert" ) -func TestCompress(t *testing.T) { +func TestCompressAndJson(t *testing.T) { kp1 := NewKeyPair() kp2 := NewKeyPair() kp3 := NewKeyPair() @@ -26,4 +27,39 @@ func TestCompress(t *testing.T) { println(err) } assert.Equal(t, ncc.Name, cc.Name) + if err != nil { + println(err) + } + jsoncc, err := json.Marshal(cc) + var cc1 ContactCard + err = json.Unmarshal(jsoncc, &cc1) + if err != nil { + println(err) + } +} + +func TestStaticJson(t *testing.T) { + ccsrt := ` + { + "contact_public_key": "LS0tLS1CRUdJTiBQR1AgUFVCTElDIEtFWSBCTE9DSy0tLS0tClZlcnNpb246IEdvcGVuUEdQIDIuNy40CkNvbW1lbnQ6IGh0dHBzOi8vZ29wZW5wZ3Aub3JnCgp4ak1FWlpST1pCWUpLd1lCQkFIYVJ3OEJBUWRBZy9iRnR4WG5hRjZLOFEzdGVWcmt3Y3YvRTV6TE94WnVZaXVvCm5MVkdtdWZOQzI1aGJXVWdQRzFoYVd3K3dvOEVFeFlJQUVFRkFtV1VUbVFKRUhmcmlVWXZsWnhyRmlFRXFFMDIKVVRmOTRTY1hJWVdjZCt1SlJpK1ZuR3NDR3dNQ0hnRUNHUUVEQ3drSEFoVUlBeFlBQWdVbkNRSUhBZ0FBYmN3QgpBT1VsTHJEbWpCM0pKeGNWUFNHaU1KTlZrem1idlhMTDVSSnh4aTNuNVVrMUFRQ2NHN29QeDYwTUdHRVNhc0V0CnBTS2VqUGFmNjNTVXhMelRoRFFacTlqOUI4NDRCR1dVVG1RU0Npc0dBUVFCbDFVQkJRRUJCMEJXeXMvaFZHSGcKRFN0V2Jid3VnbnlCdTFWdUlJbVBZMDRsKzRCQWd4QUFZQU1CQ2duQ2VBUVlGZ2dBS2dVQ1paUk9aQWtRZCt1SgpSaStWbkdzV0lRU29UVFpSTi8zaEp4Y2hoWngzNjRsR0w1V2Nhd0liREFBQWkyTUEvMTdUYksyT3FMdzZDSWZmCkE3YnlwYitxNzdHVmZlQmtmY2l3aXlCM2xRSGxBUUROZzJONisxcklEbG40cXRRc0pFSWR1OUlMMzVlMjR6cWwKbEJMSVR0YVBBQT09Cj1KeHZrCi0tLS0tRU5EIFBHUCBQVUJMSUMgS0VZIEJMT0NLLS0tLS0=", + "encryption_public_key": "LS0tLS1CRUdJTiBQR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3K3dvd0VFeFlJQUQ0RkFtUHVqQnNKa0M4aTlzQjVvVjNyRmlFRWpNeEgKZldiZmxMblRhZzFRTHlMMndIbWhYZXNDR3dNQ0hnRUNHUUVEQ3drSEFoVUlBeFlBQWdJaUFRQUF4L0lCQU5kMgpVK3hZM09LQVk5elFSbmlXQXdlVEpoMWxySEpaMHd6RmVQS3JycUJvQVAwYjRISHBoT2dJWWx2TXlqajZ0TXZRCk01RTIzY3ZiWjRPZXRjNmNmeWxIQ2M0NEJHUHVqQnNTQ2lzR0FRUUJsMVVCQlFFQkIwQ2t1bWlndUpNT003Sy8KNEl1NVppYkJUYXAwSzBkNXNybkNCN2tIU2pObGV3TUJDZ25DZUFRWUZnZ0FLZ1VDWSs2TUd3bVFMeUwyd0htaApYZXNXSVFTTXpFZDladCtVdWROcURWQXZJdmJBZWFGZDZ3SWJEQUFBMlcwQS9qY2pZTUtQY3ZXcTA2QVpVKzRHClQwUmQxU2VNUXpzNndCUU9ZejEwQkVMWEFRQ3hTQ2kvN2RqRjZUWFl0SFpBSytrVUEvUHpYaW14bnRvVFpKbjMKV3l1Z0NnPT0KPTFjU20KLS0tLS1FTkQgUEdQIFBVQkxJQyBLRVkgQkxPQ0stLS0tLQ==", + "url": "http://localhost:8080" + } + ] + } + ` + var cc1 ContactCard + jsoncc := []byte(ccsrt) + err := json.Unmarshal(jsoncc, &cc1) + if err != nil { + println(err) + } }