insecure_random 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +11 -4
- data/lib/insecure_random/version.rb +1 -1
- data/lib/insecure_random.rb +25 -23
- metadata +3 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a09a60eb5b61a7ea572735249dd0cf17ea60e9f00b352daef94482888e0cc22c
|
4
|
+
data.tar.gz: 2b714c8a2e666c94513d30031bf7f079391ed218acdc1da8e2d5719ca0212df1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33e0c230f00c79e49685785d0141df4c773fa40fd72d531f11c9d8b1c0ca29162fe1cf14574f0ca7e1a2999471487129876e96a3040a99daca561c834efd3fc7
|
7
|
+
data.tar.gz: dffa6a02b7b9952acc5c33a4dd1d3e215a7ea5800b87f35ca12cdecec87658aca2e17868254d151a57361cfe36d40d4bcff408b87e298a9a91806342db09f0d6
|
data/README.md
CHANGED
@@ -1,10 +1,17 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
<h1>
|
2
|
+
<picture>
|
3
|
+
<source media="(prefers-color-scheme: light)" srcset="https://github.com/user-attachments/assets/5c2a7f3b-71ec-4270-a613-9acebd783af5">
|
4
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/user-attachments/assets/8cf2884e-a505-4187-87c6-282969e32f40">
|
5
|
+
<img alt="Insecure Random" src="https://github.com/user-attachments/assets/5c2a7f3b-71ec-4270-a613-9acebd783af5" style="height:2em">
|
6
|
+
</picture>
|
7
|
+
</h1>
|
5
8
|
|
6
9
|
InsecureRandom hooks into SecureRandom to enable predictability via seeding.
|
7
10
|
|
11
|
+
[](https://github.com/laserlemon)
|
12
|
+
[](https://rubygems.org/gems/insecure_random)
|
13
|
+
[](https://github.com/laserlemon/insecure_random/actions/workflows/test.yml)
|
14
|
+
|
8
15
|
## Why?
|
9
16
|
|
10
17
|
### RSpec
|
data/lib/insecure_random.rb
CHANGED
@@ -1,17 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "securerandom"
|
4
|
-
|
5
3
|
# The InsecureRandom module is the interface for enabling and disabling the
|
6
4
|
# ability to seed SecureRandom's output. Outside of enabling or disabling this
|
7
5
|
# ability, there should be no need to call methods on the InsecureRandom module
|
8
6
|
# directly. Simply use SecureRandom as you normally would, with the confidence
|
9
7
|
# that its output is now repeatable by seeding via Kernel.srand.
|
10
8
|
module InsecureRandom
|
11
|
-
# This module is mixed into SecureRandom
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
9
|
+
# This module is mixed into SecureRandom. Because the Hook module is empty,
|
10
|
+
# mixing it in changes no behavior, but this module gives us a foothold in
|
11
|
+
# SecureRandom so that adding instance methods to Hook module adds the same
|
12
|
+
# method to SecureRandom as a singleton method.
|
15
13
|
module Hook
|
16
14
|
end
|
17
15
|
|
@@ -23,24 +21,16 @@ module InsecureRandom
|
|
23
21
|
end
|
24
22
|
end
|
25
23
|
|
26
|
-
# Calling InsecureRandom.hook! prepends the Hook module onto SecureRandom's
|
27
|
-
# singleton class, allowing InsecureRandom to (later) override specific
|
28
|
-
# singleton methods.
|
29
|
-
#
|
30
|
-
# InsecureRandom.hook! is called at the bottom of this file and only needs
|
31
|
-
# to be called once. However, there should be no harmful effects if this
|
32
|
-
# method is called repeatedly.
|
33
|
-
def self.hook!
|
34
|
-
::SecureRandom.singleton_class.prepend(Hook)
|
35
|
-
|
36
|
-
true
|
37
|
-
end
|
38
|
-
|
39
24
|
# Returns whether SecureRandom's behavior is currently repeatable by seeding.
|
40
25
|
def self.enabled?
|
41
26
|
Hook.instance_methods.any?
|
42
27
|
end
|
43
28
|
|
29
|
+
# Returns whether SecureRandom's behavior is not currently repeatable.
|
30
|
+
def self.disabled?
|
31
|
+
!enabled?
|
32
|
+
end
|
33
|
+
|
44
34
|
# Change SecureRandom's behavior to be repeatable by seeding. Enablement
|
45
35
|
# occurs globally and remains enabled until explicitly disabled. See:
|
46
36
|
# InsecureRandom.disable! below.
|
@@ -72,14 +62,25 @@ module InsecureRandom
|
|
72
62
|
end
|
73
63
|
|
74
64
|
# Enables SecureRandom's repeatable behavior for the duration of the given
|
75
|
-
# block, then reliably
|
65
|
+
# block, then reliably restores SecureRandom's original enablement.
|
76
66
|
#
|
77
67
|
# Returns the return value of the given block.
|
78
68
|
def self.enable
|
79
|
-
enable!
|
69
|
+
toggled = enable!
|
70
|
+
yield
|
71
|
+
ensure
|
72
|
+
disable! if toggled
|
73
|
+
end
|
74
|
+
|
75
|
+
# Disables SecureRandom's repeatable behavior for the duration of the given
|
76
|
+
# block, then reliably restores SecureRandom's original enablement.
|
77
|
+
#
|
78
|
+
# Returns the return value of the given block.
|
79
|
+
def self.disable
|
80
|
+
toggled = disable!
|
80
81
|
yield
|
81
82
|
ensure
|
82
|
-
|
83
|
+
enable! if toggled
|
83
84
|
end
|
84
85
|
end
|
85
86
|
|
@@ -89,4 +90,5 @@ end
|
|
89
90
|
# the InsecureRandom.enable! or InsecureRandom.enable methods. Until
|
90
91
|
# InsecureRandom is explicitly enabled, SecureRandom's behavior remains
|
91
92
|
# entirely untouched.
|
92
|
-
|
93
|
+
require "securerandom"
|
94
|
+
SecureRandom.singleton_class.prepend(InsecureRandom::Hook)
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: insecure_random
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Richert
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-07-01 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: bundler
|
@@ -60,7 +59,6 @@ metadata:
|
|
60
59
|
homepage_uri: https://github.com/laserlemon/insecure_random
|
61
60
|
rubygems_mfa_required: 'true'
|
62
61
|
source_code_uri: https://github.com/laserlemon/insecure_random
|
63
|
-
post_install_message:
|
64
62
|
rdoc_options: []
|
65
63
|
require_paths:
|
66
64
|
- lib
|
@@ -75,8 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
73
|
- !ruby/object:Gem::Version
|
76
74
|
version: '0'
|
77
75
|
requirements: []
|
78
|
-
rubygems_version: 3.
|
79
|
-
signing_key:
|
76
|
+
rubygems_version: 3.6.2
|
80
77
|
specification_version: 4
|
81
78
|
summary: Like SecureRandom, but less… secure
|
82
79
|
test_files: []
|