Sha256: 13da15217b7c148e52f3f655c772d399d08b0a3f71ca68c85df226b50ac3e335
Contents?: true
Size: 1.71 KB
Versions: 3
Compression:
Stored size: 1.71 KB
Contents
require 'jwe/alg/dir' require 'jwe/alg/rsa_oaep' require 'jwe/alg/rsa15' require 'openssl' describe JWE::Alg do describe '.for' do it 'returns a class for the specified alg' do expect(JWE::Alg.for('RSA-OAEP')).to eq JWE::Alg::RsaOaep end it 'raises an error for a not-implemented alg' do expect { JWE::Alg.for('ERSA-4096-MAGIC') }.to raise_error(JWE::NotImplementedError) end end end describe JWE::Alg::Dir do # The direct encryption method does not Encrypt the CEK. # When building the final JWE object, the "Encrypted CEK" part is left blank describe '#encrypt' do it 'returns an empty string' do expect(JWE::Alg::Dir.new('whatever').encrypt('any')).to eq '' end end describe '#decrypt' do it 'returns the original key' do expect(JWE::Alg::Dir.new('whatever').decrypt('any')).to eq 'whatever' end end end key_path = File.dirname(__FILE__) + '/../keys/rsa.pem' key = OpenSSL::PKey::RSA.new File.read(key_path) describe JWE::Alg::RsaOaep do let(:alg) { JWE::Alg::RsaOaep.new(key) } describe '#encrypt' do it 'returns an encrypted string' do expect(alg.encrypt('random key')).to_not eq 'random key' end end it 'decrypts the encrypted key to the original key' do ciphertext = alg.encrypt('random key') expect(alg.decrypt(ciphertext)).to eq 'random key' end end describe JWE::Alg::Rsa15 do let(:alg) { JWE::Alg::Rsa15.new(key) } describe '#encrypt' do it 'returns an encrypted string' do expect(alg.encrypt('random key')).to_not eq 'random key' end end it 'decrypts the encrypted key to the original key' do ciphertext = alg.encrypt('random key') expect(alg.decrypt(ciphertext)).to eq 'random key' end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
jwe-0.2.0 | spec/jwe/alg_spec.rb |
jwe-0.1.1 | spec/jwe/alg_spec.rb |
jwe-0.1.0 | spec/jwe/alg_spec.rb |