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

Only subset of YAML supported and raises on encrypt no implicit conversion of Hash into Integer (TypeError) #122

Open
kmcphillips opened this issue Nov 3, 2022 · 2 comments
Assignees
Milestone

Comments

@kmcphillips
Copy link

Problem

When calling encrypt with some YAML it raises. This means only a subset of YAML is supported, but the file I am trying to encrypt has a structure like this:

list:
  -
    item: 1
    details: detail1
  -
    item: 2
    details: detail2

The exception raised is:

/ruby/3.0.2/lib/ruby/gems/3.0.0/gems/diffcrypt-0.6.1/lib/diffcrypt/encryptor.rb:84:in `[]=': no implicit conversion of Hash into Integer (TypeError)
	from /ruby/3.0.2/lib/ruby/gems/3.0.0/gems/diffcrypt-0.6.1/lib/diffcrypt/encryptor.rb:84:in `block in encrypt_values'
	from /ruby/3.0.2/lib/ruby/gems/3.0.0/gems/diffcrypt-0.6.1/lib/diffcrypt/encryptor.rb:80:in `each'
	from /ruby/3.0.2/lib/ruby/gems/3.0.0/gems/diffcrypt-0.6.1/lib/diffcrypt/encryptor.rb:80:in `encrypt_values'
	from /ruby/3.0.2/lib/ruby/gems/3.0.0/gems/diffcrypt-0.6.1/lib/diffcrypt/encryptor.rb:85:in `block in encrypt_values'
	from /ruby/3.0.2/lib/ruby/gems/3.0.0/gems/diffcrypt-0.6.1/lib/diffcrypt/encryptor.rb:80:in `each'
	from /ruby/3.0.2/lib/ruby/gems/3.0.0/gems/diffcrypt-0.6.1/lib/diffcrypt/encryptor.rb:80:in `encrypt_values'
	from /ruby/3.0.2/lib/ruby/gems/3.0.0/gems/diffcrypt-0.6.1/lib/diffcrypt/encryptor.rb:65:in `encrypt_data'
	from /ruby/3.0.2/lib/ruby/gems/3.0.0/gems/diffcrypt-0.6.1/lib/diffcrypt/encryptor.rb:51:in `encrypt'

With this debug call stack information:

encrypt_values(data={"list"=>[{"item"=>1, "details"=>"detail1"}, {"item"=>2, "details"=>"detail2"}]}, original_data=)
  data[list] = [{"item"=>1, "details"=>"detail1"}, {"item"=>2, "details"=>"detail2"}] (Array)
encrypt_values(data=[{"item"=>1, "details"=>"detail1"}, {"item"=>2, "details"=>"detail2"}], original_data=)
  data[{"item"=>1, "details"=>"detail1"}] = nil (NilClass)

Reproduction

require "diffcrypt"
key = "a5c51953b9c43c3f0e1dff3d5761c7d0000aefd85903d428e01bdb6d5916dc01"
text = "list:\n  -\n    item: 1\n    details: detail1\n  -\n    item: 2\n    details: detail2\n"
encryptor = Diffcrypt::Encryptor.new(key)
encryptor.encrypt(text)
@swiknaba
Copy link
Contributor

swiknaba commented Feb 10, 2023

I'm getting encryptor.rb:81:in `[]=': no implicit conversion of String into Integer (TypeError); potentially a similar root cause.

The yml file contains some unorthodox keys such as:

foo:
  - "123123"
  - "4345354"

Likely this is rather an abuse of Rails credentials, would still be nice if I could add diffcrypt though :)

Full stack trace:

