diff options
Diffstat (limited to 'vendor/go.mau.fi/whatsmeow/msgsecret.go')
-rw-r--r-- | vendor/go.mau.fi/whatsmeow/msgsecret.go | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/vendor/go.mau.fi/whatsmeow/msgsecret.go b/vendor/go.mau.fi/whatsmeow/msgsecret.go index a4cbb17b..5f3e16ac 100644 --- a/vendor/go.mau.fi/whatsmeow/msgsecret.go +++ b/vendor/go.mau.fi/whatsmeow/msgsecret.go @@ -7,7 +7,6 @@ package whatsmeow import ( - "crypto/rand" "crypto/sha256" "fmt" "time" @@ -19,6 +18,7 @@ import ( "go.mau.fi/whatsmeow/types/events" "go.mau.fi/whatsmeow/util/gcmutil" "go.mau.fi/whatsmeow/util/hkdfutil" + "go.mau.fi/whatsmeow/util/randbytes" ) type MsgSecretType string @@ -107,11 +107,7 @@ func (cli *Client) encryptMsgSecret(chat, origSender types.JID, origMsgID types. } secretKey, additionalData := generateMsgSecretKey(useCase, ownID, origMsgID, origSender, baseEncKey) - iv = make([]byte, 12) - _, err = rand.Read(iv) - if err != nil { - return nil, nil, fmt.Errorf("failed to generate iv: %w", err) - } + iv = randbytes.Make(12) ciphertext, err = gcmutil.Encrypt(secretKey, iv, plaintext, additionalData) if err != nil { return nil, nil, fmt.Errorf("failed to encrypt secret message: %w", err) @@ -132,7 +128,7 @@ func (cli *Client) encryptMsgSecret(chat, origSender types.JID, origMsgID types. // } func (cli *Client) DecryptReaction(reaction *events.Message) (*waProto.ReactionMessage, error) { encReaction := reaction.Message.GetEncReactionMessage() - if encReaction != nil { + if encReaction == nil { return nil, ErrNotEncryptedReactionMessage } plaintext, err := cli.decryptMsgSecret(reaction, EncSecretReaction, encReaction, encReaction.GetTargetMessageKey()) @@ -225,11 +221,7 @@ func (cli *Client) BuildPollVote(pollInfo *types.MessageInfo, optionNames []stri // // resp, err := cli.SendMessage(context.Background(), chat, cli.BuildPollCreation("meow?", []string{"yes", "no"}, 1)) func (cli *Client) BuildPollCreation(name string, optionNames []string, selectableOptionCount int) *waProto.Message { - msgSecret := make([]byte, 32) - _, err := rand.Read(msgSecret) - if err != nil { - panic(err) - } + msgSecret := randbytes.Make(32) if selectableOptionCount < 0 || selectableOptionCount > len(optionNames) { selectableOptionCount = 0 } |