Skip to content

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

@kmcphillips

Description

@kmcphillips

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)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions