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 +4 -4
- data/.gitignore +1 -0
- data/Cargo.lock +7 -0
- data/Cargo.toml +1 -0
- data/Gemfile.lock +8 -1
- data/Rakefile +9 -4
- data/blake2b.gemspec +6 -2
- data/ext/Rakefile +5 -0
- data/lib/blake2b.rb +25 -3
- data/lib/blake2b/version.rb +1 -1
- data/src/lib.rs +7 -3
- metadata +24 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1efeab05937eaf481f8b8cf29f089e87a163a7b2b7bd01700ef404c818a80992
|
4
|
+
data.tar.gz: 57bac7eb73edaf73c12ba5d1514514cb9fbfe50c5ae335155ae4163d57661e11
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b81a7f9d5d2e02a50e337c7144bd9152f747b882e602b615462675398fb84cc063d28fa63b66d01f67096db2e82edc24a8c65bff79497b77a258564cc2cb6c7
|
7
|
+
data.tar.gz: fd1402ae62998ea33ce953094ada3aabc8dc15cb44578a1648b4de0c65251199c33767b143c23b3fb924d7b50f0e04a48e663389aefcaa9449cac694f226dbb8
|
data/.gitignore
CHANGED
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
data/Gemfile.lock
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
blake2b_rs (0.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
|
2
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'thermite/tasks'
|
3
3
|
|
4
|
-
|
4
|
+
Thermite::Tasks.new
|
5
5
|
|
6
|
-
task :
|
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{
|
10
|
-
spec.description = %q{
|
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
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/
|
9
|
-
attach_function :rust_blake2b, %i[pointer int int],
|
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
|
data/lib/blake2b/version.rb
CHANGED
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) -> *
|
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)
|
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.
|
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-
|
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:
|
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:
|
91
|
+
summary: A ruby blake2b gem which using rust blake2 crate
|
76
92
|
test_files: []
|