sleeping_kangaroo12 0.0.4 → 0.0.5

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: 6b89369bac3beb3d85045ea6f94f2c0d995d4e72e04a1887f83818b308e4bae7
4
- data.tar.gz: 464479f5b0d85d7d6c5453e208fc287b5637f1fcc99769101aeee75e9dd2ec58
3
+ metadata.gz: 7453def4dc8a8e3a1c2969eae931609fea5407fdba11a56e8e14fd5a09325b5f
4
+ data.tar.gz: ad708b12872beef715a367ba32ecefb0c869fb969a88df41a15fc3cac7379f43
5
5
  SHA512:
6
- metadata.gz: 7514b62f2f38a373d055f71dd6acce85ab37554403bc3fb294e2b516e768133120134469d29d81b69be36f6804dd002439ce49e9208bf6831d7e99d359bee21a
7
- data.tar.gz: 4a5dea0068e28db9180e65c3469863f9c6ada04948866999efe788c1ef941d7eebfdb6d1a18a816175b6dbd85d653d8f83bdd6613514c70e3c907245ee75911e
6
+ metadata.gz: 1ec13969d3b64f83c29a4b2b7653cc080f442b0818f9e5f818fd2c8ca139b658f9692832f9d9a046320cf16d5988240c06bddc5fd3de3ce0faa920b1af0abb56
7
+ data.tar.gz: 748c612b41ff1460dad89f1e122b466cb052089d95eb552557c6f0ef229ce74ad5d214e9f5d371464dc93aaa65db412af284dafbb83eb62d5bccab413943f84b
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # SleepingKangaroo12
2
2
 
