Browse Source

validate-path added

main
deicidus 1 year ago
parent
commit
d431d124ce
  1. 17
      spells/cantrips/validate-path
  2. 11
      spells/cantrips/validate-ssh-key

17
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

11
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."
Loading…
Cancel
Save