Gpg: Add pipe support for encrypt/decrypt.

This commit is contained in:
Dmitry Voronin 2025-01-12 22:27:53 +03:00
parent 8869c55ac8
commit 49aada16db
Signed by: voronind
SSH key fingerprint: SHA256:3kBb4iV2ahufEBNq+vFbUe4QYfHt98DHQjN7QaptY9k

View file

@ -5,22 +5,21 @@ function scunlock() {
echo verify | gpg --card-edit --no-tty --command-fd=0 echo verify | gpg --card-edit --no-tty --command-fd=0
} }
# Encrypt files to myself. # Encrypt files to myself from a file or stdin.
# Usage: encrypt <FILES> # Usage: encrypt [FILES]
function encrypt() { function encrypt() {
local IFS=$'\n' local IFS=$'\n'
local targets=(${@}) local targets=(${@})
if [[ ${targets} == "" ]]; then if [[ ${targets} == "" ]]; then
help encrypt gpg --encrypt --armor --recipient hi@voronind.com
return 2 else
process() {
pv "${target}" | gpg --encrypt --recipient hi@voronind.com --output "${target}.gpg"
}
_iterate_targets process ${targets[@]}
fi fi
process() {
gpg --encrypt --armor --recipient hi@voronind.com --output "${target}.gpg" "${target}"
}
_iterate_targets process ${targets[@]}
} }
# Decrypt files to myself. # Decrypt files to myself.
@ -29,13 +28,15 @@ function decrypt() {
local IFS=$'\n' local IFS=$'\n'
local targets=(${@}) local targets=(${@})
[[ ${targets} == "" ]] && targets=(*.gpg) if [[ ${targets} == "" ]]; then
gpg --decrypt
else
process() {
pv "${target}" | gpg --decrypt --output "${target%.gpg}"
}
process() { _iterate_targets process ${targets[@]}
gpg --decrypt --output "${target%.gpg}" "${target}" fi
}
_iterate_targets process ${targets[@]}
} }
# Sign a file. # Sign a file.