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 symKey aesKey encPublicKey []byte err error ) symKey, err = generateAesKey() if err != nil { return err } encPublicKey, err = symKey.aesEncrypt([]byte(publicKey)) if err != nil { return err } friendRequest = Models.FriendRequest{ UserID: userRequestTo.ID, UserUsername: userRequestTo.Username, AcceptedAt: time.Now(), FriendID: base64.StdEncoding.EncodeToString( encryptWithPublicKey( []byte(userRequestFrom.ID.String()), decodedPublicKey, ), ), FriendUsername: base64.StdEncoding.EncodeToString( encryptWithPublicKey( []byte(userRequestFrom.Username), decodedPublicKey, ), ), FriendPublicAsymmetricKey: base64.StdEncoding.EncodeToString( encPublicKey, ), SymmetricKey: base64.StdEncoding.EncodeToString( encryptWithPublicKey(symKey.Key, 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("ATestUser2") 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) } } }