Commit 6bfc95a
Changed files (2)
spec
support
xml
kit
crypto
spec/support/shell_helper.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+RSpec.configure do |config|
+ config.include(Module.new do
+ def execute_shell(command)
+ puts command.inspect
+ raise "command failed: #{command}" unless system(command)
+ end
+ end)
+end
spec/xml/kit/crypto/symmetric_cipher_spec.rb
@@ -1,34 +1,6 @@
# frozen_string_literal: true
RSpec.describe ::Xml::Kit::Crypto::SymmetricCipher do
- def execute_shell(command)
- puts command.inspect
- raise "command failed: #{command}" unless system(command)
- end
- let(:key_size) do
- hash = Hash.new(32 / 2)
- hash['aes128-cbc'] = 16 / 2
- hash['aes192-cbc'] = 24 / 2
- hash['tripledes-cbc'] = 24 / 2
- hash
- end
-
- [
- 'tripledes-cbc',
- 'aes128-cbc',
- 'aes192-cbc',
- 'aes256-cbc',
- ].each do |algorithm|
- describe algorithm do
- subject { described_class.new("#{::Xml::Kit::Namespaces::XMLENC}#{algorithm}", key) }
-
- let(:key) { SecureRandom.hex(key_size[algorithm]) }
- let(:uuid) { SecureRandom.uuid }
-
- specify { expect(subject.decrypt(subject.encrypt(uuid))).to eql(uuid) }
- end
- end
-
[
['tripledes-cbc', 192],
['aes128-cbc', 128],
@@ -42,6 +14,14 @@ RSpec.describe ::Xml::Kit::Crypto::SymmetricCipher do
let(:key) { SecureRandom.random_bytes(bytes_length) }
let(:iv) { SecureRandom.random_bytes(bytes_length) }
+ describe 'encrypting and decrypting' do
+ subject { described_class.new(xml_algorithm, key) }
+
+ let(:uuid) { SecureRandom.uuid }
+
+ specify { expect(subject.decrypt(subject.encrypt(uuid))).to eql(uuid) }
+ end
+
describe "decrypting #{algorithm} encrypted with the OpenSSL CLI" do
subject { described_class.new(xml_algorithm, key, 0) }