File: digest_spec.rb

package info (click to toggle)
ruby3.1 3.1.2-7%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 132,892 kB
  • sloc: ruby: 1,154,753; ansic: 736,782; yacc: 46,445; pascal: 10,401; sh: 3,931; cpp: 1,158; python: 838; makefile: 787; asm: 462; javascript: 382; lisp: 97; sed: 94; perl: 62; awk: 36; xml: 4
file content (63 lines) | stat: -rw-r--r-- 2,267 bytes parent folder | download | duplicates (2)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require_relative '../../spec_helper'
require_relative '../../library/digest/sha1/shared/constants'
require_relative '../../library/digest/sha256/shared/constants'
require_relative '../../library/digest/sha384/shared/constants'
require_relative '../../library/digest/sha512/shared/constants'
require 'openssl'

describe "OpenSSL::Digest" do

  describe ".digest" do
    it "returns a SHA1 digest" do
      OpenSSL::Digest.digest('sha1', SHA1Constants::Contents).should == SHA1Constants::Digest
    end

    it "returns a SHA256 digest" do
      OpenSSL::Digest.digest('sha256', SHA256Constants::Contents).should == SHA256Constants::Digest
    end

    it "returns a SHA384 digest" do
      OpenSSL::Digest.digest('sha384', SHA384Constants::Contents).should == SHA384Constants::Digest
    end

    it "returns a SHA512 digest" do
      OpenSSL::Digest.digest('sha512', SHA512Constants::Contents).should == SHA512Constants::Digest
    end
  end

  describe ".hexdigest" do
    it "returns a SHA1 hexdigest" do
      OpenSSL::Digest.hexdigest('sha1', SHA1Constants::Contents).should == SHA1Constants::Hexdigest
    end

    it "returns a SHA256 hexdigest" do
      OpenSSL::Digest.hexdigest('sha256', SHA256Constants::Contents).should == SHA256Constants::Hexdigest
    end

    it "returns a SHA384 hexdigest" do
      OpenSSL::Digest.hexdigest('sha384', SHA384Constants::Contents).should == SHA384Constants::Hexdigest
    end

    it "returns a SHA512 hexdigest" do
      OpenSSL::Digest.hexdigest('sha512', SHA512Constants::Contents).should == SHA512Constants::Hexdigest
    end
  end

  describe ".base64digest" do
    it "returns a SHA1 base64digest" do
      OpenSSL::Digest.base64digest('sha1', SHA1Constants::Contents).should == SHA1Constants::Base64digest
    end

    it "returns a SHA256 base64digest" do
      OpenSSL::Digest.base64digest('sha256', SHA256Constants::Contents).should == SHA256Constants::Base64digest
    end

    it "returns a SHA384 base64digest" do
      OpenSSL::Digest.base64digest('sha384', SHA384Constants::Contents).should == SHA384Constants::Base64digest
    end

    it "returns a SHA512 base64digest" do
      OpenSSL::Digest.base64digest('sha512', SHA512Constants::Contents).should == SHA512Constants::Base64digest
    end
  end
end