Remove unnecessary base64 util
This commit is contained in:
parent
13f47319b2
commit
d1897a2b80
11 changed files with 27 additions and 58 deletions
|
@ -1,6 +1,7 @@
|
|||
package textgapi
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
|
@ -166,7 +167,7 @@ func (c *Client) decryptImages(messages *binary.FetchMessagesResponse) error {
|
|||
}
|
||||
|
||||
func (c *Client) decryptImageData(imageId string, key []byte) ([]byte, error) {
|
||||
decodedRpcKey, err := crypto.Base64DecodeStandard(c.rpcKey)
|
||||
decodedRpcKey, err := base64.StdEncoding.DecodeString(c.rpcKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -192,7 +193,7 @@ func (c *Client) decryptImageData(imageId string, key []byte) ([]byte, error) {
|
|||
if err2 != nil {
|
||||
return nil, err2
|
||||
}
|
||||
download_metadata_b64 := crypto.EncodeBase64Standard(download_metadata_bytes)
|
||||
download_metadata_b64 := base64.StdEncoding.EncodeToString(download_metadata_bytes)
|
||||
req, err := http.NewRequest("GET", util.UPLOAD_MEDIA, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
package crypto
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func EncodeBase64Standard(data []byte) string {
|
||||
return base64.StdEncoding.EncodeToString(data)
|
||||
}
|
||||
|
||||
func EncodeBase64(data []byte) string {
|
||||
return base64.RawURLEncoding.EncodeToString(data)
|
||||
}
|
||||
|
||||
func Base64Decode(input string) ([]byte, error) {
|
||||
padding := len(input) % 4
|
||||
if padding > 0 {
|
||||
input += strings.Repeat("=", 4-padding)
|
||||
}
|
||||
|
||||
data, err := base64.URLEncoding.DecodeString(input)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func Base64DecodeStandard(input string) ([]byte, error) {
|
||||
decoded, err := base64.StdEncoding.DecodeString(input)
|
||||
if err != nil {
|
||||
fmt.Println("decode error:", err)
|
||||
return nil, err
|
||||
}
|
||||
return decoded, nil
|
||||
}
|
||||
|
||||
func Base64Encode(input []byte) string {
|
||||
return base64.StdEncoding.EncodeToString(input)
|
||||
}
|
|
@ -33,13 +33,13 @@ func (t *JWK) Marshal() ([]byte, error) {
|
|||
}
|
||||
|
||||
func (t *JWK) PrivKeyB64Bytes() ([]byte, error) {
|
||||
decodedPrivateKey, err2 := Base64Decode(t.D)
|
||||
decodedPrivateKey, err2 := base64.RawURLEncoding.DecodeString(t.D)
|
||||
return decodedPrivateKey, err2
|
||||
}
|
||||
|
||||
func (t *JWK) ExtractPublicKeyDetails(pubKey []byte) *JWK {
|
||||
x := EncodeBase64(pubKey[1:33])
|
||||
y := EncodeBase64(pubKey[33:])
|
||||
x := base64.RawURLEncoding.EncodeToString(pubKey[1:33])
|
||||
y := base64.RawURLEncoding.EncodeToString(pubKey[33:])
|
||||
return &JWK{
|
||||
Kty: "EC",
|
||||
Crv: "P-256",
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"crypto/hmac"
|
||||
"crypto/rand"
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
|
@ -35,7 +36,7 @@ func NewCryptor(aes_key []byte, sha_key []byte) *Cryptor {
|
|||
}
|
||||
|
||||
func (c *Cryptor) SaveAsJson() {
|
||||
AES_B64, SHA_B64 := EncodeBase64Standard(c.AES_CTR_KEY_256), EncodeBase64Standard(c.SHA_256_KEY)
|
||||
AES_B64, SHA_B64 := base64.StdEncoding.EncodeToString(c.AES_CTR_KEY_256), base64.StdEncoding.EncodeToString(c.SHA_256_KEY)
|
||||
inter := struct {
|
||||
AES_CTR_KEY_256 string
|
||||
SHA_256_KEY string
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
package crypto
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
"go.mau.fi/mautrix-gmessages/libgm/binary"
|
||||
)
|
||||
|
||||
func DecodeAndEncodeB64(data string, msg proto.Message) error {
|
||||
decodedBytes, err := Base64DecodeStandard(data)
|
||||
decodedBytes, err := base64.StdEncoding.DecodeString(data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -19,7 +21,7 @@ func DecodeAndEncodeB64(data string, msg proto.Message) error {
|
|||
}
|
||||
|
||||
func DecodeEncodedResponse(data string) (*binary.EncodedResponse, error) {
|
||||
decodedBytes, err := Base64DecodeStandard(data)
|
||||
decodedBytes, err := base64.StdEncoding.DecodeString(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package crypto
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
"go.mau.fi/mautrix-gmessages/libgm/binary"
|
||||
|
@ -55,6 +57,6 @@ func EncodeProtoB64(message proto.Message) (string, error) {
|
|||
if protoErr != nil {
|
||||
return "", protoErr
|
||||
}
|
||||
encodedStr := EncodeBase64Standard(protoBytes)
|
||||
encodedStr := base64.StdEncoding.EncodeToString(protoBytes)
|
||||
return encodedStr, nil
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package textgapi
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"io"
|
||||
"log"
|
||||
|
@ -135,7 +136,7 @@ func (c *Client) StartUploadMedia(image *Image) (*StartGoogleUpload, error) {
|
|||
|
||||
func (c *Client) buildStartUploadPayload() (string, error) {
|
||||
|
||||
decodedRpcKey, err := crypto.Base64DecodeStandard(c.rpcKey)
|
||||
decodedRpcKey, err := base64.StdEncoding.DecodeString(c.rpcKey)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
package textgapi
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"log"
|
||||
|
||||
"go.mau.fi/mautrix-gmessages/libgm/binary"
|
||||
"go.mau.fi/mautrix-gmessages/libgm/crypto"
|
||||
)
|
||||
|
||||
func (c *Client) handleSeperateOpCode(msgData *binary.MessageData) {
|
||||
decodedBytes, err := crypto.Base64DecodeStandard(msgData.EncodedData)
|
||||
decodedBytes, err := base64.StdEncoding.DecodeString(msgData.EncodedData)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package textgapi
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"io"
|
||||
"log"
|
||||
"time"
|
||||
|
@ -140,7 +141,7 @@ func (p *Pairer) GetWebEncryptionKey() {
|
|||
if err2 != nil {
|
||||
p.client.Logger.Err(err2).Msg("Parse webkeyresponse into proto struct error")
|
||||
}
|
||||
key := crypto.EncodeBase64Standard(p.client.rpc.webAuthKey)
|
||||
key := base64.StdEncoding.EncodeToString(p.client.rpc.webAuthKey)
|
||||
p.ticker.Stop()
|
||||
reconnectErr := p.client.Reconnect(key)
|
||||
if reconnectErr != nil {
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
package payload
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
|
||||
"go.mau.fi/mautrix-gmessages/libgm/binary"
|
||||
"go.mau.fi/mautrix-gmessages/libgm/crypto"
|
||||
"go.mau.fi/mautrix-gmessages/libgm/util"
|
||||
)
|
||||
|
||||
func RefreshPhoneRelay(rpcKey string) ([]byte, *binary.Container, error) {
|
||||
decodedRpcKey, err1 := crypto.Base64DecodeStandard(rpcKey)
|
||||
decodedRpcKey, err1 := base64.StdEncoding.DecodeString(rpcKey)
|
||||
if err1 != nil {
|
||||
return nil, nil, err1
|
||||
}
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
package textgapi
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
|
||||
"go.mau.fi/mautrix-gmessages/libgm/binary"
|
||||
"go.mau.fi/mautrix-gmessages/libgm/crypto"
|
||||
"go.mau.fi/mautrix-gmessages/libgm/util"
|
||||
)
|
||||
|
||||
|
@ -16,6 +17,6 @@ func (p *Pairer) GenerateQRCodeData() (string, error) {
|
|||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
cData := crypto.Base64Encode(encodedUrlData)
|
||||
cData := base64.StdEncoding.EncodeToString(encodedUrlData)
|
||||
return util.QR_CODE_URL + cData, nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue