#!/bin/sh

# POSIX shell client for PurritoBin to decrypt the message

: "${P_SERVER=https://bsd.ac}"
: "${P_PORT=42069}"
: "${P_MAXTIME=30}"

url="$1"
baseurl="${url%\/*}"
vals="${url##*\#}"
paste=$(printf %s\\n "${vals}" | cut -d'_' -f1)
key=$(printf %s\\n "${vals}" | cut -d'_' -f2)
iv=$(printf %s\\n "${vals}" | cut -d'_' -f3)
curl --max-time "${P_MAXTIME}" --write-out "\n" --silent "${baseurl}/${paste}" | openssl enc -aes-256-cbc -base64 -d -K ${key} -iv ${iv}
unset url baseurl vals paste key iv
