File: hmac.rb

package info (click to toggle)
ruby-rbnacl 7.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 700 kB
  • sloc: ruby: 2,884; makefile: 3
file content (46 lines) | stat: -rw-r--r-- 1,260 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 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