package Seeder import ( "encoding/base64" "time" "git.tovijaeschke.xyz/tovi/Envelope/Backend/Database" "git.tovijaeschke.xyz/tovi/Envelope/Backend/Models" ) func seedFriend(userRequestTo, userRequestFrom Models.User) error { var ( friendRequest Models.FriendRequest decodedID []byte id []byte decodedSymKey []byte symKey []byte err error ) decodedID, err = base64.StdEncoding.DecodeString(userRequestFrom.FriendID) if err != nil { return err } id, err = decryptWithPrivateKey(decodedID, decodedPrivateKey) if err != nil { return err } decodedSymKey, err = base64.StdEncoding.DecodeString(userRequestFrom.FriendSymmetricKey) if err != nil { return err } symKey, err = decryptWithPrivateKey(decodedSymKey, decodedPrivateKey) friendRequest = Models.FriendRequest{ UserID: userRequestTo.ID, AcceptedAt: time.Now(), FriendID: base64.StdEncoding.EncodeToString( encryptWithPublicKey(id, decodedPublicKey), ), SymmetricKey: base64.StdEncoding.EncodeToString( encryptWithPublicKey(symKey, decodedPublicKey), ), } return Database.CreateFriendRequest(&friendRequest) } func SeedFriends() { var ( primaryUser Models.User secondaryUser Models.User i int err error ) primaryUser, err = Database.GetUserByUsername("testUser") if err != nil { panic(err) } secondaryUser, err = Database.GetUserByUsername("testUser2") if err != nil { panic(err) } err = seedFriend(primaryUser, secondaryUser) if err != nil { panic(err) } err = seedFriend(secondaryUser, primaryUser) if err != nil { panic(err) } for i = 0; i <= 3; i++ { secondaryUser, err = Database.GetUserByUsername(userNames[i]) if err != nil { panic(err) } err = seedFriend(primaryUser, secondaryUser) if err != nil { panic(err) } err = seedFriend(secondaryUser, primaryUser) if err != nil { panic(err) } } }