blake2b_rs 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d6be97419891922570b5b97e14e781d7a1bc957f03d543f4c7a1a0806e3f925d
4
- data.tar.gz: 07d4a203d944db9f2623712ae3e22a8a66d181aa639a2b8fca132e733ac338f1
3
+ metadata.gz: 1efeab05937eaf481f8b8cf29f089e87a163a7b2b7bd01700ef404c818a80992
4
+ data.tar.gz: 57bac7eb73edaf73c12ba5d1514514cb9fbfe50c5ae335155ae4163d57661e11
5
5
  SHA512:
6
- metadata.gz: 158c8dcbab1a2b227e0377a06036093c6a3175c7fd6d6f4cb8b9a3939f909360d09578ab3a73609d827350f32cb58f00c156550805d8cfba51f50ef49a639345
7
- data.tar.gz: 59055f7d7b2802e0ecb27a0961cdfcedbe214202662b29156b1f89fc421c58f756e33fd1fc8a5aef9259dfc9dc75597a0e2bacb8ff4c542e1cc5676d20488568
6
+ metadata.gz: 7b81a7f9d5d2e02a50e337c7144bd9152f747b882e602b615462675398fb84cc063d28fa63b66d01f67096db2e82edc24a8c65bff79497b77a258564cc2cb6c7
7
+ data.tar.gz: fd1402ae62998ea33ce953094ada3aabc8dc15cb44578a1648b4de0c65251199c33767b143c23b3fb924d7b50f0e04a48e663389aefcaa9449cac694f226dbb8
data/.gitignore CHANGED
@@ -14,3 +14,4 @@
14
14
  # Added by cargo
15
15
 
16
16
  /target
17
+ /mkmf.log
data/Cargo.lock CHANGED
@@ -17,6 +17,7 @@ version = "0.1.0"
17
17
  dependencies = [
18
18
  "blake2",
19
19
  "hex",
20
+ "libc",
20
21
  ]
21
22
 
22
23
  [[package]]
@@ -54,6 +55,12 @@ version = "0.4.3"
54
55
  source = "registry+https://github.com/rust-lang/crates.io-index"
55
56
  checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
56
57
 
58
+ [[package]]
59
+ name = "libc"
60
+ version = "0.2.90"
61
+ source = "registry+https://github.com/rust-lang/crates.io-index"
62
+ checksum = "ba4aede83fc3617411dc6993bc8c70919750c1c257c6ca6a502aed6e0e2394ae"
63
+
57
64
  [[package]]
58
65
  name = "opaque-debug"
59
66
  version = "0.3.0"
data/Cargo.toml CHANGED
@@ -9,6 +9,7 @@ edition = "2018"
9
9
  [dependencies]
10
10
  blake2 = "0.9"
11
11
  hex = "0.4.3"
12
+ libc = "0.2.90"
12
13
 
13
14
  [lib]
14
15
  crate-type=["dylib"]
data/Gemfile.lock CHANGED
@@ -1,14 +1,16 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- blake2b_rs (0.1.1)
4
+ blake2b_rs (0.1.2)
5
5
  ffi (= 1.15.0)
6
+ thermite (~> 0)
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
9
10
  specs:
10
11
  diff-lcs (1.4.4)
11
12
  ffi (1.15.0)
13
+ minitar (0.9)
12
14
  rake (12.3.3)
13
15
  rspec (3.10.0)
14
16
  rspec-core (~> 3.10.0)
@@ -23,6 +25,11 @@ GEM
23
25
  diff-lcs (>= 1.2.0, < 2.0)
24
26
  rspec-support (~> 3.10.0)
25
27
  rspec-support (3.10.2)
28
+ thermite (0.13.0)
29
+ minitar (~> 0.5)
30
+ rake (>= 10)
31
+ tomlrb (~> 1.2)
32
+ tomlrb (1.3.0)
26
33
 
27
34
  PLATFORMS
28
35
  ruby
data/Rakefile CHANGED
@@ -1,6 +1,11 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'thermite/tasks'
3
3
 
4
- RSpec::Core::RakeTask.new(:spec)
4
+ Thermite::Tasks.new
5
5
 
6
- task :default => :spec
6
+ task default: %w(thermite:build)
7
+
8
+ desc 'Run Rust & Ruby testsuites'
9
+ task test: ['thermite:build', 'thermite:test'] do
10
+
11
+ end
data/blake2b.gemspec CHANGED
@@ -6,8 +6,8 @@ Gem::Specification.new do |spec|
6
6
  spec.authors = ["Aki Wu"]
7
7
  spec.email = ["wuminzhe@gmail.com"]
8
8
 
9
- spec.summary = %q{Blake2b from rust}
10
- spec.description = %q{Blake2b from rust}
9
+ spec.summary = %q{A ruby blake2b gem which using rust blake2 crate}
10
+ spec.description = %q{A ruby blake2b gem which using rust blake2 crate}
11
11
  spec.homepage = "https://github.com/wuminzhe/blake2b"
12
12
  spec.license = "MIT"
13
13
  spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
@@ -25,5 +25,9 @@ Gem::Specification.new do |spec|
25
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
26
  spec.require_paths = ["lib"]
27
27
 