3
+ [![GitHub version](https://badge.fury.io/gh/the-cave%2Fsleeping-kangaroo12.svg)](https://badge.fury.io/gh/the-cave%2Fsleeping-kangaroo12)
4
+ [![Gem Version](https://badge.fury.io/rb/sleeping_kangaroo12.svg)](https://badge.fury.io/rb/sleeping_kangaroo12)
5
+
3
6
  ## What is it?
4
7
 
5
8
  SleepingKangaroo12 is a Ruby binding of [KangarooTwelve](https://keccak.team/kangarootwelve.html), a fast cryptographic
@@ -3,6 +3,7 @@
3
3
  require_relative 'build/loader'
4
4
 
5
5
  module SleepingKangaroo12
6
+ # @!visibility private
6
7
  module Binding
7
8
  extend ::FFI::Library
8
9
  ffi_lib Build::Loader.find('SleepingKangaroo12')
@@ -5,6 +5,7 @@ require 'pathname'
5
5
  require_relative 'platform'
6
6
 
7
7
  module SleepingKangaroo12
8
+ # @!visibility private
8
9
  module Build
9
10
  # taken from:
10
11
  # https://github.com/ffi/ffi-compiler/blob/master/lib/ffi-compiler/loader.rb
@@ -4,6 +4,7 @@ require 'ffi'
4
4
  require 'singleton'
5
5
 
6
6
  module SleepingKangaroo12
7
+ # @!visibility private
7
8
  module Build
8
9
  # mostly taken from:
9
10
  # https://github.com/ffi/ffi-compiler/blob/master/lib/ffi-compiler/platform.rb
@@ -6,16 +6,30 @@ require 'objspace'
6
6
  require_relative 'binding'
7
7
 
8
8
  module SleepingKangaroo12
9
+ # @example basic usage
10
+ # digest = ::SleepingKangaroo12::Digest.new(output_length: 10)
11
+ # digest << 'some input'
12
+ # digest << 'some more input'
13
+ # digest.hexdigest
14
+ # #=> "cbea8144fbbf6150ceaf"
15
+ # See {file:README.md README} for more usage examples
9
16
  class Digest
17
+ module Error
18
+ end
19
+
10
20
  class UpdatingFailed < ::StandardError
21
+ include Error
11
22
  end
12
23
 
13
24
  class FinalizationFailed < ::StandardError
25
+ include Error
14
26
  end
15
27
 
16
28
  class Finalized < ::StandardError
29
+ include Error
17
30
  end
18
31
 
32
+ # Create a new Digest
19
33
  def initialize(output_length: 32, key: nil)
20
34
  raise ::TypeError, 'Hash length is not an Integer' unless output_length.is_a?(::Integer)
21
35
  raise ::ArgumentError, 'Hash length out of range' unless (1...(1 << 20)).include?(output_length)
@@ -31,6 +45,7 @@ module SleepingKangaroo12
31
45
  @result = nil
32
46
  end
33
47
 
48
+ # Feed in the data
34
49
  def update(data)
35
50
  raise Finalized if @finalized
36
51
  data_size = data.bytesize
@@ -42,10 +57,12 @@ module SleepingKangaroo12
42
57
  self
43
58
  end
44
59
 
60
+ # Alias for {#update}
45
61
  def <<(*args, **kwargs)
46
62
  update(*args, **kwargs)
47
63
  end
48
64
 
65
+ # Finalize and output a binary hash
49
66
  def digest
50
67
  @finalized = true
51
68
  return @_digest if @_digest
@@ -65,30 +82,45 @@ module SleepingKangaroo12
65
82
  @_digest = data_buffer.get_bytes(0, @output_length)
66
83
  end
67
84
 
85
+ # Finalize and output a hexadecimal-encoded hash
68
86
  def hexdigest
69
87
  @_hexdigest ||= digest.unpack1('H*')
70
88
  end
71
89
 
90
+ # Finalize and output a Base64-encoded hash
72
91
  def base64digest
73
92
  @_base64digest ||= ::Base64.strict_encode64(digest)
74
93
  end
75
94
 
76
95
  class << self
96
+ # @!visibility private
77
97
  # https://www.mikeperham.com/2010/02/24/the-trouble-with-ruby-finalizers/
78
98
  def _create_finalizer(instance)
79
- proc {
99
+ proc do
80
100
  Binding.destroy(instance)
81
- }
101
+ end
82
102
  end
83
103
 
104
+ # Shortcut to calculate a raw digest
105
+ # @example basic usage
106
+ # ::SleepingKangaroo12::Digest.digest('some input')
107
+ # #=> "m\x9FJ\xDA\xE9\x96\xD1X\xC5K\xE83e(x\x8C\xD3o\xFBh\xB2\x17W ,\xD5\xED!\xE4D\xAF\xDD"
108
+ # @example with key (AKA: customization)
109
+ # ::SleepingKangaroo12::Digest.digest('some input', key: 'secret')
110
+ # #=> "\x96\xE2K\xC4\xCF\xFFGF\xE1\x05\xB9\xF6f\xF0-\xF8\x1F\a\n\xFC\xD7\xC9\x91\n\xFC\xFB\xA6hOx\x99<"
111
+ # @example controlled output length
112
+ # ::SleepingKangaroo12::Digest.digest('some input', output_length: 5)
113
+ # #=> "m\x9FJ\xDA\xE9"
84
114
  def digest(*args, **kwargs)
85
115
  _generic_digest(*args, **kwargs, &:digest)
86
116
  end
87
117
 
118
+ # Same as {.digest} but encode the output in hexadecimal format
88
119
  def hexdigest(*args, **kwargs)
89
120
  _generic_digest(*args, **kwargs, &:hexdigest)
90
121
  end
91
122
 
123
+ # Same as {.digest} but encode the output in Base64 format
92
124
  def base64digest(*args, **kwargs)
93
125
  _generic_digest(*args, **kwargs, &:base64digest)
94
126
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SleepingKangaroo12
4
- VERSION = '0.0.4'
4
+ VERSION = '0.0.5'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sleeping_kangaroo12
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sarun Rattanasiri
@@ -16,46 +16,46 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.15.5
19
+ version: 1.15.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.15.5
26
+ version: 1.15.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: posix-spawn
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.3.15
33
+ version: 0.3.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.3.15
40
+ version: 0.3.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 13.0.6
47
+ version: 13.0.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 13.0.6
55
- description: This gem brought the hash algorithm, KangarooTwelve, to Ruby. It uses
56
- the official library, K12, maintained by the Keccak team themselves. The implementation
57
- is highly optimized on popular hardware, including AVX512, AVX2, SSSE3 instruction
58
- sets.
54
+ version: 13.0.0
55
+ description: |-
56
+ KangarooTwelve binding for Ruby
57
+ The gem build on top of the official library, K12, maintained by the Keccak team themselves.
58
+ The implementation is highly optimized and supporting AVX512, AVX2, SSSE3 instruction sets.
59
59
  email: midnight_w@gmx.tw
60
60
  executables: []
61
61
  extensions:
@@ -107,7 +107,9 @@ licenses:
107
107
  - BSD-3-Clause
108
108
  metadata:
109
109
  homepage_uri: https://github.com/the-cave/sleeping-kangaroo12
110
- source_code_uri: https://github.com/the-cave/sleeping-kangaroo12/tree/v0.0.4
110
+ source_code_uri: https://github.com/the-cave/sleeping-kangaroo12/tree/v0.0.5
111
+ documentation_uri: https://rubydoc.info/gems/sleeping_kangaroo12/0.0.5
112
+ bug_tracker_uri: https://github.com/the-cave/sleeping-kangaroo12/issues
111
113
  post_install_message:
112
114
  rdoc_options: []
113
115
  require_paths:
@@ -126,5 +128,5 @@ requirements: []
126
128
  rubygems_version: 3.2.32
127
129
  signing_key:
128
130
  specification_version: 4
129
- summary: A binding of the KangarooTwelve hash algorithm for Ruby
131
+ summary: KangarooTwelve, the hash algorithm, native binding for Ruby
130
132
  test_files: []