secret_string 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/secret_string.rb +14 -6
- data/lib/secret_string/version.rb +1 -1
- data/spec/secret_string_test/tests/secret_string_spec.rb +24 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a3f2a2c2ed72f290759aaa09d8319f2b8493ad872f2842b9b00f93db0f3023c
|
4
|
+
data.tar.gz: 1db00c50a1469d3851b8e0e90dcb56fe5a75a031a3662ffb615bb4db13fb5c77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99b41639952e0dad4f9e79c64481c80d824d70458e13943ea35ddc7db89a4fa543cc50190b6b1d8ea055977c09a78d15beb042316fbb2ed4008281825c150ab3
|
7
|
+
data.tar.gz: 82dfaf0c8dda03b3f411be18d542123c4caca4faed322cfe3034ca785788c08305c0a44860fd558e5affa680cc5cae77bb1af5f33247cc38b025a42f4655a2a7
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
# [v1.1.1](https://github.com/Muriel-Salvan/secret_string/compare/v1.1.0...v1.1.1) (2021-08-13 09:59:55)
|
2
|
+
|
3
|
+
### Patches
|
4
|
+
|
5
|
+
* [[Fix] [#2] Handle frozen strings with correct exception messages before using them](https://github.com/Muriel-Salvan/secret_string/commit/b3e21e57613a6d39feca2118d272264cb77bdb5f)
|
6
|
+
|
1
7
|
# [v1.1.0](https://github.com/Muriel-Salvan/secret_string/compare/v1.0.1...v1.1.0) (2021-07-07 10:21:42)
|
2
8
|
|
3
9
|
### Features
|
data/lib/secret_string.rb
CHANGED
@@ -12,6 +12,8 @@ class SecretString
|
|
12
12
|
# Parameters::
|
13
13
|
# * *secret* (String): The secret to erase from memory
|
14
14
|
def erase(secret)
|
15
|
+
raise 'Can\'t erase a frozen string' if secret.frozen?
|
16
|
+
|
15
17
|
secret_size = secret.bytesize
|
16
18
|
io = StringIO.new("\0" * secret_size)
|
17
19
|
io.read(secret_size, secret)
|
@@ -21,16 +23,20 @@ class SecretString
|
|
21
23
|
# Make sure the String will be erased at the end of its access.
|
22
24
|
#
|
23
25
|
# Parameters::
|
24
|
-
# * *str* (String): String to protect
|
26
|
+
# * *str* (String): String to protect, unfrozen
|
25
27
|
# * *silenced_str* (String): The protected representation of this string [default: 'XXXXX']
|
26
28
|
# * Proc: Code called with the string secured
|
27
29
|
# * Parameters::
|
28
30
|
# * *secretstring* (SecretString): The secret string
|
29
31
|
def protect(str, silenced_str: 'XXXXX')
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
32
|
+
raise 'Can\'t protect a frozen string' if str.frozen?
|
33
|
+
|
34
|
+
begin
|
35
|
+
secret_string = SecretString.new(str, silenced_str: silenced_str)
|
36
|
+
yield secret_string
|
37
|
+
ensure
|
38
|
+
secret_string.erase
|
39
|
+
end
|
34
40
|
end
|
35
41
|
|
36
42
|
end
|
@@ -38,9 +44,11 @@ class SecretString
|
|
38
44
|
# Constructor
|
39
45
|
#
|
40
46
|
# Parameters::
|
41
|
-
# * *str* (String): The original string to protect
|
47
|
+
# * *str* (String): The original string to protect, unfrozen
|
42
48
|
# * *silenced_str* (String): The silenced representation of this string [default: 'XXXXX']
|
43
49
|
def initialize(str, silenced_str: 'XXXXX')
|
50
|
+
raise 'Can\'t silence a frozen string' if str.frozen?
|
51
|
+
|
44
52
|
@str = str
|
45
53
|
# Make sure we manipulate @str without cloning or modifying it from now on.
|
46
54
|
@silenced_str = silenced_str
|
@@ -39,6 +39,14 @@ describe SecretString do
|
|
39
39
|
|
40
40
|
end
|
41
41
|
|
42
|
+
context 'with a silenced frozen string' do
|
43
|
+
|
44
|
+
it 'fails to initialize a secret string frozen' do
|
45
|
+
expect { described_class.new('MySecret'.freeze, silenced_str: 'SilencedString') }.to raise_error 'Can\'t silence a frozen string'
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
42
50
|
describe 'erase' do
|
43
51
|
|
44
52
|
it 'erases a String' do
|
@@ -47,6 +55,11 @@ describe SecretString do
|
|
47
55
|
expect(str).not_to eq 'MySecret'
|
48
56
|
end
|
49
57
|
|
58
|
+
it 'fails to erase a frozen String' do
|
59
|
+
str = 'MySecret'.freeze
|
60
|
+
expect { described_class.erase(str) }.to raise_error 'Can\'t erase a frozen string'
|
61
|
+
end
|
62
|
+
|
50
63
|
end
|
51
64
|
|
52
65
|
describe 'protect' do
|
@@ -61,6 +74,17 @@ describe SecretString do
|
|
61
74
|
expect(str.to_s).not_to eq 'MySecret'
|
62
75
|
end
|
63
76
|
|
77
|
+
it 'fails to protect a frozen String' do
|
78
|
+
str = 'MySecret'.freeze
|
79
|
+
called = false
|
80
|
+
expect do
|
81
|
+
described_class.protect(str, silenced_str: 'SilencedString') do
|
82
|
+
called = true
|
83
|
+
end
|
84
|
+
end.to raise_error 'Can\'t protect a frozen string'
|
85
|
+
expect(called).to eq false
|
86
|
+
end
|
87
|
+
|
64
88
|
end
|
65
89
|
|
66
90
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: secret_string
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Muriel Salvan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -72,9 +72,9 @@ email:
|
|
72
72
|
executables: []
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files:
|
75
|
+
- CHANGELOG.md
|
75
76
|
- README.md
|
76
77
|
- LICENSE.md
|
77
|
-
- CHANGELOG.md
|
78
78
|
files:
|
79
79
|
- CHANGELOG.md
|
80
80
|
- LICENSE.md
|