From: Steven Baltakatei Sandoval Date: Mon, 6 Jul 2020 17:37:11 +0000 (+0000) Subject: feat(unitproc):validateInput:Add integer type X-Git-Tag: 0.3.0~57 X-Git-Url: https://zdv2.bktei.com/gitweb/BK-2020-03.git/commitdiff_plain/a3d13a3218173de2a5b1a663f2b06d2f9e78b11f?hp=-c feat(unitproc):validateInput:Add integer type --- a3d13a3218173de2a5b1a663f2b06d2f9e78b11f diff --git a/unitproc/bktemp-validateInput b/unitproc/bktemp-validateInput index 8126747..ef125ad 100644 --- a/unitproc/bktemp-validateInput +++ b/unitproc/bktemp-validateInput @@ -7,7 +7,7 @@ try() { "$@" || die "cannot $*"; } #o validateInput() { # Desc: Validates Input # Usage: validateInput [str input] [str input type] - # Version: 0.2.1 + # Version: 0.2.2 # Input: arg1: string to validate # arg2: string specifying input type (ex:"ssh_pubkey") # Output: return code 0: if input string matched specified string type @@ -29,7 +29,7 @@ validateInput() { ### Check for alnum/dash base64 (ex: "ssh-rsa AAAAB3NzaC1yc2EAAA") if [[ "$argType" = "ssh_pubkey" ]]; then if [[ "$argInput" =~ ^[[:alnum:]-]*[\ ]*[[:alnum:]+/=]*$ ]]; then - return 0; fi; fi; + return 0; fi; fi; ## age_pubkey ### Check for age1[:bech32:] @@ -37,21 +37,45 @@ validateInput() { if [[ "$argInput" =~ ^age1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]*$ ]]; then return 0; fi; fi + ## integer + if [[ "$argType" = "integer" ]]; then + if [[ "$argInput" =~ ^[[:digit:]]*$ ]]; then + return 0; fi; fi; # Return error if no condition matched. return 1; } # Validates strings #==BEGIN sample code== -testKey1="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCq8G0XWi8A+MXNu7MEaxDsZJUwtgPC4shGAAarXC4PQTRxLfUHtyWkNbzGh31U/bKI3Snp1O78yOVEZSjdmWkDvkwtWKJQcoZBStgqw9oIPE0oG8uh49XoX77nVabi0JCf8zO63Ai4/9EdwyqE9xsJ+soOYt2V5+UCj0zsv1xpt2YhfYyXrzBv9x6k9lCxy0NW3Ik1mSW+OzSOT3tgDf36ujV/CI2i8ERM9civWy8FtFOReZMV2kkbj7fXI4E1wKM1RFIn7er1MseCSvbvh3o2uCO46/euqHAstYs5cL+4yB2qM/xKfHT5aocDjq7GBLKtree9xdNF0EE9CNr/+J5R"; -testKey2="blah-blah onetwothreeREEE"; +testKey="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCq8G0XWi8A+MXNu7MEaxDsZJUwtgPC4shGAAarXC4PQTRxLfUHtyWkNbzGh31U/bKI3Snp1O78yOVEZSjdmWkDvkwtWKJQcoZBStgqw9oIPE0oG8uh49XoX77nVabi0JCf8zO63Ai4/9EdwyqE9xsJ+soOYt2V5+UCj0zsv1xpt2YhfYyXrzBv9x6k9lCxy0NW3Ik1mSW+OzSOT3tgDf36ujV/CI2i8ERM9civWy8FtFOReZMV2kkbj7fXI4E1wKM1RFIn7er1MseCSvbvh3o2uCO46/euqHAstYs5cL+4yB2qM/xKfHT5aocDjq7GBLKtree9xdNF0EE9CNr/+J5R"; +keyType="ssh_pubkey"; +if validateInput "$testKey" "$keyType"; then echo "Looks like a valid $keyType:\"$testKey\""; else echo "doesn't look like a valid $keyType:\"$testKey\""; fi +echo ""; + +testKey="blah-blah onetwothreeREEE"; +keyType="ssh_pubkey"; +if validateInput "$testKey" "$keyType"; then echo "Looks like a valid $keyType:\"$testKey\""; else echo "doesn't look like a valid $keyType:\"$testKey\""; fi +echo ""; + testKey3=""; -testKey4="age1c3s6huz6en6jh40cem0erc0m2un2ry85my0t0ujj4a5cu8gzkysq9l39e4"; -keyTypeA="ssh_pubkey"; -keyTypeB="age_pubkey"; -if validateInput "$testKey1" "$keyTypeA"; then echo "$testKey1 looks like a valid $keyTypeA."; else echo "$testKey1 doesn't look like a valid $keyTypeA."; fi -if validateInput "$testKey2" "$keyTypeA"; then echo "$testKey2 looks like a valid $keyTypeA."; else echo "$testKey2 doesn't look like a valid $keyTypeA."; fi -if validateInput "$testKey3" "$keyTypeA"; then echo "$testKey3 looks like a valid $keyTypeA."; else echo "$testKey3 doesn't look like a valid $keyTypeA."; fi -if validateInput "$testKey4" "$keyTypeB"; then echo "$testKey4 looks like a valid $keyTypeB."; else echo "$testKey4 doesn't look like a valid $keyTypeB."; fi +keyType="ssh_pubkey"; +if validateInput "$testKey" "$keyType"; then echo "Looks like a valid $keyType:\"$testKey\""; else echo "doesn't look like a valid $keyType:\"$testKey\""; fi +echo ""; + +testKey="age1c3s6huz6en6jh40cem0erc0m2un2ry85my0t0ujj4a5cu8gzkysq9l39e4"; +keyType="age_pubkey"; +if validateInput "$testKey" "$keyType"; then echo "Looks like a valid $keyType:\"$testKey\""; else echo "doesn't look like a valid $keyType:\"$testKey\""; fi +echo ""; + +testKey="123" +keyType="integer"; +if validateInput "$testKey" "$keyType"; then echo "Looks like a valid $keyType:\"$testKey\""; else echo "doesn't look like a valid $keyType:\"$testKey\""; fi +echo ""; + +testKey="123abc" +keyType="integer"; +if validateInput "$testKey" "$keyType"; then echo "Looks like a valid $keyType:\"$testKey\""; else echo "doesn't look like a valid $keyType:\"$testKey\""; fi +echo ""; + #==END sample code== # Author: Steven Baltakatei Sandoval (bktei.com)