|
|
@ -4,19 +4,18 @@ import ( |
|
|
|
"encoding/base64" |
|
|
|
|
|
|
|
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Database" |
|
|
|
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Models" |
|
|
|
|
|
|
|
"github.com/gofrs/uuid" |
|
|
|
) |
|
|
|
|
|
|
|
func seedMessage( |
|
|
|
primaryUser, secondaryUser Models.User, |
|
|
|
primaryUser, secondaryUser Database.User, |
|
|
|
primaryUserAssociationKey, secondaryUserAssociationKey string, |
|
|
|
i int, |
|
|
|
) error { |
|
|
|
var ( |
|
|
|
message Models.Message |
|
|
|
messageData Models.MessageData |
|
|
|
message Database.Message |
|
|
|
messageData Database.MessageData |
|
|
|
key, userKey AesKey |
|
|
|
keyCiphertext []byte |
|
|
|
plaintext string |
|
|
@ -61,13 +60,13 @@ func seedMessage( |
|
|
|
panic(err) |
|
|
|
} |
|
|
|
|
|
|
|
messageData = Models.MessageData{ |
|
|
|
messageData = Database.MessageData{ |
|
|
|
Data: base64.StdEncoding.EncodeToString(dataCiphertext), |
|
|
|
SenderID: base64.StdEncoding.EncodeToString(senderIDCiphertext), |
|
|
|
SymmetricKey: base64.StdEncoding.EncodeToString(keyCiphertext), |
|
|
|
} |
|
|
|
|
|
|
|
message = Models.Message{ |
|
|
|
message = Database.Message{ |
|
|
|
MessageData: messageData, |
|
|
|
SymmetricKey: base64.StdEncoding.EncodeToString( |
|
|
|
EncryptWithPublicKey(userKey.Key, decodedPublicKey), |
|
|
@ -75,12 +74,12 @@ func seedMessage( |
|
|
|
AssociationKey: primaryUserAssociationKey, |
|
|
|
} |
|
|
|
|
|
|
|
err = Database.CreateMessage(&message) |
|
|
|
err = (&message).CreateMessage() |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
message = Models.Message{ |
|
|
|
message = Database.Message{ |
|
|
|
MessageData: messageData, |
|
|
|
SymmetricKey: base64.StdEncoding.EncodeToString( |
|
|
|
EncryptWithPublicKey(userKey.Key, decodedPublicKey), |
|
|
@ -88,12 +87,12 @@ func seedMessage( |
|
|
|
AssociationKey: secondaryUserAssociationKey, |
|
|
|
} |
|
|
|
|
|
|
|
return Database.CreateMessage(&message) |
|
|
|
return (&message).CreateMessage() |
|
|
|
} |
|
|
|
|
|
|
|
func seedConversationDetail(key AesKey) (Models.ConversationDetail, error) { |
|
|
|
func seedConversationDetail(key AesKey) (Database.ConversationDetail, error) { |
|
|
|
var ( |
|
|
|
conversationDetail Models.ConversationDetail |
|
|
|
conversationDetail Database.ConversationDetail |
|
|
|
name string |
|
|
|
nameCiphertext []byte |
|
|
|
falseCiphertext []byte |
|
|
@ -118,7 +117,7 @@ func seedConversationDetail(key AesKey) (Models.ConversationDetail, error) { |
|
|
|
panic(err) |
|
|
|
} |
|
|
|
|
|
|
|
conversationDetail = Models.ConversationDetail{ |
|
|
|
conversationDetail = Database.ConversationDetail{ |
|
|
|
Name: base64.StdEncoding.EncodeToString(nameCiphertext), |
|
|
|
TwoUser: base64.StdEncoding.EncodeToString(falseCiphertext), |
|
|
|
AdminAddMembers: base64.StdEncoding.EncodeToString(trueCiphertext), |
|
|
@ -126,17 +125,17 @@ func seedConversationDetail(key AesKey) (Models.ConversationDetail, error) { |
|
|
|
AdminSendMessages: base64.StdEncoding.EncodeToString(falseCiphertext), |
|
|
|
} |
|
|
|
|
|
|
|
err = Database.CreateConversationDetail(&conversationDetail) |
|
|
|
err = (&conversationDetail).CreateConversationDetail() |
|
|
|
return conversationDetail, err |
|
|
|
} |
|
|
|
|
|
|
|
func seedUserConversation( |
|
|
|
user Models.User, |
|
|
|
user Database.User, |
|
|
|
threadID uuid.UUID, |
|
|
|
key AesKey, |
|
|
|
) (Models.UserConversation, error) { |
|
|
|
) (Database.UserConversation, error) { |
|
|
|
var ( |
|
|
|
messageThreadUser Models.UserConversation |
|
|
|
messageThreadUser Database.UserConversation |
|
|
|
conversationDetailIDCiphertext []byte |
|
|
|
adminCiphertext []byte |
|
|
|
err error |
|
|
@ -152,7 +151,7 @@ func seedUserConversation( |
|
|
|
return messageThreadUser, err |
|
|
|
} |
|
|
|
|
|
|
|
messageThreadUser = Models.UserConversation{ |
|
|
|
messageThreadUser = Database.UserConversation{ |
|
|
|
UserID: user.ID, |
|
|
|
ConversationDetailID: base64.StdEncoding.EncodeToString(conversationDetailIDCiphertext), |
|
|
|
Admin: base64.StdEncoding.EncodeToString(adminCiphertext), |
|
|
@ -161,19 +160,19 @@ func seedUserConversation( |
|
|
|
), |
|
|
|
} |
|
|
|
|
|
|
|
err = Database.CreateUserConversation(&messageThreadUser) |
|
|
|
err = (&messageThreadUser).CreateUserConversation() |
|
|
|
return messageThreadUser, err |
|
|
|
} |
|
|
|
|
|
|
|
func seedConversationDetailUser( |
|
|
|
user Models.User, |
|
|
|
conversationDetail Models.ConversationDetail, |
|
|
|
user Database.User, |
|
|
|
conversationDetail Database.ConversationDetail, |
|
|
|
associationKey uuid.UUID, |
|
|
|
admin bool, |
|
|
|
key AesKey, |
|
|
|
) (Models.ConversationDetailUser, error) { |
|
|
|
) (Database.ConversationDetailUser, error) { |
|
|
|
var ( |
|
|
|
conversationDetailUser Models.ConversationDetailUser |
|
|
|
conversationDetailUser Database.ConversationDetailUser |
|
|
|
|
|
|
|
userIDCiphertext []byte |
|
|
|
usernameCiphertext []byte |
|
|
@ -215,7 +214,7 @@ func seedConversationDetailUser( |
|
|
|
return conversationDetailUser, err |
|
|
|
} |
|
|
|
|
|
|
|
conversationDetailUser = Models.ConversationDetailUser{ |
|
|
|
conversationDetailUser = Database.ConversationDetailUser{ |
|
|
|
ConversationDetailID: conversationDetail.ID, |
|
|
|
UserID: base64.StdEncoding.EncodeToString(userIDCiphertext), |
|
|
|
Username: base64.StdEncoding.EncodeToString(usernameCiphertext), |
|
|
@ -224,7 +223,7 @@ func seedConversationDetailUser( |
|
|
|
PublicKey: base64.StdEncoding.EncodeToString(publicKeyCiphertext), |
|
|
|
} |
|
|
|
|
|
|
|
err = Database.CreateConversationDetailUser(&conversationDetailUser) |
|
|
|
err = (&conversationDetailUser).CreateConversationDetailUser() |
|
|
|
|
|
|
|
return conversationDetailUser, err |
|
|
|
} |
|
|
@ -232,11 +231,11 @@ func seedConversationDetailUser( |
|
|
|
// SeedMessages seeds messages & conversations for testing
|
|
|
|
func SeedMessages() { |
|
|
|
var ( |
|
|
|
conversationDetail Models.ConversationDetail |
|
|
|
conversationDetail Database.ConversationDetail |
|
|
|
key AesKey |
|
|
|
primaryUser Models.User |
|
|
|
primaryUser Database.User |
|
|
|
primaryUserAssociationKey uuid.UUID |
|
|
|
secondaryUser Models.User |
|
|
|
secondaryUser Database.User |
|
|
|
secondaryUserAssociationKey uuid.UUID |
|
|
|
i int |
|
|
|
err error |
|
|
|