nix/home/program/bash/module/Gpg.nix

77 lines
1.5 KiB
Nix
Raw Normal View History

2024-04-09 16:30:33 +03:00
{ ... }: {
text = ''
# Check smartcard pin.
function pincheck() {
2024-09-29 22:20:59 +03:00
pkill keyboxd &> /dev/null
# pkill gpg-agent &> /dev/null
echo verify | gpg --card-edit --no-tty --command-fd=0
}
2024-04-09 16:30:33 +03:00
# Encrypt files to myself.
# Usage: encrypt <FILES>
function encrypt() {
local IFS=$'\n'
local targets=(''${@})
if [[ "''${targets}" = "" ]]; then
help encrypt
return 2
fi
2024-04-09 16:30:33 +03:00
process() {
gpg --encrypt --armor --recipient hi@voronind.com --output "''${target}.gpg" "''${target}"
2024-04-09 16:30:33 +03:00
}
_iterate_targets process ''${targets[@]}
}
# Decrypt files to myself.
# Usage: decrypt [FILES]
2024-04-09 16:30:33 +03:00
function decrypt() {
local IFS=$'\n'
local targets=(''${@})
[[ "''${targets}" = "" ]] && targets=(*.gpg)
2024-04-09 16:30:33 +03:00
process() {
gpg --decrypt --output "''${target%.gpg}" "''${target}"
2024-04-09 16:30:33 +03:00
}
_iterate_targets process ''${targets[@]}
}
# Sign a file.
# Usage: sign <FILES>
function sign() {
local IFS=$'\n'
local targets=(''${@})
if [[ "''${targets}" = "" ]]; then
help sign
return 2
fi
2024-04-09 16:30:33 +03:00
process() {
gpg --detach-sig --armor --output "''${target}.sig" "''${target}"
}
_iterate_targets process ''${targets[@]}
}
# Verify a signature. All .sig files by default.
# Usage: verify [FILES]
2024-04-09 16:30:33 +03:00
function verify() {
local IFS=$'\n'
local targets=(''${@})
2024-04-09 16:30:33 +03:00
[[ "''${targets}" = "" ]] && targets=(*.sig)
process() {
gpg --verify "''${target}"
}
_iterate_targets process ''${targets[@]}
}
'';
}