mirror of
https://github.com/dehydrated-io/dehydrated.git
synced 2026-04-18 14:39:46 +02:00
rewritten hex2bin method
This commit is contained in:
@@ -158,27 +158,10 @@ urlbase64() {
|
|||||||
openssl base64 -e | anti_newline | sed 's/=*$//g' | tr '+/' '-_'
|
openssl base64 -e | anti_newline | sed 's/=*$//g' | tr '+/' '-_'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Convert hex string to binary data
|
||||||
hex2bin() {
|
hex2bin() {
|
||||||
# Store hex string from stdin
|
# Remove spaces, add leading zero, escape as hex string and parse with printf
|
||||||
tmphex="$(cat)"
|
printf -- "$(cat | sed -E -e 's/[[:space:]]//g' -e 's/^(.(.{2})*)$/0\1/' -e 's/(.{2})/\\x\1/g')"
|
||||||
|
|
||||||
# Remove spaces
|
|
||||||
hex=''
|
|
||||||
for ((i=0; i<${#tmphex}; i+=1)); do
|
|
||||||
test "${tmphex:$i:1}" == " " || hex="${hex}${tmphex:$i:1}"
|
|
||||||
done
|
|
||||||
|
|
||||||
# Add leading zero
|
|
||||||
test $((${#hex} & 1)) == 0 || hex="0${hex}"
|
|
||||||
|
|
||||||
# Convert to escaped string
|
|
||||||
escapedhex=''
|
|
||||||
for ((i=0; i<${#hex}; i+=2)); do
|
|
||||||
escapedhex=$escapedhex\\x${hex:$i:2}
|
|
||||||
done
|
|
||||||
|
|
||||||
# Convert to binary data
|
|
||||||
printf -- "${escapedhex}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get_json_string_value() {
|
get_json_string_value() {
|
||||||
|
|||||||
Reference in New Issue
Block a user