Commit cb2cc9a
Changed files (3)
lib
xml
kit
crypto
spec
support
xml
kit
crypto
lib/xml/kit/crypto/symmetric_cipher.rb
@@ -31,10 +31,10 @@ module Xml
end
def decrypt(cipher_text)
- iv_len = cipher.iv_len
- iv = cipher_text[0...iv_len]
- data = cipher_text[iv_len..-1]
- default_decrypt(iv, data)
+ default_decrypt(
+ cipher_text[0...cipher.iv_len],
+ cipher_text[cipher.iv_len..-1]
+ )
end
protected
spec/support/shell_helper.rb
@@ -1,10 +1,12 @@
# frozen_string_literal: true
+require 'English'
+
RSpec.configure do |config|
config.include(Module.new do
def execute_shell(command)
- puts command.inspect
- raise "command failed: #{command}" unless system(command)
+ puts `#{command}`
+ raise "command failed: #{command}" unless $CHILD_STATUS.success?
end
end)
end
spec/xml/kit/crypto/symmetric_cipher_spec.rb
@@ -51,12 +51,11 @@ RSpec.describe ::Xml::Kit::Crypto::SymmetricCipher do
subject { described_class.new(xml_algorithm, key) }
let(:encrypted_file) { Tempfile.new(algorithm).path }
- let(:original_file) { __FILE__ }
let(:decrypted_file) { Tempfile.new("#{algorithm}-decrypted").path }
- let(:original_content) { IO.read(original_file) }
+ let(:secret) { SecureRandom.hex }
before do
- IO.write(encrypted_file, subject.encrypt(IO.read(original_file)))
+ IO.write(encrypted_file, subject.encrypt(secret))
execute_shell([
"openssl enc -#{openssl_algorithm} -p -d -nosalt",
"-in #{encrypted_file}",
@@ -66,7 +65,7 @@ RSpec.describe ::Xml::Kit::Crypto::SymmetricCipher do
].join(' '))
end
- specify { expect(IO.read(decrypted_file)).to end_with(original_content) }
+ specify { expect(IO.read(decrypted_file)).to end_with(secret) }
end
end
end