diff --git a/secrets b/secrets index 123c556..7009da4 100755 --- a/secrets +++ b/secrets @@ -117,6 +117,15 @@ _validate_age_recipient() { return 0 } +# Recipient display names become "# " comment lines in recipients.txt. +# Restrict to a safe charset so a name can't inject extra lines/metacharacters. +_validate_recipient_name() { + case "$1" in + *[!A-Za-z0-9\ ._-]*) return 1 ;; + *) return 0 ;; + esac +} + # Populate the global RECIPIENT_ARGS array with one "-r " per store # recipient. recipients.txt present -> validated keys from the file (the store # is multi-recipient). Absent -> the single pubkey derived from key.txt (legacy @@ -2067,7 +2076,8 @@ cmd_recipients() { [ $# -gt 0 ] && shift case "$sub" in list) _recipients_list ;; - *) die "Unknown recipients subcommand: '$sub'. Usage: secrets recipients [list]" ;; + add) _recipients_add "$@" ;; + *) die "Unknown recipients subcommand: '$sub'. Usage: secrets recipients [list|add [--name N]]" ;; esac } @@ -2088,6 +2098,42 @@ _recipients_list() { done < <(_recipients_dump) } +_recipients_add() { + check_cmd age + check_cmd git + check_initialized + check_key + local key="" name="" + while [ $# -gt 0 ]; do + case "$1" in + --name) name="${2:-}"; shift 2 ;; + -*) die "Unknown flag: $1. Usage: secrets recipients add [--name