Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unify rubythemis token protect mode, uncomment integration tests #281

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/wrappers/themis/ruby/lib/rubythemis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,8 @@ def encrypt(message, context = nil)
raise(ThemisError,
"Secure Cell (Token Protect) failed encrypting: #{res}")
end
[enccontext.get_bytes(0, enccontext_length.read_uint),
encrypted_message.get_bytes(0, encrypted_message_length.read_uint)]
[encrypted_message.get_bytes(0, encrypted_message_length.read_uint),
enccontext.get_bytes(0, enccontext_length.read_uint),]
when CONTEXT_IMPRINT_MODE
res = themis_secure_cell_encrypt_context_imprint(
@key, @key_length, message_, message_length_, context_,
Expand Down Expand Up @@ -520,7 +520,7 @@ def decrypt(message, context = nil)
end
decrypted_message.get_bytes(0, decrypted_message_length.read_uint)
when TOKEN_PROTECT_MODE
enccontext, message_ = message
message_, enccontext = message
message__, message_length__ = string_to_pointer_size(message_)
enccontext_, enccontext_length = string_to_pointer_size(enccontext)
res = themis_secure_cell_decrypt_token_protect(
Expand Down
16 changes: 8 additions & 8 deletions tests/_integration/integration_php.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ php -f ./tests/_integration/scell_seal_string_echo.php "dec" "passwd" `ruby ./te

ruby ./tests/_integration/scell_seal_string_echo.rb "dec" "passwd" `php -f ./tests/_integration/scell_seal_string_echo.php "enc" "passwd" "php->ruby seal with context" "somecontext"` "somecontext"

#echo ".. testing secure cell, context imprint mode, php <--> ruby"
echo ".. testing secure cell, context imprint mode, php <--> ruby"
ruby ./tests/_integration/scell_context_string_echo.rb "dec" "passwd" `php -f ./tests/_integration/scell_context_string_echo.php "enc" "passwd" "php->ruby with context" "somecontext"` "somecontext"
php -f ./tests/_integration/scell_context_string_echo.php "dec" "passwd" `ruby ./tests/_integration/scell_context_string_echo.rb "enc" "passwd" "ruby->php with context" "somecontext"` "somecontext"

echo ".. testing secure cell, token protect mode, php <--> ruby - SKIPPED!"
#ruby ./tests/_integration/scell_token_string_echo.rb "dec" "passwd" `php -f ./tests/_integration/scell_token_string_echo.php "enc" "passwd" "php->ruby token test"`
#
#ruby ./tests/_integration/scell_token_string_echo.rb "dec" "passwd" `php -f ./tests/_integration/scell_token_string_echo.php "enc" "passwd" "php->ruby token test with content"` "somecontext"
#
#php -f ./tests/_integration/scell_token_string_echo.php "dec" "passwd" `ruby ./tests/_integration/scell_token_string_echo.rb "enc" "passwd" "ruby->php with context" "somecontext"` "somecontext"
#php -f ./tests/_integration/scell_token_string_echo.php "dec" "passwd" `ruby ./tests/_integration/scell_token_string_echo.rb "enc" "passwd" "ruby->php with context" "somecontext"` "somecontext"
echo ".. testing secure cell, token protect mode, php <--> ruby"
ruby ./tests/_integration/scell_token_string_echo.rb "dec" "passwd" `php -f ./tests/_integration/scell_token_string_echo.php "enc" "passwd" "php->ruby token test"`

ruby ./tests/_integration/scell_token_string_echo.rb "dec" "passwd" `php -f ./tests/_integration/scell_token_string_echo.php "enc" "passwd" "php->ruby token test with content" "somecontext"` "somecontext"

php -f ./tests/_integration/scell_token_string_echo.php "dec" "passwd" `ruby ./tests/_integration/scell_token_string_echo.rb "enc" "passwd" "ruby->php with context" "somecontext"` "somecontext"
php -f ./tests/_integration/scell_token_string_echo.php "dec" "passwd" `ruby ./tests/_integration/scell_token_string_echo.rb "enc" "passwd" "ruby->php with context" "somecontext"` "somecontext"

echo ".. testing secure cell, token protect mode, php <--> go"
go run ./tests/_integration/scell_token_string_echo.go "dec" "passwd" `php -f ./tests/_integration/scell_token_string_echo.php "enc" "passwd" "php->go token"`
Expand Down
4 changes: 3 additions & 1 deletion tests/rubythemis/scell_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,18 @@ def test_seal
def test_token_protect
token_protect = Themis::Scell.new(@key, Themis::Scell::TOKEN_PROTECT_MODE)
encrypted_message, token = token_protect.encrypt(@message, @context)
assert_equal(@message.length, encrypted_message.length)

assert_raise(Themis::ThemisError) do
decrypted_message = token_protect.decrypt(
[encrypted_message, token + '1'], @context)
[encrypted_message + '1', token], @context)
end
decrypted_message = token_protect.decrypt(
[encrypted_message, token], @context)

assert_equal(@message, decrypted_message)
encrypted_message, token = token_protect.encrypt(@message)
assert_equal(@message.length, encrypted_message.length)
decrypted_message = token_protect.decrypt([encrypted_message, token])
assert_equal(@message, decrypted_message)
end
Expand Down