34: from bin/rails:4:in `<main>'
33: from 2.7.7/gems/activesupport-6.0.6.1/lib/active_support/dependencies.rb:324:in `require'
32: from 2.7.7/gems/activesupport-6.0.6.1/lib/active_support/dependencies.rb:291:in `load_dependency'
31: from 2.7.7/gems/activesupport-6.0.6.1/lib/active_support/dependencies.rb:324:in `block in require'
30: from 2.7.7/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
29: from 2.7.7/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
28: from 2.7.7/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
27: from 2.7.7/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
26: from 2.7.7/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
25: from 2.7.7/gems/railties-6.0.6.1/lib/rails/commands.rb:18:in `<main>'
24: from 2.7.7/gems/railties-6.0.6.1/lib/rails/command.rb:46:in `invoke'
23: from 2.7.7/gems/railties-6.0.6.1/lib/rails/command/base.rb:69:in `perform'
22: from 2.7.7/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
21: from 2.7.7/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
20: from 2.7.7/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
19: from 2.7.7/gems/railties-6.0.6.1/lib/rails/commands/credentials/credentials_command.rb:32:in `edit'
18: from 2.7.7/gems/railties-6.0.6.1/lib/rails/command/helpers/editor.rb:26:in `catch_editing_exceptions'
17: from 2.7.7/gems/railties-6.0.6.1/lib/rails/commands/credentials/credentials_command.rb:33:in `block in edit'
16: from 2.7.7/gems/railties-6.0.6.1/lib/rails/commands/credentials/credentials_command.rb:67:in `change_credentials_in_system_editor'
15: from 2.7.7/gems/diffcrypt-0.6.1/lib/diffcrypt/rails/encrypted_configuration.rb:72:in `change'
14: from 2.7.7/gems/diffcrypt-0.6.1/lib/diffcrypt/rails/encrypted_configuration.rb:87:in `writing'
13: from 2.7.7/gems/diffcrypt-0.6.1/lib/diffcrypt/rails/encrypted_configuration.rb:57:in `write'
12: from 2.7.7/gems/diffcrypt-0.6.1/lib/diffcrypt/rails/encrypted_configuration.rb:104:in `encrypt'
11: from 2.7.7/gems/diffcrypt-0.6.1/lib/diffcrypt/encryptor.rb:51:in `encrypt'
10: from 2.7.7/gems/diffcrypt-0.6.1/lib/diffcrypt/encryptor.rb:65:in `encrypt_data'
9: from 2.7.7/gems/diffcrypt-0.6.1/lib/diffcrypt/encryptor.rb:79:in `encrypt_values'
8: from 2.7.7/gems/diffcrypt-0.6.1/lib/diffcrypt/encryptor.rb:79:in `each'
7: from 2.7.7/gems/diffcrypt-0.6.1/lib/diffcrypt/encryptor.rb:82:in `block in encrypt_values'
6: from 2.7.7/gems/diffcrypt-0.6.1/lib/diffcrypt/encryptor.rb:79:in `encrypt_values'
5: from 2.7.7/gems/diffcrypt-0.6.1/lib/diffcrypt/encryptor.rb:79:in `each'
4: from 2.7.7/gems/diffcrypt-0.6.1/lib/diffcrypt/encryptor.rb:82:in `block in encrypt_values'
3: from 2.7.7/gems/diffcrypt-0.6.1/lib/diffcrypt/encryptor.rb:79:in `encrypt_values'
2: from 2.7.7/gems/diffcrypt-0.6.1/lib/diffcrypt/encryptor.rb:79:in `each'
1: from 2.7.7/gems/diffcrypt-0.6.1/lib/diffcrypt/encryptor.rb:81:in `block in encrypt_values'
2.7.7/gems/diffcrypt-0.6.1/lib/diffcrypt/encryptor.rb:81:in `[]=': no implicit conversion of String into Integer (TypeError)

@marcqualie
Copy link
Collaborator

Will investigate @kmcphillips + @swiknaba. Better error handling for unsupported YAML should help here and ideally figure out why these specific scenarios don't work, both look as if they should.

@marcqualie marcqualie self-assigned this Feb 28, 2023
@marcqualie marcqualie added this to the v1.0 milestone Feb 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants