Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,20 @@ jobs:
os:
- ubuntu-20.04
- ubuntu-18.04
- macos-11.0
- macos-11
- macos-10.15
- windows-latest
ruby:
- '3.0'
- 2.7
- 2.6
- 2.5
- debug
include:
- { os: ubuntu-20.04, ruby: head, ignore-pkg-error: true }
- { os: windows-latest, ruby: mingw, ignore-pkg-error: true }
- { os: windows-latest, ruby: mswin, ignore-pkg-error: true }
- { os: ubuntu-20.04, ruby: jruby }
- { os: ubuntu-20.04, ruby: jruby-head, ignore-pkg-error: true }
exclude:
- { os: windows-latest, ruby: debug }

Expand All @@ -43,11 +44,11 @@ jobs:

- run: bundle install

- run: rake compile
- run: bundle exec rake compile

- run: rake build
- run: bundle exec rake build

- run: rake test
- run: bundle exec rake test

- run: gem install pkg/*.gem
- run: rake check
continue-on-error: ${{ matrix.ignore-pkg-error || (matrix.ruby == 'debug') }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/pkg/
/spec/reports/
/tmp/
lib/*.jar
*.bundle
*.so
*.o
66 changes: 58 additions & 8 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,71 @@ require "rake/testtask"

Rake::TestTask.new(:test) do |t|
t.libs << "test" << "test/lib" << "lib"
if RUBY_ENGINE == "jruby"
t.libs << "ext/java/org/jruby/ext/digest/lib"
else
t.libs << "ext/digest/lib"
end
t.ruby_opts << "-rhelper"
t.test_files = FileList["test/**/test_*.rb"]
end

require 'rake/extensiontask'
Rake::ExtensionTask.new("digest")
%w(bubblebabble md5 rmd160 sha1 sha2).each do |ext|
Rake::ExtensionTask.new("digest/#{ext}")
if RUBY_ENGINE == "jruby"
require "rake/javaextensiontask"
Rake::JavaExtensionTask.new("digest") do |ext|
ext.source_version = "1.8"
ext.target_version = "1.8"
ext.ext_dir = "ext/java"
end
else
require "rake/extensiontask"
Rake::ExtensionTask.new("digest")
%w[bubblebabble md5 rmd160 sha1 sha2].each do |ext|
Rake::ExtensionTask.new("digest/#{ext}")
end
end

task :sync_tool do
require 'fileutils'
FileUtils.cp "../ruby/tool/lib/test/unit/core_assertions.rb", "./test/lib"
FileUtils.cp "../ruby/tool/lib/envutil.rb", "./test/lib"
FileUtils.cp "../ruby/tool/lib/find_executable.rb", "./test/lib"
cp "../ruby/tool/lib/core_assertions.rb", "./test/lib"
cp "../ruby/tool/lib/envutil.rb", "./test/lib"
cp "../ruby/tool/lib/find_executable.rb", "./test/lib"
end

task :check => :"install:local" do
spec = Gem::Specification::load("digest.gemspec")
version = spec.version.to_s

require_relative "test/lib/envutil"

_, _, status = EnvUtil.invoke_ruby([], <<~EOS)
version = #{version.dump}
gem "digest", version
loaded_version = Gem.loaded_specs["digest"].version.to_s

if loaded_version == version
puts "digest \#{loaded_version} is loaded."
else
abort "digest \#{loaded_version} is loaded instead of \#{version}!"
end

require "digest"

string = "digest"
actual = Digest::SHA256.hexdigest(string)
expected = "0bf474896363505e5ea5e5d6ace8ebfb13a760a409b1fb467d428fc716f9f284"
puts "sha256(\#{string.dump}) = \#{actual.dump}"

if actual != expected
abort "no! expected to be \#{expected.dump}!"
end
EOS

if status.success?
puts "check succeeded!"
else
warn "check failed!"
exit status.exitstatus
end
end

task :default => :test
53 changes: 17 additions & 36 deletions digest.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,28 @@ Gem::Specification.new do |spec|
spec.homepage = "https://github.com/ruby/digest"
spec.licenses = ["Ruby", "BSD-2-Clause"]

spec.files = [
"LICENSE.txt", "README.md",

"ext/digest/defs.h", "ext/digest/digest.c", "ext/digest/digest.h",
"ext/digest/digest_conf.rb", "ext/digest/extconf.rb",
"ext/digest/lib/digest.rb",

"ext/digest/bubblebabble/bubblebabble.c",
"ext/digest/bubblebabble/extconf.rb",

"ext/digest/md5/extconf.rb", "ext/digest/md5/md5.c",
"ext/digest/md5/md5.h", "ext/digest/md5/md5cc.h",
"ext/digest/md5/md5init.c",

"ext/digest/rmd160/extconf.rb", "ext/digest/rmd160/rmd160.c",
"ext/digest/rmd160/rmd160.h", "ext/digest/rmd160/rmd160init.c",

"ext/digest/sha1/extconf.rb", "ext/digest/sha1/sha1.c",
"ext/digest/sha1/sha1.h", "ext/digest/sha1/sha1cc.h",
"ext/digest/sha1/sha1init.c",

"ext/digest/sha2/extconf.rb", "ext/digest/sha2/lib/sha2.rb",
"ext/digest/sha2/sha2.c", "ext/digest/sha2/sha2.h",
"ext/digest/sha2/sha2cc.h", "ext/digest/sha2/sha2init.c",

"ext/openssl/deprecation.rb",
"ext/digest/test.sh",
spec.files = [
"LICENSE.txt",
"README.md",
*Dir["lib/digest{.rb,/**/*.rb}"],
]

spec.required_ruby_version = ">= 2.5.0"

spec.bindir = "exe"
spec.executables = []
spec.require_paths = ["lib"]
spec.extensions = %w[
ext/digest/extconf.rb
ext/digest/bubblebabble/extconf.rb
ext/digest/md5/extconf.rb
ext/digest/rmd160/extconf.rb
ext/digest/sha1/extconf.rb
ext/digest/sha2/extconf.rb
]

if Gem::Platform === spec.platform and spec.platform =~ 'java' or RUBY_ENGINE == 'jruby'
spec.platform = 'java'

spec.files += Dir["ext/java/**/*.{rb,java}"]
spec.require_paths = %w[lib ext/java/org/jruby/ext/digest/lib]
else
spec.extensions = Dir["ext/digest/**/extconf.rb"]

spec.files += Dir["ext/digest/**/*.{rb,c,h,sh}"]
spec.require_paths = %w[lib]
end

spec.metadata["msys2_mingw_dependencies"] = "openssl"
end
3 changes: 3 additions & 0 deletions ext/digest/lib/digest/loader.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# frozen_string_literal: true

require 'digest.so'
3 changes: 3 additions & 0 deletions ext/digest/lib/digest/sha2/loader.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# frozen_string_literal: true

require 'digest/sha2.so'
119 changes: 119 additions & 0 deletions ext/java/org/jruby/ext/digest/BubbleBabble.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
**** BEGIN LICENSE BLOCK *****
* BSD 2-Clause License
*
* Copyright (c) 2010, Charles Oliver Nutter <headius@headius.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
***** END LICENSE BLOCK *****/

package org.jruby.ext.digest;

import org.jruby.Ruby;
import org.jruby.runtime.load.Library;
import org.jruby.util.ByteList;

import java.io.IOException;

public class BubbleBabble implements Library {

public void load(final Ruby runtime, boolean wrap) throws IOException {
RubyDigest.createDigestBubbleBabble(runtime);
}

/**
* Ported from OpenSSH (https://github.com/openssh/openssh-portable/blob/957fbceb0f3166e41b76fdb54075ab3b9cc84cba/sshkey.c#L942-L987)
*
* OpenSSH License Notice
*
* Copyright (c) 2000, 2001 Markus Friedl. All rights reserved.
* Copyright (c) 2008 Alexander von Gernler. All rights reserved.
* Copyright (c) 2010,2011 Damien Miller. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
public static ByteList bubblebabble(byte[] message, int begin, int length) {
char[] vowels = new char[]{'a', 'e', 'i', 'o', 'u', 'y'};
char[] consonants = new char[]{'b', 'c', 'd', 'f', 'g', 'h', 'k', 'l', 'm',
'n', 'p', 'r', 's', 't', 'v', 'z', 'x'};

long seed = 1;

ByteList retval = new ByteList();

int rounds = (length / 2) + 1;
retval.append('x');
for (int i = 0; i < rounds; i++) {
int idx0, idx1, idx2, idx3, idx4;

if ((i + 1 < rounds) || (length % 2 != 0)) {
long b = message[begin + 2 * i] & 0xFF;
idx0 = (int) ((((b >> 6) & 3) + seed) % 6) & 0xFFFFFFFF;
idx1 = (int) (((b) >> 2) & 15) & 0xFFFFFFFF;
idx2 = (int) (((b & 3) + (seed / 6)) % 6) & 0xFFFFFFFF;
retval.append(vowels[idx0]);
retval.append(consonants[idx1]);
retval.append(vowels[idx2]);
if ((i + 1) < rounds) {
long b2 = message[begin + (2 * i) + 1] & 0xFF;
idx3 = (int) ((b2 >> 4) & 15) & 0xFFFFFFFF;
idx4 = (int) ((b2) & 15) & 0xFFFFFFFF;
retval.append(consonants[idx3]);
retval.append('-');
retval.append(consonants[idx4]);
seed = ((seed * 5) +
((b * 7) +
b2)) % 36;
}
} else {
idx0 = (int) (seed % 6) & 0xFFFFFFFF;
idx1 = 16;
idx2 = (int) (seed / 6) & 0xFFFFFFFF;
retval.append(vowels[idx0]);
retval.append(consonants[idx1]);
retval.append(vowels[idx2]);
}
}
retval.append('x');

return retval;
}
}
44 changes: 44 additions & 0 deletions ext/java/org/jruby/ext/digest/DigestLibrary.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
**** BEGIN LICENSE BLOCK *****
* BSD 2-Clause License
*
* Copyright (C) 2006 Ola Bini <ola@ologix.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
***** END LICENSE BLOCK *****/

package org.jruby.ext.digest;

import java.io.IOException;

import org.jruby.Ruby;
import org.jruby.runtime.load.Library;

/**
* @author <a href="mailto:ola.bini@ki.se">Ola Bini</a>
*/
public class DigestLibrary implements Library {
public void load(final Ruby runtime, boolean wrap) throws IOException {
org.jruby.ext.digest.RubyDigest.createDigest(runtime);
}
}// DigestLibrary
Loading