Sha256: 09c1d0cb655607a61237a70cf5e1bd04d9ba9962c4e1c6fa9d94d15da8f711ab

Contents?: true

Size: 1.23 KB

Versions: 5

Compression:

Stored size: 1.23 KB

Contents

# encoding: binary
# frozen_string_literal: true

RSpec.shared_examples "HMAC" do
  context ".new" do
    it "raises EncodingError on a key with wrong encoding" do
      expect { described_class.new(wrong_key) }.to raise_error(EncodingError)
    end
  end

  context ".auth" do
    it "raises EncodingError on a key with wrong encoding " do
      expect { described_class.auth(wrong_key, message) }.to raise_error(EncodingError)
    end
  end

  context ".verify" do
    it "raises EncodingError on a key with wrong encoding" do
      expect { described_class.verify(wrong_key, tag, message) }.to raise_error(EncodingError)
    end
  end

  context "Instance methods" do
    let(:authenticator) { described_class.new(key) }

    before(:each) { authenticator.update(message) }

    context "#update" do
      it "returns hexdigest when produces an authenticator" do
        expect(authenticator.update(message)).to eq mult_tag.unpack("H*").first
      end
    end

    context "#digest" do
      it "returns an authenticator" do
        expect(authenticator.digest).to eq tag
      end
    end

    context "#hexdigest" do
      it "returns hex authenticator" do
        expect(authenticator.hexdigest).to eq tag.unpack("H*").first
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rbnacl-7.1.1 spec/shared/hmac.rb
rbnacl-7.1.0 spec/shared/hmac.rb
rbnacl-7.0.0 spec/shared/hmac.rb
rbnacl-6.0.1 spec/shared/hmac.rb
rbnacl-6.0.0 spec/shared/hmac.rb