declare -gxir __ipc_version=1
+ interface "encode" \
+ "decode"
return 0
}
-_ipc_encode() {
+ipc_encode() {
local decoded="$1"
if (( $# > 0 )); then
fi
}
-_ipc_decode() {
+ipc_decode() {
local encoded="$1"
if (( $# > 0 )); then
local signature
if ! signature=$(gpg --output - --detach-sig <(echo "$data") |
- _ipc_encode); then
+ ipc_encode); then
return 1
fi
err=0
- if ! result=$(gpg --verify <(_ipc_decode <<< "$signature") <(echo "$data") 2>&1); then
+ if ! result=$(gpg --verify <(ipc_decode <<< "$signature") <(echo "$data") 2>&1); then
err=1
fi
local value
- if ! value=$(_ipc_decode "$msg" | jq -e -r ".$field" 2>/dev/null); then
+ if ! value=$(ipc_decode "$msg" | jq -e -r ".$field" 2>/dev/null); then
return 1
fi
Signer : $signer_name <$signer_email>
Key fingerprint: $signer_key
-$(_ipc_decode <<< "$msg" | jq .)
+$(ipc_decode <<< "$msg" | jq .)
EOF
return 0
local envelope
local encoded_envelope
- if ! encoded_data=$(_ipc_encode <<< "$data"); then
+ if ! encoded_data=$(ipc_encode <<< "$data"); then
log_error "Could not encode data"
elif ! timestamp=$(date +"%s"); then
"data" "$encoded_data"); then
log_error "Could not make message"
- elif ! encoded_message=$(_ipc_encode "$message"); then
+ elif ! encoded_message=$(ipc_encode "$message"); then
log_error "Could not encode message"
elif ! signature=$(_ipc_sign "$encoded_message"); then
"signature" "$signature"); then
log_error "Could not make envelope"
- elif ! encoded_envelope=$(_ipc_encode "$envelope"); then
+ elif ! encoded_envelope=$(ipc_encode "$envelope"); then
log_error "Could not encode envelope"
else
return 1
fi
- if ! data_raw=$(_ipc_decode <<< "$data"); then
+ if ! data_raw=$(ipc_decode <<< "$data"); then
return 1
fi
}
Describe "Encoding"
- It "_ipc_encode() outputs base64"
+ It "ipc_encode() outputs base64"
_test_encoding() {
local data
data=$(dd if=/dev/urandom bs=1024 count=1024 2>/dev/null |
- _ipc_encode)
+ ipc_encode)
if ! [[ "$data" =~ ^[a-zA-Z0-9+/]+[=]*$ ]]; then
return 1
The status should equal 0
End
- It "_ipc_encode() output has correct length"
+ It "ipc_encode() output has correct length"
_test_encoding_length() {
local data
local block_size
input_bits=$((input_bytes * 8))
actual_length=$(dd if=/dev/urandom bs="$block_size" count="$block_num" 2>/dev/null |
- _ipc_encode | wc -c)
+ ipc_encode | wc -c)
if (( input_bits % 24 > 0 )); then
# data is padded
The status should equal 0
End
- It "_ipc_encode() output does not contain newlines"
+ It "ipc_encode() output does not contain newlines"
_test_encoding_newlines() {
local lines
lines=$(dd if=/dev/urandom bs=1024 count=1024 2>/dev/null |
- _ipc_encode | wc -l)
+ ipc_encode | wc -l)
if (( lines != 0 )); then
return 1
End
- It "_ipc_decode() reverses _ipc_encode()"
+ It "ipc_decode() reverses ipc_encode()"
_test_encode_decode() {
local data_before
local data_encoded
local data_after
data_before=$(dd if=/dev/urandom bs=1024 count=1024 2>/dev/null | base64 -w 0)
- data_encoded=$(_ipc_encode <<< "$data_before")
- data_after=$(_ipc_decode <<< "$data_encoded")
+ data_encoded=$(ipc_encode <<< "$data_before")
+ data_after=$(ipc_decode <<< "$data_encoded")
if [[ "$data_before" != "$data_after" ]]; then
return 1
_test_ipc_sign_length() {
local data
- data=$(dd if=/dev/urandom bs=1024 count=1024 2>/dev/null | _ipc_encode)
+ data=$(dd if=/dev/urandom bs=1024 count=1024 2>/dev/null | ipc_encode)
if ! signature=$(_ipc_sign <<< "$data"); then
return 1
local data
local signature
- data=$(dd if=/dev/urandom bs=1024 count=1024 2>/dev/null | _ipc_encode)
+ data=$(dd if=/dev/urandom bs=1024 count=1024 2>/dev/null | ipc_encode)
if ! signature=$(_ipc_sign "$data"); then
return 1
local data
local signature
- data=$(dd if=/dev/urandom bs=1024 count=1024 2>/dev/null | _ipc_encode)
+ data=$(dd if=/dev/urandom bs=1024 count=1024 2>/dev/null | ipc_encode)
if ! signature=$(_ipc_sign "$data"); then
return 1
return 1
fi
- if ! _ipc_decode <<< "$msg" | jq -r -e . ; then
+ if ! ipc_decode <<< "$msg" | jq -r -e . ; then
return 1
fi
return 1
fi
- if ! spec/validate.py spec/ipc_envelope.schema.json <(_ipc_decode "$msg"); then
+ if ! spec/validate.py spec/ipc_envelope.schema.json <(ipc_decode "$msg"); then
return 1
fi
fi
if ! spec/validate.py spec/ipc_message.schema.json \
- <(_ipc_get "$msg" "message" | _ipc_decode); then
+ <(_ipc_get "$msg" "message" | ipc_decode); then
return 1
fi