28
+ spec.extensions << 'ext/Rakefile'
29
+
30
+ spec.add_runtime_dependency 'thermite', '~> 0'
31
+
28
32
  spec.add_dependency "ffi", "1.15.0"
29
33
  end
data/ext/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require 'thermite/tasks'
2
+
3
+ project_dir = File.dirname(File.dirname(__FILE__))
4
+ Thermite::Tasks.new(cargo_project_path: project_dir, ruby_project_path: project_dir)
5
+ task default: %w(thermite:build)
data/lib/blake2b.rb CHANGED
@@ -1,17 +1,39 @@
1
1
  require "blake2b/version"
2
2
  require 'ffi'
3
3
 
4
+ class Str < FFI::AutoPointer
5
+ def self.release(ptr)
6
+ Blake2b.free(ptr)
7
+ end
8
+
9
+ def to_s
10
+ @str ||= self.read_string.force_encoding('UTF-8')
11
+ end
12
+ end
13
+
4
14
  module Blake2b
5
15
  class Error < StandardError; end
6
16
 
7
17
  extend FFI::Library
8
- ffi_lib "target/debug/libblake2b." + FFI::Platform::LIBSUFFIX
9
- attach_function :rust_blake2b, %i[pointer int int], :string
18
+ ffi_lib "#{__dir__}/../target/release/libblake2b." + FFI::Platform::LIBSUFFIX
19
+ attach_function :rust_blake2b, %i[pointer int int], Str
10
20
 
11
21
  def self.hex(u8a, out_len=32)
12
22
  c = FFI::MemoryPointer.new(:int8, u8a.size)
13
23
  c.write_array_of_int8 u8a
14
24
 
15
- self.rust_blake2b(c, c.size, out_len)
25
+ self.rust_blake2b(c, c.size, out_len).to_s
26
+ end
27
+
28
+ def self.blake2b160(u8a)
29
+ self.hex(u8a, 20)
30
+ end
31
+
32
+ def self.blake2b256(u8a)
33
+ self.hex(u8a, 32)
34
+ end
35
+
36
+ def self.blake2b512(u8a)
37
+ self.hex(u8a, 64)
16
38
  end
17
39
  end
@@ -1,3 +1,3 @@
1
1
  module Blake2b
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/src/lib.rs CHANGED
@@ -1,6 +1,8 @@
1
1
  use std::slice;
2
2
  use blake2::VarBlake2b;
3
3
  use blake2::digest::{Update, VariableOutput};
4
+ use libc::c_char;
5
+ use std::ffi::CString;
4
6
 
5
7
  fn to_u8_vec(pointer: *const u8, len: usize) -> Vec<u8> {
6
8
  let data_slice = unsafe {
@@ -11,13 +13,15 @@ fn to_u8_vec(pointer: *const u8, len: usize) -> Vec<u8> {
11
13
  }
12
14
 
13
15
  #[no_mangle]
14
- pub extern fn rust_blake2b(p: *const u8, len: usize, out_len: usize) -> *const u8{
16
+ pub extern fn rust_blake2b(p: *const u8, len: usize, out_len: usize) -> *mut c_char{
15
17
  let data = to_u8_vec(p, len);
16
18
  let mut hasher = VarBlake2b::new(out_len).unwrap();
17
19
  hasher.update(&data);
18
20
  let mut result = vec![0u8; out_len];
19
21
  hasher.finalize_variable(|res| {
20
- result.copy_from_slice(res);
22
+ result[0..out_len].copy_from_slice(res);
21
23
  });
22
- hex::encode(result).as_ptr()
24
+ let s = hex::encode(result);
25
+ let c_str = CString::new(s).unwrap();
26
+ c_str.into_raw()
23
27
  }
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blake2b_rs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aki Wu
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-19 00:00:00.000000000 Z
11
+ date: 2021-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thermite
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: ffi
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -24,11 +38,12 @@ dependencies:
24
38
  - - '='
25
39
  - !ruby/object:Gem::Version
26
40
  version: 1.15.0
27
- description: Blake2b from rust
41
+ description: A ruby blake2b gem which using rust blake2 crate
28
42
  email:
29
43
  - wuminzhe@gmail.com
30
44
  executables: []
31
- extensions: []
45
+ extensions:
46
+ - ext/Rakefile
32
47
  extra_rdoc_files: []
33
48
  files:
34
49
  - ".gitignore"
@@ -45,6 +60,7 @@ files:
45
60
  - bin/console
46
61
  - bin/setup
47
62
  - blake2b.gemspec
63
+ - ext/Rakefile
48
64
  - lib/blake2b.rb
49
65
  - lib/blake2b/version.rb
50
66
  - src/lib.rs
@@ -54,7 +70,7 @@ licenses:
54
70
  metadata:
55
71
  allowed_push_host: https://rubygems.org/
56
72
  homepage_uri: https://github.com/wuminzhe/blake2b
57
- post_install_message:
73
+ post_install_message:
58
74
  rdoc_options: []
59
75
  require_paths:
60
76
  - lib
@@ -70,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
86
  version: '0'
71
87
  requirements: []
72
88
  rubygems_version: 3.1.4
73
- signing_key:
89
+ signing_key:
74
90
  specification_version: 4
75
- summary: Blake2b from rust
91
+ summary: A ruby blake2b gem which using rust blake2 crate
76
92
  test_files: []