refactor - pasdns can now look sane 3.0

This commit is contained in:
amy 2024-07-15 22:12:54 +03:30
parent 57fbfbf059
commit 61f89c8067
7 changed files with 3 additions and 3 deletions

29
helper/read.go Normal file
View file

@ -0,0 +1,29 @@
package helper
import (
"bufio"
"bytes"
)
func ReadUntilNull(reader *bufio.Reader) ([]byte, error) {
var buf bytes.Buffer
for {
b, err := reader.ReadByte()
if err != nil {
return nil, err
}
if b == byte(rune(0)) {
break
}
buf.WriteByte(b)
}
return buf.Bytes(), nil
}
func ReadUntilNullString(reader *bufio.Reader) (string, error) {
buf, err := ReadUntilNull(reader)
if err != nil {
return "", err
}
return string(buf), nil
}

17
helper/response.go Normal file
View file

@ -0,0 +1,17 @@
package helper
import (
"fmt"
"strings"
"git.gay/exhq/pas/Constants"
)
func IntentGenerator(res Constants.Response) string {
headersString := ""
for key, value := range res.ResponseHeader {
headersString += fmt.Sprintf("%s:%s\n", key, value)
}
headersString = strings.TrimSuffix(headersString, "\n")
return fmt.Sprintf("PAS %s\n%s\n\n%s", string(res.OperationSuccessClassification), headersString, res.Body)
}

27
helper/stringfuckery.go Normal file
View file

@ -0,0 +1,27 @@
package helper
import (
"crypto/rand"
"math/big"
)
func Ender() string {
return string(rune(0))
}
func StringToByteWithEnd(str string) []byte {
return append([]byte(str), byte(0))
}
func GetRandString(length int) string {
const charset = "qwertyuiopasdfghjklzxcvbnm"
result := make([]byte, length)
for i := range result {
num, err := rand.Int(rand.Reader, big.NewInt(int64(len(charset))))
if err != nil {
panic(err)
}
result[i] = charset[num.Int64()]
}
return string(result)
}