Skip to content

Commit

Permalink
gem: update for ruby 3.2 (#23)
Browse files Browse the repository at this point in the history
* gem: update for ruby 3.2

* ci: add codeql

* ci: fix spec path

* ci: add dependabot yml
  • Loading branch information
q9f authored Jan 5, 2023
1 parent 20cc5de commit 1f85188
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 57 deletions.
18 changes: 18 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
updates:
-
directory: /
labels:
- dependencies
package-ecosystem: bundler
schedule:
interval: weekly
versioning-strategy: increase
-
directory: /
labels:
- operations
package-ecosystem: github-actions
schedule:
interval: monthly
version: 2
14 changes: 10 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
---
name: Build

on: [push, pull_request]
on:
pull_request:
branches:
- main
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.0
ruby-version: 3.2
- name: Install Dependencies
run: |
gem install test-unit
Expand Down
45 changes: 45 additions & 0 deletions .github/workflows/codecl.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
name: CodeQL

on:
pull_request:
branches:
- main
push:
branches:
- main

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language:
- ruby
- c
steps:
- name: "Checkout repository"
uses: actions/checkout@v3
- name: "Initialize CodeQL"
uses: github/codeql-action/init@v2
with:
languages: "${{ matrix.language }}"
- name: Autobuild
uses: github/codeql-action/autobuild@v2
- name: "Perform CodeQL Analysis"
uses: github/codeql-action/analyze@v2
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.2'
bundler-cache: true
- name: "Run rufo code formatting checks"
run: |
gem install rufo
rufo --check ./lib
rufo --check ./test
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

source 'https://rubygems.org'
source "https://rubygems.org"

# Specify your gem's dependencies in keccak.gemspec
gemspec
22 changes: 11 additions & 11 deletions ext/digest/extconf.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'mkmf'
require "mkmf"

def cflags(*args)
args.each do |str|
$CFLAGS += (ENV['OS'] == "Windows_NT") ? " #{str} " : " #{str.shellescape} "
$CFLAGS += (ENV["OS"] == "Windows_NT") ? " #{str} " : " #{str.shellescape} "
end
end

Expand All @@ -17,15 +17,15 @@ def have_func!(header, *args)
exit 1 unless have_func(*args, header)
end

cflags '-std=c11'
cflags '-Wall'
cflags '-Wextra'
cflags '-fvisibility=hidden'
cflags "-std=c11"
cflags "-Wall"
cflags "-Wextra"
cflags "-fvisibility=hidden"

have_header! 'ruby/digest.h'
have_header! 'stdio.h'
have_header! 'string.h'
have_header! "ruby/digest.h"
have_header! "stdio.h"
have_header! "string.h"

have_func! 'rb_str_set_len'
have_func! "rb_str_set_len"

create_makefile 'digest/keccak' or exit 1
create_makefile "digest/keccak" or exit 1
20 changes: 10 additions & 10 deletions keccak.gemspec
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true

lib = File.expand_path('lib', __dir__).freeze
lib = File.expand_path("lib", __dir__).freeze
$LOAD_PATH.unshift lib unless $LOAD_PATH.include? lib

require 'digest/keccak/version'
require "digest/keccak/version"

Gem::Specification.new do |spec|
spec.name = "keccak"
Expand All @@ -15,15 +15,15 @@ Gem::Specification.new do |spec|
spec.email = "%w[[email protected]]"
spec.extensions << "ext/digest/extconf.rb"
spec.platform = Gem::Platform::RUBY
spec.required_ruby_version = ">= 2.2", "< 4.0"
spec.required_ruby_version = ">= 2.7", "< 4.0"
spec.license = "Apache-2.0"
spec.metadata = {
'homepage_uri' => 'https://github.com/q9f/keccak.rb',
'source_code_uri' => 'https://github.com/q9f/keccak.rb',
'github_repo' => 'https://github.com/q9f/keccak.rb',
'bug_tracker_uri' => 'https://github.com/q9f/keccak.rb/issues',
"homepage_uri" => "https://github.com/q9f/keccak.rb",
"source_code_uri" => "https://github.com/q9f/keccak.rb",
"github_repo" => "https://github.com/q9f/keccak.rb",
"bug_tracker_uri" => "https://github.com/q9f/keccak.rb/issues",
}.freeze
spec.require_paths = ['lib']
spec.require_paths = ["lib"]
spec.files = Dir[
"README.md",
"COPYRIGHT",
Expand All @@ -34,6 +34,6 @@ Gem::Specification.new do |spec|
"lib/**/*"
]
spec.test_files = spec.files.grep %r{^(test|spec|features)/}
spec.add_development_dependency 'bundler', '~> 2.2'
spec.add_development_dependency 'test-unit', '~> 3.4'
spec.add_development_dependency "bundler", "~> 2.2"
spec.add_development_dependency "test-unit", "~> 3.4"
end
2 changes: 1 addition & 1 deletion lib/digest/keccak/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Digest
class Keccak
VERSION = "1.3.1"
VERSION = "1.3.2"
end
end
18 changes: 9 additions & 9 deletions test/generate_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
# Based on python-sha3's test suite.

FILES = [
['test/data/ShortMsgKAT_224.txt', 224],
['test/data/ShortMsgKAT_256.txt', 256],
['test/data/ShortMsgKAT_384.txt', 384],
['test/data/ShortMsgKAT_512.txt', 512],
['test/data/LongMsgKAT_224.txt', 224],
["test/data/ShortMsgKAT_224.txt", 224],
["test/data/ShortMsgKAT_256.txt", 256],
["test/data/ShortMsgKAT_384.txt", 384],
["test/data/ShortMsgKAT_512.txt", 512],
["test/data/LongMsgKAT_224.txt", 224],
]

def generate
Expand All @@ -23,15 +23,15 @@ class KeccakTests < Test::Unit::TestCase
}

