Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
V4NSH4J
GitHub Repository: V4NSH4J/discord-mass-DM-GO
Path: blob/main/utilities/encryption.go
310 views
1
// Copyright (C) 2021 github.com/V4NSH4J
2
//
3
// This source code has been released under the GNU Affero General Public
4
// License v3.0. A copy of this license is available at
5
// https://www.gnu.org/licenses/agpl-3.0.en.html
6
7
package utilities
8
9
import (
10
"bytes"
11
"fmt"
12
"io/ioutil"
13
14
http "github.com/Danny-Dasilva/fhttp"
15
16
"compress/zlib"
17
18
"github.com/andybalholm/brotli"
19
)
20
21
// Decoding brotli encrypted responses
22
func DecodeBr(data []byte) ([]byte, error) {
23
r := bytes.NewReader(data)
24
br := brotli.NewReader(r)
25
26
return ioutil.ReadAll(br)
27
}
28
29
// Function to handle all sorts of accepted-encryptions
30
func ReadBody(resp http.Response) ([]byte, error) {
31
32
defer resp.Body.Close()
33
34
body, err := ioutil.ReadAll(resp.Body)
35
if err != nil {
36
return nil, err
37
}
38
39
if resp.Header.Get("Content-Encoding") == "gzip" {
40
gzipreader, err := zlib.NewReader(bytes.NewReader(body))
41
if err != nil {
42
return nil, err
43
}
44
gzipbody, err := ioutil.ReadAll(gzipreader)
45
if err != nil {
46
return nil, err
47
}
48
return gzipbody, nil
49
}
50
51
if resp.Header.Get("Content-Encoding") == "br" {
52
brreader := brotli.NewReader(bytes.NewReader(body))
53
brbody, err := ioutil.ReadAll(brreader)
54
if err != nil {
55
fmt.Println(string(brbody))
56
return nil, err
57
}
58
59
return brbody, nil
60
}
61
return body, nil
62
}
63
64