2022-04-09 03:00:38 +00:00
|
|
|
// 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 (
|
2022-04-18 08:16:00 +00:00
|
|
|
"bytes"
|
2022-04-09 03:00:38 +00:00
|
|
|
"crypto/rand"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
2022-04-18 08:16:00 +00:00
|
|
|
"os"
|
2022-04-09 03:00:38 +00:00
|
|
|
)
|
|
|
|
|
2022-04-18 08:16:00 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2022-04-29 09:36:41 +00:00
|
|
|
func getRpad(messageLength int) string {
|
|
|
|
length := 100 - messageLength%100
|
2022-05-02 13:07:58 +00:00
|
|
|
rpad := make([]byte, length)
|
|
|
|
_, err := rand.Read(rpad)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
2022-04-17 15:16:29 +00:00
|
|
|
}
|
2022-05-02 13:07:58 +00:00
|
|
|
return fmt.Sprintf("%x", rpad)
|
2022-04-17 15:16:29 +00:00
|
|
|
}
|
|
|
|
|
2022-04-09 03:00:38 +00:00
|
|
|
func getID() string {
|
2022-05-02 14:13:00 +00:00
|
|
|
id := make([]byte, 12)
|
|
|
|
_, err := rand.Read(id)
|
2022-04-09 03:00:38 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2022-05-02 14:13:00 +00:00
|
|
|
return fmt.Sprintf("%x-%x-%x", id[0:4], id[4:8], id[8:])
|
2022-04-09 03:00:38 +00:00
|
|
|
}
|
2022-04-23 21:40:15 +00:00
|
|
|
|
|
|
|
func getShortID() string {
|
2022-05-02 14:13:00 +00:00
|
|
|
id := make([]byte, 4)
|
|
|
|
_, err := rand.Read(id)
|
2022-04-23 21:40:15 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2022-05-02 14:13:00 +00:00
|
|
|
return fmt.Sprintf("%x", id[0:4])
|
2022-04-23 21:40:15 +00:00
|
|
|
}
|