blake3 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +5 -0
- data/Gemfile +4 -2
- data/Rakefile +6 -4
- data/bin/console +4 -3
- data/blake3.gemspec +26 -22
- data/ext/extconf.rb +3 -1
- data/lib/blake3.rb +25 -13
- data/lib/blake3/version.rb +3 -1
- data/src/lib.rs +45 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24f3ea81f0ab648e1b84512a098f428bb4e4e6c65730390d62686a6d60247eb4
|
4
|
+
data.tar.gz: c540c7cbb915c8ff49f18d25d8e34b990c175331fd6052f5baa6dc4910b7b1b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b1fde0ee3e56ef0fe0b0a57caed97e852d67a4e2aa810a701ed2eade8a2f9f97b1f1a61690c6712e9c2c70e2138714a2d13aa11fc1e3c29491924067f283aca
|
7
|
+
data.tar.gz: 9df9ec9df6a03fa09c002f5c93ebfd6a141596a1cfeea6a71e26135bcd0098df307d9cb1dd59727b8bf1dc07f09fead5ddee0805658bda822ad4c27bb7f9fec4
|
data/.rubocop.yml
ADDED
data/Gemfile
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
4
6
|
|
5
7
|
# Specify your gem's dependencies in blake3.gemspec
|
6
8
|
gemspec
|
data/Rakefile
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'bundler/gem_tasks'
|
5
|
+
require 'helix_runtime/build_task'
|
4
6
|
|
5
7
|
HelixRuntime::BuildTask.new do |t|
|
6
8
|
end
|
7
9
|
|
8
|
-
task :
|
10
|
+
task default: :build
|
data/bin/console
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
-
require
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'blake3'
|
5
6
|
|
6
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
8
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +11,5 @@ require "blake3"
|
|
10
11
|
# require "pry"
|
11
12
|
# Pry.start
|
12
13
|
|
13
|
-
require
|
14
|
+
require 'irb'
|
14
15
|
IRB.start(__FILE__)
|
data/blake3.gemspec
CHANGED
@@ -1,36 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
|
-
lib = File.expand_path(
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
5
|
+
require 'blake3/version'
|
5
6
|
|
6
7
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
8
|
+
spec.name = 'blake3'
|
8
9
|
spec.version = Blake3::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
10
|
+
spec.authors = ['Hajime Yamaguchi']
|
11
|
+
spec.email = ['gen.yamaguchi0@gmail.com']
|
11
12
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
13
|
+
spec.summary = 'Blake3 for Ruby'
|
14
|
+
spec.description = 'Blake3 for Ruby'
|
15
|
+
spec.homepage = 'https://github.com/Yamaguchi/blake3rb'
|
16
|
+
spec.license = 'MIT'
|
16
17
|
|
17
|
-
spec.metadata[
|
18
|
-
spec.metadata[
|
19
|
-
spec.metadata[
|
18
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
19
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
20
|
+
spec.metadata['changelog_uri'] = "#{spec.homepage}/CHANGELOG.md"
|
20
21
|
|
21
22
|
# Specify which files should be added to the gem when it is released.
|
22
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added
|
23
|
-
|
24
|
-
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added
|
24
|
+
# into git.
|
25
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
26
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
25
29
|
end
|
26
|
-
spec.bindir =
|
30
|
+
spec.bindir = 'exe'
|
27
31
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
-
spec.require_paths = [
|
32
|
+
spec.require_paths = ['lib']
|
29
33
|
|
30
|
-
spec.extensions = %w
|
31
|
-
spec.add_development_dependency
|
32
|
-
spec.add_development_dependency
|
33
|
-
spec.add_development_dependency
|
34
|
+
spec.extensions = %w[ext/extconf.rb]
|
35
|
+
spec.add_development_dependency 'bundler', '~> 1.17'
|
36
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
37
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
34
38
|
|
35
|
-
spec.add_runtime_dependency
|
39
|
+
spec.add_runtime_dependency 'helix_runtime', '= 0.7.5'
|
36
40
|
end
|
data/ext/extconf.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
RAKEFILE = 'native.rake'
|
2
4
|
|
3
5
|
def command_exists(command, *extra_test_arguments)
|
@@ -21,4 +23,4 @@ File.open(RAKEFILE, 'w') do |rakefile|
|
|
21
23
|
require 'helix_runtime/build_task'
|
22
24
|
HelixRuntime::BuildTask.new
|
23
25
|
RUBY
|
24
|
-
end
|
26
|
+
end
|
data/lib/blake3.rb
CHANGED
@@ -1,26 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'helix_runtime'
|
2
4
|
|
3
5
|
require 'blake3native/native'
|
4
|
-
require
|
6
|
+
require 'blake3/version'
|
5
7
|
|
6
8
|
module Blake3
|
7
9
|
module_function
|
8
10
|
|
9
|
-
def hexdigest(plain)
|
10
|
-
Hasher.hexdigest(plain)
|
11
|
+
def hexdigest(plain, key: nil)
|
12
|
+
Hasher.hexdigest(plain, key: key)
|
13
|
+
end
|
14
|
+
|
15
|
+
def digest(plain, key: nil)
|
16
|
+
Hasher.digest(plain, key: key)
|
11
17
|
end
|
12
18
|
|
13
|
-
def
|
14
|
-
|
19
|
+
def derive_key(context, input_key)
|
20
|
+
hex = input_key.unpack1('H*')
|
21
|
+
Blake3Key.new.derive(context, hex)
|
15
22
|
end
|
16
23
|
|
17
24
|
class Hasher
|
18
|
-
def initialize
|
19
|
-
|
25
|
+
def initialize(key: nil)
|
26
|
+
if key
|
27
|
+
hex = key.unpack1('H*')
|
28
|
+
@hasher = Blake3KeyedHasher.new(hex)
|
29
|
+
else
|
30
|
+
@hasher = Blake3Hasher.new
|
31
|
+
end
|
20
32
|
end
|
21
33
|
|
22
34
|
def update(plain)
|
23
|
-
hex = plain.unpack1(
|
35
|
+
hex = plain.unpack1('H*')
|
24
36
|
@hasher.update(hex)
|
25
37
|
self
|
26
38
|
end
|
@@ -29,16 +41,16 @@ module Blake3
|
|
29
41
|
@hasher.finalize
|
30
42
|
end
|
31
43
|
|
32
|
-
def self.digest(plain)
|
33
|
-
new.update(plain).digest
|
44
|
+
def self.digest(plain, key: nil)
|
45
|
+
new(key: key).update(plain).digest
|
34
46
|
end
|
35
47
|
|
36
|
-
def self.hexdigest(plain)
|
37
|
-
new.update(plain).hexdigest
|
48
|
+
def self.hexdigest(plain, key: nil)
|
49
|
+
new(key: key).update(plain).hexdigest
|
38
50
|
end
|
39
51
|
|
40
52
|
def digest
|
41
|
-
[hexdigest].pack(
|
53
|
+
[hexdigest].pack('H*')
|
42
54
|
end
|
43
55
|
|
44
56
|
def hexdigest
|
data/lib/blake3/version.rb
CHANGED
data/src/lib.rs
CHANGED
@@ -23,4 +23,49 @@ ruby! {
|
|
23
23
|
format!("{}", self.hasher.finalize().to_hex())
|
24
24
|
}
|
25
25
|
}
|
26
|
+
|
27
|
+
class Blake3KeyedHasher {
|
28
|
+
struct {
|
29
|
+
hasher: blake3::Hasher,
|
30
|
+
}
|
31
|
+
|
32
|
+
def initialize(helix, key: std::string::String ) {
|
33
|
+
let mut array = [0; 32];
|
34
|
+
let vec = hex::decode(key).expect("Decoding failed");
|
35
|
+
let bytes = &vec[..array.len()];
|
36
|
+
array.copy_from_slice(bytes);
|
37
|
+
Blake3KeyedHasher {
|
38
|
+
helix,
|
39
|
+
hasher: blake3::Hasher::new_keyed(&array),
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
def update(&mut self, hex: std::string::String) {
|
44
|
+
let decoded = hex::decode(hex).expect("Decoding failed");
|
45
|
+
self.hasher.update(&decoded[..]);
|
46
|
+
}
|
47
|
+
|
48
|
+
def finalize(&mut self) -> std::string::String {
|
49
|
+
format!("{}", self.hasher.finalize().to_hex())
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
class Blake3Key {
|
54
|
+
struct {
|
55
|
+
|
56
|
+
}
|
57
|
+
|
58
|
+
def initialize(helix) {
|
59
|
+
Blake3Key {
|
60
|
+
helix,
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
def derive(&self, context: std::string::String, hex: std::string::String) -> std::string::String {
|
65
|
+
let mut output = [0; 32];
|
66
|
+
let key_material = hex::decode(hex).expect("Decoding failed");
|
67
|
+
blake3::derive_key(&context, &key_material[..], &mut output);
|
68
|
+
hex::encode(output)
|
69
|
+
}
|
70
|
+
}
|
26
71
|
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blake3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hajime Yamaguchi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01-
|
11
|
+
date: 2020-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -76,6 +76,7 @@ extra_rdoc_files: []
|
|
76
76
|
files:
|
77
77
|
- ".gitignore"
|
78
78
|
- ".rspec"
|
79
|
+
- ".rubocop.yml"
|
79
80
|
- ".travis.yml"
|
80
81
|
- CODE_OF_CONDUCT.md
|
81
82
|
- Cargo.lock
|