mirror of
https://salsa.debian.org/mdosch/go-sendxmpp
synced 2024-11-18 21:25:31 +00:00
1214e7920f
This reverts commit 83c92bd4cc
.
56 lines
995 B
Go
56 lines
995 B
Go
// Copyright 2022 Martin Dosch.
|
|
// Use of this source code is governed by the BSD-2-clause
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"crypto/rand"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
)
|
|
|
|
func readFile(path string) (*bytes.Buffer, error) {
|
|
file, err := os.Open(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer file.Close()
|
|
buffer := new(bytes.Buffer)
|
|
_, err = buffer.ReadFrom(file)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return buffer, nil
|
|
}
|
|
|
|
func getRpad(messageLength int) string {
|
|
length := 100 - messageLength%100
|
|
rpad := make([]byte, length)
|
|
_, err := rand.Read(rpad)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
return fmt.Sprintf("%x", rpad)
|
|
}
|
|
|
|
func getID() string {
|
|
id := make([]byte, 12)
|
|
_, err := rand.Read(id)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
return fmt.Sprintf("%x-%x-%x", id[0:4], id[4:8], id[8:])
|
|
}
|
|
|
|
func getShortID() string {
|
|
id := make([]byte, 4)
|
|
_, err := rand.Read(id)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
return fmt.Sprintf("%x", id[0:4])
|
|
}
|