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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c1226d2df68de1c35ccf371af01c3e58bed8f73164eabacd6a11a4b30b2188df
4
- data.tar.gz: 9a778e23f7c452c5835d7e583a2982257f2ed9a723b312ebfb8778b59e8d5f03
3
+ metadata.gz: 24f3ea81f0ab648e1b84512a098f428bb4e4e6c65730390d62686a6d60247eb4
4
+ data.tar.gz: c540c7cbb915c8ff49f18d25d8e34b990c175331fd6052f5baa6dc4910b7b1b3
5
5
  SHA512:
6
- metadata.gz: e80a9b881dbc75a8e30f9e2379c02413aa8cda52ee8b61e28af6df4a3f0279e34a8c0e6794f203e08e4d8e868497339511cce77eac50bce2b59d5730f08e6e12
7
- data.tar.gz: eb4ce98bbd52946f7faaf6fd18ff42097b0a1d7f98f36b1df1daa5a696d0aa74b6e5da62ad55c40014bd1ac64407e62718d2db913dcb601ee2d3853dfa4731f4
6
+ metadata.gz: 5b1fde0ee3e56ef0fe0b0a57caed97e852d67a4e2aa810a701ed2eade8a2f9f97b1f1a61690c6712e9c2c70e2138714a2d13aa11fc1e3c29491924067f283aca
7
+ data.tar.gz: 9df9ec9df6a03fa09c002f5c93ebfd6a141596a1cfeea6a71e26135bcd0098df307d9cb1dd59727b8bf1dc07f09fead5ddee0805658bda822ad4c27bb7f9fec4
@@ -0,0 +1,5 @@
1
+ Metrics/LineLength:
2
+ Max: 120
3
+
4
+ Style/Documentation:
5
+ Enabled: false
data/Gemfile CHANGED
@@ -1,6 +1,8 @@
1
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
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
- require "bundler/setup"
2
- require "bundler/gem_tasks"
3
- require "helix_runtime/build_task"
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 :default => :build
10
+ task default: :build
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "bundler/setup"
4
- require "blake3"
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 "irb"
14
+ require 'irb'
14
15
  IRB.start(__FILE__)
@@ -1,36 +1,40 @@
1
+ # frozen_string_literal: true
1
2
 
2
- lib = File.expand_path("../lib", __FILE__)
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "blake3/version"
5
+ require 'blake3/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "blake3"
8
+ spec.name = 'blake3'
8
9
  spec.version = Blake3::VERSION
9
- spec.authors = ["Hajime Yamaguchi"]
10
- spec.email = ["gen.yamaguchi0@gmail.com"]
10
+ spec.authors = ['Hajime Yamaguchi']
11
+ spec.email = ['gen.yamaguchi0@gmail.com']
11
12
 
12
- spec.summary = "Blake3 for Ruby"
13
- spec.description = "Blake3 for Ruby"
14
- spec.homepage = "https://github.com/Yamaguchi/blake3rb"
15
- spec.license = "MIT"
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["homepage_uri"] = spec.homepage
18
- spec.metadata["source_code_uri"] = spec.homepage
19
- spec.metadata["changelog_uri"] = "#{spec.homepage}/CHANGELOG.md"
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 into git.
23
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
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 = "exe"
30
+ spec.bindir = 'exe'
27
31
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
- spec.require_paths = ["lib"]
32
+ spec.require_paths = ['lib']
29
33
 
30
- spec.extensions = %w(ext/extconf.rb)
31
- spec.add_development_dependency "bundler", "~> 1.17"
32
- spec.add_development_dependency "rake", "~> 10.0"
33
- spec.add_development_dependency "rspec", "~> 3.0"
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 "helix_runtime", "= 0.7.5"
39
+ spec.add_runtime_dependency 'helix_runtime', '= 0.7.5'
36
40
  end
@@ -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
@@ -1,26 +1,38 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'helix_runtime'
2
4
 
3
5
  require 'blake3native/native'
4
- require "blake3/version"
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 digest(plain)
14
- Hasher.digest(plain)
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
- @hasher = Blake3Hasher.new
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("H*")
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("H*")
53
+ [hexdigest].pack('H*')
42
54
  end
43
55
 
44
56
  def hexdigest
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Blake3
2
- VERSION = "0.1.2"
4
+ VERSION = '0.1.3'
3
5
  end
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.2
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-18 00:00:00.000000000 Z
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