diff --git a/.rubocop.yml b/.rubocop.yml index 8b36803..559bd75 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -41,7 +41,6 @@ Style/StringLiterals: Metrics/AbcSize: Exclude: - db/migrate/**/* - - app/services/crypt_serializer.rb Metrics/LineLength: Max: 110 @@ -54,3 +53,6 @@ Metrics/LineLength: Metrics/MethodLength: Exclude: - db/migrate/* + +Rails: + Enabled: true diff --git a/.ruby_version b/.ruby_version new file mode 100644 index 0000000..2bf1c1c --- /dev/null +++ b/.ruby_version @@ -0,0 +1 @@ +2.3.1 diff --git a/Guardfile b/Guardfile index e97c0a7..5113fbf 100644 --- a/Guardfile +++ b/Guardfile @@ -32,5 +32,6 @@ end guard :rubocop do watch(/.+\.rb$/) watch(/Rakefile/) + watch(/.rubocop.yml/) watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) } end diff --git a/app/services/crypt_serializer.rb b/app/services/crypt_serializer.rb index ef391c6..9f2b656 100644 --- a/app/services/crypt_serializer.rb +++ b/app/services/crypt_serializer.rb @@ -26,18 +26,28 @@ class CryptSerializer raise "Attribute was supposed to be a `String`, but was instead a `#{value.class}`" end - cipher.encrypt - parts = [cipher.random_key, cipher.random_iv, cipher.update(value) + cipher.final] - Base64.urlsafe_encode64 Marshal.dump(parts) + build_cipher value end def decrypt(value) return value if value.nil? parts = Marshal.load Base64.urlsafe_decode64(value) - cipher.decrypt - cipher.key = parts[0] - cipher.iv = parts[1] - cipher.update(parts[2]) + cipher.final + decode_cipher parts end + + private + + def build_cipher value + cipher.encrypt + parts = [cipher.random_key, cipher.random_iv, cipher.update(value) + cipher.final] + Base64.urlsafe_encode64 Marshal.dump(parts) + end + + def decode_cipher parts + cipher.decrypt + cipher.key = parts[0] + cipher.iv = parts[1] + cipher.update(parts[2]) + cipher.final + end end diff --git a/config/database.yml b/config/database.yml index 73b808d..23bb41d 100644 --- a/config/database.yml +++ b/config/database.yml @@ -16,7 +16,7 @@ default: &default host: <%= ENV['mysql_host'] %> username: <%= ENV['mysql_usr'] %> password: <%= ENV['mysql_pwd'] %> - socket: /var/run/mysqld/mysqld.sock + # socket: /var/run/mysqld/mysqld.sock development: <<: *default