From 6149f3cfd2ce0e68352735aa0a3d6d441019d28d Mon Sep 17 00:00:00 2001 From: moznion Date: Thu, 6 Nov 2025 21:14:01 +0900 Subject: [PATCH] Add frozen string literal support for Ruby 3.4 compatibility - Add frozen_string_literal: true to all Ruby files - Fix string mutations to work with frozen strings This change improves memory efficiency and performance by making all string literals frozen by default, which is becoming the standard in modern Ruby versions. Signed-off-by: moznion --- lib/symmetric-encryption.rb | 2 ++ lib/symmetric_encryption.rb | 2 ++ .../active_record/attr_encrypted.rb | 2 ++ .../active_record/encrypted_attribute.rb | 2 ++ lib/symmetric_encryption/cipher.rb | 2 ++ lib/symmetric_encryption/cli.rb | 2 ++ lib/symmetric_encryption/coerce.rb | 2 ++ lib/symmetric_encryption/config.rb | 2 ++ lib/symmetric_encryption/core.rb | 2 ++ lib/symmetric_encryption/encoder.rb | 2 ++ lib/symmetric_encryption/exception.rb | 2 ++ lib/symmetric_encryption/generator.rb | 2 ++ lib/symmetric_encryption/header.rb | 4 +++- lib/symmetric_encryption/key.rb | 2 ++ lib/symmetric_encryption/keystore.rb | 2 ++ lib/symmetric_encryption/keystore/aws.rb | 2 ++ lib/symmetric_encryption/keystore/environment.rb | 2 ++ lib/symmetric_encryption/keystore/file.rb | 2 ++ lib/symmetric_encryption/keystore/gcp.rb | 2 ++ lib/symmetric_encryption/keystore/heroku.rb | 2 ++ lib/symmetric_encryption/keystore/memory.rb | 2 ++ lib/symmetric_encryption/railtie.rb | 2 ++ lib/symmetric_encryption/railties/mongoid_encrypted.rb | 2 ++ .../railties/symmetric_encryption_validator.rb | 2 ++ lib/symmetric_encryption/reader.rb | 4 +++- lib/symmetric_encryption/rsa_key.rb | 2 ++ lib/symmetric_encryption/symmetric_encryption.rb | 2 ++ lib/symmetric_encryption/utils/aws.rb | 2 ++ lib/symmetric_encryption/utils/files.rb | 2 ++ lib/symmetric_encryption/utils/re_encrypt_files.rb | 2 ++ lib/symmetric_encryption/version.rb | 2 ++ lib/symmetric_encryption/writer.rb | 2 ++ test/active_record/encrypted_attribute_test.rb | 2 ++ test/active_record_test.rb | 2 ++ test/cipher_test.rb | 10 ++++++---- test/encoder_test.rb | 4 +++- test/header_test.rb | 8 +++++--- test/key_test.rb | 6 ++++-- test/keystore/aws_test.rb | 2 ++ test/keystore/environment_test.rb | 2 ++ test/keystore/file_test.rb | 2 ++ test/keystore/gcp_test.rb | 2 ++ test/keystore/heroku_test.rb | 2 ++ test/keystore_test.rb | 2 ++ test/mongoid_test.rb | 2 ++ test/reader_test.rb | 6 ++++-- test/symmetric_encryption_test.rb | 6 ++++-- test/test_helper.rb | 2 ++ test/utils/aws_test.rb | 2 ++ test/writer_test.rb | 4 +++- 50 files changed, 117 insertions(+), 17 deletions(-) diff --git a/lib/symmetric-encryption.rb b/lib/symmetric-encryption.rb index f592fd2..7689041 100644 --- a/lib/symmetric-encryption.rb +++ b/lib/symmetric-encryption.rb @@ -1 +1,3 @@ +# frozen_string_literal: true + require "symmetric_encryption" diff --git a/lib/symmetric_encryption.rb b/lib/symmetric_encryption.rb index 8024e61..6c7ad8a 100644 --- a/lib/symmetric_encryption.rb +++ b/lib/symmetric_encryption.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "symmetric_encryption/core" # Add extensions. Gems are no longer order dependent. diff --git a/lib/symmetric_encryption/active_record/attr_encrypted.rb b/lib/symmetric_encryption/active_record/attr_encrypted.rb index 6a1d97e..75637fe 100644 --- a/lib/symmetric_encryption/active_record/attr_encrypted.rb +++ b/lib/symmetric_encryption/active_record/attr_encrypted.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SymmetricEncryption module ActiveRecord module AttrEncrypted diff --git a/lib/symmetric_encryption/active_record/encrypted_attribute.rb b/lib/symmetric_encryption/active_record/encrypted_attribute.rb index 73a382c..94ecb3a 100644 --- a/lib/symmetric_encryption/active_record/encrypted_attribute.rb +++ b/lib/symmetric_encryption/active_record/encrypted_attribute.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SymmetricEncryption module ActiveRecord class EncryptedAttribute < ::ActiveModel::Type::String diff --git a/lib/symmetric_encryption/cipher.rb b/lib/symmetric_encryption/cipher.rb index a7d4887..85b1cef 100644 --- a/lib/symmetric_encryption/cipher.rb +++ b/lib/symmetric_encryption/cipher.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "openssl" module SymmetricEncryption # Hold all information related to encryption keys diff --git a/lib/symmetric_encryption/cli.rb b/lib/symmetric_encryption/cli.rb index 7ad465c..faad52e 100644 --- a/lib/symmetric_encryption/cli.rb +++ b/lib/symmetric_encryption/cli.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "optparse" require "fileutils" module SymmetricEncryption diff --git a/lib/symmetric_encryption/coerce.rb b/lib/symmetric_encryption/coerce.rb index a4fccd6..af16fa9 100644 --- a/lib/symmetric_encryption/coerce.rb +++ b/lib/symmetric_encryption/coerce.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SymmetricEncryption # For coercing data types to from strings module Coerce diff --git a/lib/symmetric_encryption/config.rb b/lib/symmetric_encryption/config.rb index bedd1d7..7d08dc8 100644 --- a/lib/symmetric_encryption/config.rb +++ b/lib/symmetric_encryption/config.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "erb" require "yaml" module SymmetricEncryption diff --git a/lib/symmetric_encryption/core.rb b/lib/symmetric_encryption/core.rb index d630d76..7e11a1c 100644 --- a/lib/symmetric_encryption/core.rb +++ b/lib/symmetric_encryption/core.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Used for compression require "zlib" # Used to coerce data types between string and their actual types diff --git a/lib/symmetric_encryption/encoder.rb b/lib/symmetric_encryption/encoder.rb index de0c931..168d1f2 100644 --- a/lib/symmetric_encryption/encoder.rb +++ b/lib/symmetric_encryption/encoder.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SymmetricEncryption module Encoder def self.[](encoding) diff --git a/lib/symmetric_encryption/exception.rb b/lib/symmetric_encryption/exception.rb index b5b7af7..3ac767b 100644 --- a/lib/symmetric_encryption/exception.rb +++ b/lib/symmetric_encryption/exception.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SymmetricEncryption # Exceptions created by SymmetricEncryption class Error < StandardError diff --git a/lib/symmetric_encryption/generator.rb b/lib/symmetric_encryption/generator.rb index 51fbc7c..dd3ef56 100644 --- a/lib/symmetric_encryption/generator.rb +++ b/lib/symmetric_encryption/generator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SymmetricEncryption module Generator # Common internal method for generating accessors for decrypted accessors diff --git a/lib/symmetric_encryption/header.rb b/lib/symmetric_encryption/header.rb index af166b2..07e8b2f 100644 --- a/lib/symmetric_encryption/header.rb +++ b/lib/symmetric_encryption/header.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SymmetricEncryption # Defines the Header Structure returned when parsing the header. # @@ -8,7 +10,7 @@ module SymmetricEncryption class Header # Encrypted data includes this header prior to encoding when # `always_add_header` is true. - MAGIC_HEADER = "@EnC".force_encoding(SymmetricEncryption::BINARY_ENCODING) + MAGIC_HEADER = (+"@EnC").force_encoding(SymmetricEncryption::BINARY_ENCODING) MAGIC_HEADER_SIZE = MAGIC_HEADER.size # [true|false] Whether to compress the data before encryption. diff --git a/lib/symmetric_encryption/key.rb b/lib/symmetric_encryption/key.rb index 999569e..36b155d 100644 --- a/lib/symmetric_encryption/key.rb +++ b/lib/symmetric_encryption/key.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # The key, iv and encrypted data are handled in their raw form, with no encoding. module SymmetricEncryption class Key diff --git a/lib/symmetric_encryption/keystore.rb b/lib/symmetric_encryption/keystore.rb index 07aefd4..57c8017 100644 --- a/lib/symmetric_encryption/keystore.rb +++ b/lib/symmetric_encryption/keystore.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SymmetricEncryption # Encryption keys are secured in Keystores module Keystore diff --git a/lib/symmetric_encryption/keystore/aws.rb b/lib/symmetric_encryption/keystore/aws.rb index 2cf5091..facfbde 100644 --- a/lib/symmetric_encryption/keystore/aws.rb +++ b/lib/symmetric_encryption/keystore/aws.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "aws-sdk-kms" module SymmetricEncryption module Keystore diff --git a/lib/symmetric_encryption/keystore/environment.rb b/lib/symmetric_encryption/keystore/environment.rb index a91d441..921f301 100644 --- a/lib/symmetric_encryption/keystore/environment.rb +++ b/lib/symmetric_encryption/keystore/environment.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SymmetricEncryption module Keystore # Store the encrypted encryption key in an environment variable diff --git a/lib/symmetric_encryption/keystore/file.rb b/lib/symmetric_encryption/keystore/file.rb index fed652e..a4f294e 100644 --- a/lib/symmetric_encryption/keystore/file.rb +++ b/lib/symmetric_encryption/keystore/file.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SymmetricEncryption module Keystore class File diff --git a/lib/symmetric_encryption/keystore/gcp.rb b/lib/symmetric_encryption/keystore/gcp.rb index 1921bc7..89a55f3 100644 --- a/lib/symmetric_encryption/keystore/gcp.rb +++ b/lib/symmetric_encryption/keystore/gcp.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "google/cloud/kms/v1" module SymmetricEncryption diff --git a/lib/symmetric_encryption/keystore/heroku.rb b/lib/symmetric_encryption/keystore/heroku.rb index 9e2bfd0..931fa8a 100644 --- a/lib/symmetric_encryption/keystore/heroku.rb +++ b/lib/symmetric_encryption/keystore/heroku.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SymmetricEncryption module Keystore # Heroku uses environment variables too. diff --git a/lib/symmetric_encryption/keystore/memory.rb b/lib/symmetric_encryption/keystore/memory.rb index 8516304..77c406f 100644 --- a/lib/symmetric_encryption/keystore/memory.rb +++ b/lib/symmetric_encryption/keystore/memory.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SymmetricEncryption module Keystore # In Memory Keystore usually used for testing purposes diff --git a/lib/symmetric_encryption/railtie.rb b/lib/symmetric_encryption/railtie.rb index 08acbf2..8082cbf 100644 --- a/lib/symmetric_encryption/railtie.rb +++ b/lib/symmetric_encryption/railtie.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SymmetricEncryption # :nodoc: class Railtie < Rails::Railtie # :nodoc: # Exposes Symmetric Encryption's configuration to the Rails application configuration. diff --git a/lib/symmetric_encryption/railties/mongoid_encrypted.rb b/lib/symmetric_encryption/railties/mongoid_encrypted.rb index 727f9d2..74b1b7a 100644 --- a/lib/symmetric_encryption/railties/mongoid_encrypted.rb +++ b/lib/symmetric_encryption/railties/mongoid_encrypted.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "mongoid" # Add :encrypted option for Mongoid models # diff --git a/lib/symmetric_encryption/railties/symmetric_encryption_validator.rb b/lib/symmetric_encryption/railties/symmetric_encryption_validator.rb index 0276783..ec1cd15 100644 --- a/lib/symmetric_encryption/railties/symmetric_encryption_validator.rb +++ b/lib/symmetric_encryption/railties/symmetric_encryption_validator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Add an ActiveModel Validator # # Example: diff --git a/lib/symmetric_encryption/reader.rb b/lib/symmetric_encryption/reader.rb index bb787e2..b89e327 100644 --- a/lib/symmetric_encryption/reader.rb +++ b/lib/symmetric_encryption/reader.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "openssl" module SymmetricEncryption @@ -185,7 +187,7 @@ def size # At end of file, it returns nil if no more data is available, or the last # remaining bytes def read(length = nil, outbuf = nil) - data = outbuf.nil? ? "" : outbuf.clear + data = outbuf.nil? ? +"" : outbuf.clear remaining_length = length until remaining_length&.zero? || eof? diff --git a/lib/symmetric_encryption/rsa_key.rb b/lib/symmetric_encryption/rsa_key.rb index 3b3ed62..649874f 100644 --- a/lib/symmetric_encryption/rsa_key.rb +++ b/lib/symmetric_encryption/rsa_key.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "openssl" module SymmetricEncryption # DEPRECATED - Internal use only diff --git a/lib/symmetric_encryption/symmetric_encryption.rb b/lib/symmetric_encryption/symmetric_encryption.rb index d8f18f7..db123ef 100644 --- a/lib/symmetric_encryption/symmetric_encryption.rb +++ b/lib/symmetric_encryption/symmetric_encryption.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "base64" require "openssl" require "zlib" diff --git a/lib/symmetric_encryption/utils/aws.rb b/lib/symmetric_encryption/utils/aws.rb index 071501b..045ce9b 100644 --- a/lib/symmetric_encryption/utils/aws.rb +++ b/lib/symmetric_encryption/utils/aws.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "base64" require "aws-sdk-kms" module SymmetricEncryption diff --git a/lib/symmetric_encryption/utils/files.rb b/lib/symmetric_encryption/utils/files.rb index 452e1df..0c8a969 100644 --- a/lib/symmetric_encryption/utils/files.rb +++ b/lib/symmetric_encryption/utils/files.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SymmetricEncryption module Utils module Files diff --git a/lib/symmetric_encryption/utils/re_encrypt_files.rb b/lib/symmetric_encryption/utils/re_encrypt_files.rb index f3d8bc8..15fed89 100644 --- a/lib/symmetric_encryption/utils/re_encrypt_files.rb +++ b/lib/symmetric_encryption/utils/re_encrypt_files.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Used for re-encrypting encrypted passwords stored in configuration files. # # Search for any encrypted value and re-encrypt it using the latest encryption key. diff --git a/lib/symmetric_encryption/version.rb b/lib/symmetric_encryption/version.rb index a4645c7..6e2e998 100644 --- a/lib/symmetric_encryption/version.rb +++ b/lib/symmetric_encryption/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SymmetricEncryption VERSION = "4.6.0".freeze end diff --git a/lib/symmetric_encryption/writer.rb b/lib/symmetric_encryption/writer.rb index 55d8700..ced29bb 100644 --- a/lib/symmetric_encryption/writer.rb +++ b/lib/symmetric_encryption/writer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "openssl" module SymmetricEncryption diff --git a/test/active_record/encrypted_attribute_test.rb b/test/active_record/encrypted_attribute_test.rb index a6cc8d1..687c411 100644 --- a/test/active_record/encrypted_attribute_test.rb +++ b/test/active_record/encrypted_attribute_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative "../test_helper" ActiveRecord::Base.configurations = YAML.safe_load(ERB.new(File.read("test/config/database.yml")).result) diff --git a/test/active_record_test.rb b/test/active_record_test.rb index 4952c78..0046768 100644 --- a/test/active_record_test.rb +++ b/test/active_record_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative "test_helper" if ActiveRecord.version <= Gem::Version.new("7.0.0") diff --git a/test/cipher_test.rb b/test/cipher_test.rb index cd8a909..30aa570 100644 --- a/test/cipher_test.rb +++ b/test/cipher_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative "test_helper" # Tests for SymmetricEncryption::Cipher @@ -63,13 +65,13 @@ class CipherTest < Minitest::Test no_header: "c9378b8ec1d36bcca4a0ef792b42909a" }, none: { - header: "@EnC\x00\x00\xC97\x8B\x8E\xC1\xD3k\xCC\xA4\xA0\xEFy+B\x90\x9A", - no_header: "\xC97\x8B\x8E\xC1\xD3k\xCC\xA4\xA0\xEFy+B\x90\x9A" + header: +"@EnC\x00\x00\xC97\x8B\x8E\xC1\xD3k\xCC\xA4\xA0\xEFy+B\x90\x9A", + no_header: +"\xC97\x8B\x8E\xC1\xD3k\xCC\xA4\xA0\xEFy+B\x90\x9A" } } } - @non_utf8 = "\xc2".force_encoding("binary") + @non_utf8 = (+"\xc2").force_encoding("binary") @cipher = SymmetricEncryption::Cipher.new( key: "ABCDEF1234567890", iv: "ABCDEF1234567890", @@ -145,7 +147,7 @@ class CipherTest < Minitest::Test ) @social_security_number = "987654321" - @social_security_number_encrypted = "A\335*\314\336\250V\340\023%\000S\177\305\372\266" + @social_security_number_encrypted = +"A\335*\314\336\250V\340\023%\000S\177\305\372\266" @social_security_number_encrypted.force_encoding("binary") @sample_data = [ diff --git a/test/encoder_test.rb b/test/encoder_test.rb index 4cc1841..542e132 100644 --- a/test/encoder_test.rb +++ b/test/encoder_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative "test_helper" # Unit Test for SymmetricEncryption @@ -22,7 +24,7 @@ class EncoderTest < Minitest::Test @data end @encoder = SymmetricEncryption::Encoder[encoding] - @non_utf8 = "\xc2".force_encoding("binary") + @non_utf8 = (+"\xc2").force_encoding("binary") end it "correctly encodes" do diff --git a/test/header_test.rb b/test/header_test.rb index 257394b..f1b0d71 100644 --- a/test/header_test.rb +++ b/test/header_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative "test_helper" class CipherTest < Minitest::Test @@ -42,7 +44,7 @@ class CipherTest < Minitest::Test end it "does not have a header" do - refute SymmetricEncryption::Header.present?(clear_value) + refute SymmetricEncryption::Header.present?(+clear_value) end it "does not have a header when nil" do @@ -110,7 +112,7 @@ class CipherTest < Minitest::Test it "unencrypted string" do header = SymmetricEncryption::Header.new - assert_equal 0, header.parse("hello there") + assert_equal 0, header.parse(+"hello there") end it "encrypted string" do @@ -153,7 +155,7 @@ class CipherTest < Minitest::Test it "unencrypted string" do header = SymmetricEncryption::Header.new - assert_nil header.parse!("hello there") + assert_nil header.parse!(+"hello there") end it "encrypted string" do diff --git a/test/key_test.rb b/test/key_test.rb index cc09b25..0349f04 100644 --- a/test/key_test.rb +++ b/test/key_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative "test_helper" class KeyTest < Minitest::Test @@ -23,7 +25,7 @@ class KeyTest < Minitest::Test end let :encrypted_ssn do - essn = "cR\x9C,\x91\xA4{\b`\x9Fls\xA4\f\xD1\xBF" + essn = +"cR\x9C,\x91\xA4{\b`\x9Fls\xA4\f\xD1\xBF" essn.force_encoding("binary") essn end @@ -44,7 +46,7 @@ class KeyTest < Minitest::Test describe "decrypt" do it "empty string" do - assert_equal "", key.decrypt("") + assert_equal "", key.decrypt(+"") end it "nil" do diff --git a/test/keystore/aws_test.rb b/test/keystore/aws_test.rb index 8026c96..c8abf46 100644 --- a/test/keystore/aws_test.rb +++ b/test/keystore/aws_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative "../test_helper" require "stringio" diff --git a/test/keystore/environment_test.rb b/test/keystore/environment_test.rb index f88da7f..6fa0c61 100644 --- a/test/keystore/environment_test.rb +++ b/test/keystore/environment_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative "../test_helper" require "stringio" diff --git a/test/keystore/file_test.rb b/test/keystore/file_test.rb index f10e534..8eb52c6 100644 --- a/test/keystore/file_test.rb +++ b/test/keystore/file_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative "../test_helper" require "stringio" require "fileutils" diff --git a/test/keystore/gcp_test.rb b/test/keystore/gcp_test.rb index 8e15b68..5005766 100644 --- a/test/keystore/gcp_test.rb +++ b/test/keystore/gcp_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative "../test_helper" module SymmetricEncryption diff --git a/test/keystore/heroku_test.rb b/test/keystore/heroku_test.rb index c0c8307..00a4672 100644 --- a/test/keystore/heroku_test.rb +++ b/test/keystore/heroku_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative "../test_helper" require "stringio" diff --git a/test/keystore_test.rb b/test/keystore_test.rb index eb179b8..0498502 100644 --- a/test/keystore_test.rb +++ b/test/keystore_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative "test_helper" module SymmetricEncryption diff --git a/test/mongoid_test.rb b/test/mongoid_test.rb index 7f2249a..2ecb137 100644 --- a/test/mongoid_test.rb +++ b/test/mongoid_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + begin require "mongoid" require_relative "test_helper" diff --git a/test/reader_test.rb b/test/reader_test.rb index 605c368..17ad424 100644 --- a/test/reader_test.rb +++ b/test/reader_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative "test_helper" require "stringio" @@ -11,7 +13,7 @@ class ReaderTest < Minitest::Test "Keep this secret\n", "And keep going even further and further..." ] - @data_str = @data.inject("") { |sum, str| sum << str } + @data_str = @data.inject(+"") { |sum, str| sum << str } @data_len = @data_str.length # Use Cipher 0 since it does not always include a header @cipher = SymmetricEncryption.cipher(0) @@ -188,7 +190,7 @@ class ReaderTest < Minitest::Test # Not supported with compressed files if file.is_a?(SymmetricEncryption::Reader) eof = file.eof? - output_buffer = "buffer" + output_buffer = +"buffer" data = file.read(4096, output_buffer) file.close diff --git a/test/symmetric_encryption_test.rb b/test/symmetric_encryption_test.rb index 1688452..c993e51 100644 --- a/test/symmetric_encryption_test.rb +++ b/test/symmetric_encryption_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative "test_helper" # Unit Test for SymmetricEncryption @@ -59,11 +61,11 @@ class SymmetricEncryptionTest < Minitest::Test when :base16 "40456e4302004bef17d4d46ba9d7c4210c851d53ee54" when :none - "@EnC\x02\x00K\xEF\x17\xD4\xD4k\xA9\xD7\xC4!\f\x85\x1DS\xEET".force_encoding(Encoding.find("binary")) + (+"@EnC\x02\x00K\xEF\x17\xD4\xD4k\xA9\xD7\xC4!\f\x85\x1DS\xEET").force_encoding(Encoding.find("binary")) else raise "Add test for encoding: #{encoding}" end - @non_utf8 = "\xc2".force_encoding("binary") + @non_utf8 = (+"\xc2").force_encoding("binary") @encoding = SymmetricEncryption.cipher.encoding SymmetricEncryption.cipher.encoding = encoding end diff --git a/test/test_helper.rb b/test/test_helper.rb index 5242c41..bd7ca9e 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib" require "yaml" diff --git a/test/utils/aws_test.rb b/test/utils/aws_test.rb index c98a199..e27e9f9 100644 --- a/test/utils/aws_test.rb +++ b/test/utils/aws_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative "../test_helper" require "stringio" diff --git a/test/writer_test.rb b/test/writer_test.rb index ee3e026..499207b 100644 --- a/test/writer_test.rb +++ b/test/writer_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative "test_helper" require "stringio" @@ -11,7 +13,7 @@ class WriterTest < Minitest::Test "Keep this secret\n", "And keep going even further and further..." ] - @data_str = @data.inject("") { |sum, str| sum << str } + @data_str = @data.inject(+"") { |sum, str| sum << str } @data_len = @data_str.length @file_name = "._test" @source_file_name = "._source_test"