mirror of
https://github.com/jesseduffield/horcrux
synced 2024-05-31 14:52:14 +02:00
39 lines
676 B
Go
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)
|
|
}
|