Sha256: c33d9618d0b71809b4c903bcc74456d6a5b2ec02bfec0dff6a4fa512a0ae4bd4

Contents?: true

Size: 987 Bytes

Versions: 1

Compression:

Stored size: 987 Bytes

Contents

require 'spec_helper'

describe Parsel do
  let(:key) { 'my secret key' }

  it 'encrypts data' do
    expect(Parsel.encrypt(key, 'hello')).not_to eq('hello')
  end

  it 'decrypts data' do
    encrypted = Parsel.encrypt(key, 'hello')
    expect(Parsel.decrypt(key, encrypted)).to eq('hello')
  end

  it 'returns false when decryption fails' do
    expect(Parsel.decrypt('abc', '123')).to be_falsy
  end

  it 'uses custom iv' do
    iv = SecureRandom.hex(100)
    encrypted = Parsel.encrypt(key, iv, 'hello')

    expect(Parsel.decrypt(key, iv, encrypted)).to eq('hello')
  end

  it 'return false when decryption for custom iv fails' do
    iv = SecureRandom.hex(100)
    encrypted = Parsel.encrypt(key, iv, 'hello')

    expect(Parsel.decrypt(key, encrypted)).to be_falsy
  end

  it 'changes global iv' do
    iv = SecureRandom.hex(100)
    Parsel.default_iv = iv
    encrypted = Parsel.encrypt(key, 'hello')

    expect(Parsel.decrypt(key, iv, encrypted)).to eq('hello')
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
parsel-0.3.0 spec/parsel_spec.rb