horcrux/pkg/commands/utils.go
2020-06-14 13:44:11 +10:00

39 lines
676 B
Go

package commands
import (
"bufio"
"crypto/aes"
"crypto/cipher"
"fmt"
"io"
"os"
"strings"
)
func cryptoReader(r io.Reader, key []byte) io.Reader {
block, err := aes.NewCipher(key)
if err != nil {
panic(err)
}
var iv [aes.BlockSize]byte
stream := cipher.NewOFB(block, iv[:])
return cipher.StreamReader{S: stream, R: r}
}
func fileExists(filename string) bool {
info, err := os.Stat(filename)
if os.IsNotExist(err) {
return false
}
return !info.IsDir()
}
func Prompt(message string, args ...interface{}) string {
reader := bufio.NewReader(os.Stdin)
fmt.Printf(message, args...)
input, _ := reader.ReadString('\n')
return strings.TrimSpace(input)
}