Skip to content
Open
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
2 changes: 2 additions & 0 deletions lib/symmetric-encryption.rb
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# frozen_string_literal: true

require "symmetric_encryption"
2 changes: 2 additions & 0 deletions lib/symmetric_encryption.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "symmetric_encryption/core"

# Add extensions. Gems are no longer order dependent.
Expand Down
2 changes: 2 additions & 0 deletions lib/symmetric_encryption/active_record/attr_encrypted.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module SymmetricEncryption
module ActiveRecord
module AttrEncrypted
Expand Down
2 changes: 2 additions & 0 deletions lib/symmetric_encryption/active_record/encrypted_attribute.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module SymmetricEncryption
module ActiveRecord
class EncryptedAttribute < ::ActiveModel::Type::String
Expand Down
2 changes: 2 additions & 0 deletions lib/symmetric_encryption/cipher.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "openssl"
module SymmetricEncryption
# Hold all information related to encryption keys
Expand Down
2 changes: 2 additions & 0 deletions lib/symmetric_encryption/cli.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "optparse"
require "fileutils"
module SymmetricEncryption
Expand Down
2 changes: 2 additions & 0 deletions lib/symmetric_encryption/coerce.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module SymmetricEncryption
# For coercing data types to from strings
module Coerce
Expand Down
2 changes: 2 additions & 0 deletions lib/symmetric_encryption/config.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "erb"
require "yaml"
module SymmetricEncryption
Expand Down
2 changes: 2 additions & 0 deletions lib/symmetric_encryption/core.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Used for compression
require "zlib"
# Used to coerce data types between string and their actual types
Expand Down
2 changes: 2 additions & 0 deletions lib/symmetric_encryption/encoder.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module SymmetricEncryption
module Encoder
def self.[](encoding)
Expand Down
2 changes: 2 additions & 0 deletions lib/symmetric_encryption/exception.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module SymmetricEncryption
# Exceptions created by SymmetricEncryption
class Error < StandardError
Expand Down
2 changes: 2 additions & 0 deletions lib/symmetric_encryption/generator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module SymmetricEncryption
module Generator
# Common internal method for generating accessors for decrypted accessors
Expand Down
4 changes: 3 additions & 1 deletion lib/symmetric_encryption/header.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module SymmetricEncryption
# Defines the Header Structure returned when parsing the header.
#
Expand All @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions lib/symmetric_encryption/key.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/symmetric_encryption/keystore.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module SymmetricEncryption
# Encryption keys are secured in Keystores
module Keystore
Expand Down
2 changes: 2 additions & 0 deletions lib/symmetric_encryption/keystore/aws.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "aws-sdk-kms"
module SymmetricEncryption
module Keystore
Expand Down
2 changes: 2 additions & 0 deletions lib/symmetric_encryption/keystore/environment.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module SymmetricEncryption
module Keystore
# Store the encrypted encryption key in an environment variable
Expand Down
2 changes: 2 additions & 0 deletions lib/symmetric_encryption/keystore/file.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module SymmetricEncryption
module Keystore
class File
Expand Down
2 changes: 2 additions & 0 deletions lib/symmetric_encryption/keystore/gcp.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "google/cloud/kms/v1"

module SymmetricEncryption
Expand Down
2 changes: 2 additions & 0 deletions lib/symmetric_encryption/keystore/heroku.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module SymmetricEncryption
module Keystore
# Heroku uses environment variables too.
Expand Down
2 changes: 2 additions & 0 deletions lib/symmetric_encryption/keystore/memory.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module SymmetricEncryption
module Keystore
# In Memory Keystore usually used for testing purposes
Expand Down
2 changes: 2 additions & 0 deletions lib/symmetric_encryption/railtie.rb
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 2 additions & 0 deletions lib/symmetric_encryption/railties/mongoid_encrypted.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "mongoid"
# Add :encrypted option for Mongoid models
#
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Add an ActiveModel Validator
#
# Example:
Expand Down
4 changes: 3 additions & 1 deletion lib/symmetric_encryption/reader.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "openssl"

module SymmetricEncryption
Expand Down Expand Up @@ -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?
Expand Down
2 changes: 2 additions & 0 deletions lib/symmetric_encryption/rsa_key.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "openssl"
module SymmetricEncryption
# DEPRECATED - Internal use only
Expand Down
2 changes: 2 additions & 0 deletions lib/symmetric_encryption/symmetric_encryption.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "base64"
require "openssl"
require "zlib"
Expand Down
2 changes: 2 additions & 0 deletions lib/symmetric_encryption/utils/aws.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "base64"
require "aws-sdk-kms"
module SymmetricEncryption
Expand Down
2 changes: 2 additions & 0 deletions lib/symmetric_encryption/utils/files.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module SymmetricEncryption
module Utils
module Files
Expand Down
2 changes: 2 additions & 0 deletions lib/symmetric_encryption/utils/re_encrypt_files.rb
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 2 additions & 0 deletions lib/symmetric_encryption/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module SymmetricEncryption
VERSION = "4.6.0".freeze
end
2 changes: 2 additions & 0 deletions lib/symmetric_encryption/writer.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "openssl"

module SymmetricEncryption
Expand Down
2 changes: 2 additions & 0 deletions test/active_record/encrypted_attribute_test.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 2 additions & 0 deletions test/active_record_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative "test_helper"

if ActiveRecord.version <= Gem::Version.new("7.0.0")
Expand Down
10 changes: 6 additions & 4 deletions test/cipher_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative "test_helper"

# Tests for SymmetricEncryption::Cipher
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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 = [
Expand Down
4 changes: 3 additions & 1 deletion test/encoder_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative "test_helper"

# Unit Test for SymmetricEncryption
Expand All @@ -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
Expand Down
8 changes: 5 additions & 3 deletions test/header_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative "test_helper"

class CipherTest < Minitest::Test
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions test/key_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative "test_helper"

class KeyTest < Minitest::Test
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions test/keystore/aws_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative "../test_helper"
require "stringio"

Expand Down
2 changes: 2 additions & 0 deletions test/keystore/environment_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative "../test_helper"
require "stringio"

Expand Down
2 changes: 2 additions & 0 deletions test/keystore/file_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative "../test_helper"
require "stringio"
require "fileutils"
Expand Down
2 changes: 2 additions & 0 deletions test/keystore/gcp_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative "../test_helper"

module SymmetricEncryption
Expand Down
2 changes: 2 additions & 0 deletions test/keystore/heroku_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative "../test_helper"
require "stringio"

Expand Down
2 changes: 2 additions & 0 deletions test/keystore_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative "test_helper"

module SymmetricEncryption
Expand Down
2 changes: 2 additions & 0 deletions test/mongoid_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

begin
require "mongoid"
require_relative "test_helper"
Expand Down
6 changes: 4 additions & 2 deletions test/reader_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative "test_helper"
require "stringio"

Expand All @@ -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)
Expand Down Expand Up @@ -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

Expand Down
Loading
Loading