diff --git a/spells/cantrips/validate-path b/spells/cantrips/validate-path new file mode 100755 index 0000000..330929a --- /dev/null +++ b/spells/cantrips/validate-path @@ -0,0 +1,17 @@ +#!/bin/sh + +# POSIX compliant regular expressions +# Matches any string that contains a null byte or begins or ends with a / +REGEX1='(^/|/$|\\0)' +# Matches any string longer than 255 characters (for a single filename) +REGEX2='^.{256,}$' +# Matches any string longer than 4096 characters (for a full path) +REGEX3='^.{4097,}$' + +if echo "$1" | grep -Eq "$REGEX1" || echo "$1" | grep -Eq "$REGEX2" || echo "$1" | grep -Eq "$REGEX3"; then + # If any regex matches, this is an invalid path + exit 1 +else + # Otherwise, it's valid + exit 0 +fi \ No newline at end of file diff --git a/spells/cantrips/validate-ssh-key b/spells/cantrips/validate-ssh-key new file mode 100644 index 0000000..5159f7f --- /dev/null +++ b/spells/cantrips/validate-ssh-key @@ -0,0 +1,11 @@ +!/bin/sh + +read -p "Enter the SSH key: " ssh_key + +# Check if the SSH key is in the correct format +if ! echo "$ssh_key" | grep -E '^ssh-([a-zA-Z0-9]+) ([A-Za-z0-9+/]+=*) ([A-Za-z0-9]+@[A-Za-z0-9]+)?$' > /dev/null; then + echo "Invalid SSH key format." + exit 1 +fi + +echo "Valid SSH key."