uncle_blake3 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -3
- data/lib/uncle_blake3/binding.rb +1 -0
- data/lib/uncle_blake3/build/loader.rb +1 -0
- data/lib/uncle_blake3/build/platform.rb +1 -0
- data/lib/uncle_blake3/digest.rb +31 -2
- data/lib/uncle_blake3/version.rb +1 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 743e230c6eeeecf88ca38acfa04bb212085d456dcded4b872d70426835cea804
|
4
|
+
data.tar.gz: b47f56a53d6ebe8a83ac09cd63e4d89ff0af61afd6969d5d31350167576b2897
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b22a753142ae17492aca3210d36a3e8f7332d848dfb4c3ed9bd629ef87eadee9be41e25f71441e6419e150ab93a9d9d2a9dec4defa4c0f48982426ddea1085a0
|
7
|
+
data.tar.gz: 9093e31501959a8e22970eac43a0857100da31eff9225eec07b23e1f253c849e34e2dfb20a18823aa99fe9dacf37dd56ac31b4dbce93b800a4bd87131ad9b5b4
|
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# UncleBlake3
|
2
2
|
|
3
|
+
[![GitHub version](https://badge.fury.io/gh/the-cave%2Funcle-blake3.svg)](https://badge.fury.io/gh/the-cave%2Funcle-blake3)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/uncle_blake3.svg)](https://badge.fury.io/rb/uncle_blake3)
|
5
|
+
|
3
6
|
## What is it?
|
4
7
|
|
5
8
|
UncleBlake3 is a Ruby binding of [Blake3](https://github.com/BLAKE3-team/BLAKE3), a fast cryptographic hash function.
|
@@ -25,9 +28,9 @@ In order to install the gem, your needs:
|
|
25
28
|
|
26
29
|
Add this line to your application's Gemfile:
|
27
30
|
|
28
|
-
|
31
|
+
~~~ruby
|
29
32
|
gem 'uncle_blake3'
|
30
|
-
|
33
|
+
~~~
|
31
34
|
|
32
35
|
And then execute:
|
33
36
|
|
@@ -35,7 +38,7 @@ And then execute:
|
|
35
38
|
|
36
39
|
## Usage Examples
|
37
40
|
|
38
|
-
~~~
|
41
|
+
~~~ruby
|
39
42
|
# basic usage
|
40
43
|
::UncleBlake3::Digest.hexdigest("\x00")
|
41
44
|
# => "2d3adedff11b61f14c886e35afa036736dcd87a74d27b5c1510225d0f592e213"
|
data/lib/uncle_blake3/binding.rb
CHANGED
data/lib/uncle_blake3/digest.rb
CHANGED
@@ -6,6 +6,13 @@ require 'objspace'
|
|
6
6
|
require_relative 'binding'
|
7
7
|
|
8
8
|
module UncleBlake3
|
9
|
+
# @example basic usage
|
10
|
+
# digest = ::UncleBlake3::Digest.new(output_length: 10)
|
11
|
+
# digest << 'some input'
|
12
|
+
# digest << 'some more input'
|
13
|
+
# digest.hexdigest
|
14
|
+
# #=> "d709fca62bbf74099e87"
|
15
|
+
# See {file:README.md README} for more usage examples
|
9
16
|
class Digest
|
10
17
|
KEY_LENGTH = Binding.key_length
|
11
18
|
DEFAULT_OUTPUT_LENGTH = Binding.default_output_length
|
@@ -21,6 +28,7 @@ module UncleBlake3
|
|
21
28
|
include Error
|
22
29
|
end
|
23
30
|
|
31
|
+
# Create a new Digest
|
24
32
|
def initialize(output_length: DEFAULT_OUTPUT_LENGTH, key: nil, key_seed: nil)
|
25
33
|
raise TypeError, 'Hash length is not an Integer' unless output_length.is_a?(::Integer)
|
26
34
|
raise ArgumentError, 'Hash length out of range' unless (1...(1 << 20)).include?(output_length)
|
@@ -49,6 +57,7 @@ module UncleBlake3
|
|
49
57
|
invalidate_cache
|
50
58
|
end
|
51
59
|
|
60
|
+
# Feed in the data
|
52
61
|
def update(data)
|
53
62
|
data_size = data.bytesize
|
54
63
|
data_buffer = ::FFI::MemoryPointer.new(:uint8, data_size)
|
@@ -59,10 +68,12 @@ module UncleBlake3
|
|
59
68
|
invalidate_cache
|
60
69
|
end
|
61
70
|
|
71
|
+
# Alias for {#update}
|
62
72
|
def <<(*args, **kwargs)
|
63
73
|
update(*args, **kwargs)
|
64
74
|
end
|
65
75
|
|
76
|
+
# Finalize and output a binary hash
|
66
77
|
def digest
|
67
78
|
@_digest_cache ||= begin
|
68
79
|
data_buffer = ::FFI::MemoryPointer.new(:uint8, @output_length)
|
@@ -71,10 +82,12 @@ module UncleBlake3
|
|
71
82
|
end
|
72
83
|
end
|
73
84
|
|
85
|
+
# Finalize and output a hexadecimal-encoded hash
|
74
86
|
def hexdigest
|
75
87
|
@_hexdigest_cache ||= digest.unpack1('H*')
|
76
88
|
end
|
77
89
|
|
90
|
+
# Finalize and output a Base64-encoded hash
|
78
91
|
def base64digest
|
79
92
|
@_base64digest_cache ||= ::Base64.strict_encode64(digest)
|
80
93
|
end
|
@@ -88,21 +101,37 @@ module UncleBlake3
|
|
88
101
|
end
|
89
102
|
|
90
103
|
class << self
|
104
|
+
# @!visibility private
|
91
105
|
# https://www.mikeperham.com/2010/02/24/the-trouble-with-ruby-finalizers/
|
92
106
|
def _create_finalizer(instance)
|
93
|
-
proc
|
107
|
+
proc do
|
94
108
|
Binding.destroy(instance)
|
95
|
-
|
109
|
+
end
|
96
110
|
end
|
97
111
|
|
112
|
+
# Shortcut to calculate a raw digest
|
113
|
+
# @example basic usage
|
114
|
+
# ::UncleBlake3::Digest.digest('some input')
|
115
|
+
# #=> "{7\x00\f\x00EZ\xBD \x9A\x9A\x02\xDDH|>({\xC6\xA1\x9DNA\xEB\x81\xC8K\x85\x9E\xBF\x87;"
|
116
|
+
# @example with key derived from seed
|
117
|
+
# ::UncleBlake3::Digest.digest('some input', key_seed: 'secret')
|
118
|
+
# #=> "\xA7d\x13c)e\e`>\x9D\e\xB0\x9E\xF9\xA6\x82F:\xA8w;\xB0!\xBC*l\xF3w\x83\x85\xCA\x1E"
|
119
|
+
# @example with raw key (fixed-length key)
|
120
|
+
# ::UncleBlake3::Digest.digest('some input', key: '0123456789abcdef0123456789abcdef')
|
121
|
+
# #=> "8Z\x89+\x1A}\x0E\xBBI\xD4)\xC5\x9A\x8A\x17\x13[\xB7\x1DO\x98\xE8\xEF\x06\xD58\x83c\xC3u\x13\xE1"
|
122
|
+
# @example controlled output length
|
123
|
+
# ::UncleBlake3::Digest.digest('some input', output_length: 5)
|
124
|
+
# #=> "{7\x00\f\x00"
|
98
125
|
def digest(*args, **kwargs)
|
99
126
|
_generic_digest(*args, **kwargs, &:digest)
|
100
127
|
end
|
101
128
|
|
129
|
+
# Same as {.digest} but encode the output in hexadecimal format
|
102
130
|
def hexdigest(*args, **kwargs)
|
103
131
|
_generic_digest(*args, **kwargs, &:hexdigest)
|
104
132
|
end
|
105
133
|
|
134
|
+
# Same as {.digest} but encode the output in Base64 format
|
106
135
|
def base64digest(*args, **kwargs)
|
107
136
|
_generic_digest(*args, **kwargs, &:base64digest)
|
108
137
|
end
|
data/lib/uncle_blake3/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uncle_blake3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sarun Rattanasiri
|
@@ -38,9 +38,10 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 13.0.0
|
41
|
-
description:
|
42
|
-
Blake3
|
43
|
-
themselves.
|
41
|
+
description: |-
|
42
|
+
Blake3 binding for Ruby
|
43
|
+
The gem build on top of the official Blake3 implementation maintained by the team behind Blake3 themselves.
|
44
|
+
It supports `AVX512`, `AVX2`, `SSE4.1`, and `SSE2` acceleration with thin and stable binding.
|
44
45
|
email: midnight_w@gmx.tw
|
45
46
|
executables: []
|
46
47
|
extensions:
|
@@ -90,8 +91,8 @@ licenses:
|
|
90
91
|
- BSD-3-Clause
|
91
92
|
metadata:
|
92
93
|
homepage_uri: https://github.com/the-cave/uncle-blake3
|
93
|
-
source_code_uri: https://github.com/the-cave/uncle-blake3/tree/v0.0.
|
94
|
-
documentation_uri: https://rubydoc.info/gems/uncle_blake3/0.0.
|
94
|
+
source_code_uri: https://github.com/the-cave/uncle-blake3/tree/v0.0.3
|
95
|
+
documentation_uri: https://rubydoc.info/gems/uncle_blake3/0.0.3
|
95
96
|
bug_tracker_uri: https://github.com/the-cave/uncle-blake3/issues
|
96
97
|
post_install_message:
|
97
98
|
rdoc_options: []
|
@@ -111,5 +112,5 @@ requirements: []
|
|
111
112
|
rubygems_version: 3.2.32
|
112
113
|
signing_key:
|
113
114
|
specification_version: 4
|
114
|
-
summary:
|
115
|
+
summary: Blake3, the hash algorithm, native binding for Ruby
|
115
116
|
test_files: []
|