FILES.each do |path, hashlen|
contents = File.read(path).split('Len = ')
contents = File.read(path).split("Len = ")
contents.each do |test|
lines = test.split("\n")
if !lines.empty? && lines[0] !~ /^#/
length = lines[0].to_i
if length % 8 == 0 && length != 0
msg_raw = [lines[1].split(' = ').last].pack("H*")
md = lines[2].split(' = ').last.downcase
name = File.basename(path).split('.')[0]
msg_raw = [lines[1].split(" = ").last].pack("H*")
md = lines[2].split(" = ").last.downcase
name = File.basename(path).split(".")[0]
puts %Q{
def test_#{name}_#{length}
inst = Digest::Keccak.new(#{hashlen})
Expand Down
8 changes: 4 additions & 4 deletions test/test_all.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

$LOAD_PATH.unshift(File.expand_path("lib"))
$LOAD_PATH.unshift(File.expand_path("ext"))
require 'digest/keccak'
require File.expand_path('test/test_usage')
require File.expand_path('test/test_vectors')
require File.expand_path('test/test_new')
require "digest/keccak"
require File.expand_path("test/test_usage")
require File.expand_path("test/test_vectors")
require File.expand_path("test/test_new")
14 changes: 7 additions & 7 deletions test/test_new.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# frozen_string_literal: true

require 'test/unit'
require "test/unit"

class KeccakNewTests < Test::Unit::TestCase
def test_singleton_method_hexdigest_256_empty
result = Digest::Keccak.hexdigest '', 256
result = Digest::Keccak.hexdigest "", 256
assert_instance_of String, result
assert_equal 'c5d2460186f7233c927e7db2dcc703c0' \
'e500b653ca82273b7bfad8045d85a470',
assert_equal "c5d2460186f7233c927e7db2dcc703c0" \
"e500b653ca82273b7bfad8045d85a470",
result
end

def test_singleton_method_hexdigest_256_sample
result = Digest::Keccak.hexdigest 'sample', 256
result = Digest::Keccak.hexdigest "sample", 256
assert_instance_of String, result
assert_equal 'b80204f7e9243e4fca5489740ccd31dc' \
'd0a54619a7f4165cee73c191ef7271a1',
assert_equal "b80204f7e9243e4fca5489740ccd31dc" \
"d0a54619a7f4165cee73c191ef7271a1",
result
end
end
20 changes: 10 additions & 10 deletions test/test_usage.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'test/unit'
require "test/unit"

class KeccakUsageTest < Test::Unit::TestCase
def init(hashsize = 512)
Expand All @@ -9,49 +9,49 @@ def init(hashsize = 512)

def test_copy
a = init(224)
a.update('foo')
a.update("foo")
b = a.dup
assert_equal b.digest, a.digest
b.update('bar')
b.update("bar")
assert_not_equal b.digest, a.digest
end

def test_class_methods
assert_equal 'a9cab59eb40a10b246290f2d6086e32e3689faf1d26b470c899f2802',
assert_equal "a9cab59eb40a10b246290f2d6086e32e3689faf1d26b470c899f2802",
Digest::Keccak.hexdigest("\xcc", 224)
end

def test_update
a = init(224)
a.update("\xcc")
assert_equal 'a9cab59eb40a10b246290f2d6086e32e3689faf1d26b470c899f2802', a.hexdigest
assert_equal "a9cab59eb40a10b246290f2d6086e32e3689faf1d26b470c899f2802", a.hexdigest
end

def test_updates
a = init(224)
a.update("\x21")
a.update("\xf1\x34")
a.update("\xac\x57")
assert_equal '5573da2b02216a860389a581f6e9fb8d805e9e02f6fa911701eee298', a.hexdigest
assert_equal "5573da2b02216a860389a581f6e9fb8d805e9e02f6fa911701eee298", a.hexdigest
end

def test_empty_224
a = init(224)
assert_equal 'f71837502ba8e10837bdd8d365adb85591895602fc552b48b7390abd', a.hexdigest
assert_equal "f71837502ba8e10837bdd8d365adb85591895602fc552b48b7390abd", a.hexdigest
end

def test_empty_256
a = init(256)
assert_equal 'c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470', a.hexdigest
assert_equal "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470", a.hexdigest
end

def test_empty_384
a = init(384)
assert_equal '2c23146a63a29acf99e73b88f8c24eaa7dc60aa771780ccc006afbfa8fe2479b2dd2b21362337441ac12b515911957ff', a.hexdigest()
assert_equal "2c23146a63a29acf99e73b88f8c24eaa7dc60aa771780ccc006afbfa8fe2479b2dd2b21362337441ac12b515911957ff", a.hexdigest()
end

def test_empty_512
a = init(512)
assert_equal '0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e', a.hexdigest
assert_equal "0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e", a.hexdigest
end
end

0 comments on commit 1f85188

Please sign in to comment.