glogin 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/codecov.yml +1 -1
- data/.github/workflows/pdd.yml +1 -1
- data/.github/workflows/xcop.yml +1 -1
- data/.rubocop.yml +2 -2
- data/Gemfile +4 -4
- data/lib/glogin/codec.rb +13 -4
- data/lib/glogin/version.rb +1 -1
- data/test/glogin/test_codec.rb +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d64766709045453b457180e430e7c21e92e0d2aa83aaf5045496dd579f20ecb4
|
4
|
+
data.tar.gz: '0829be0aa00b90774dfe10c2f2a0957dac27bb516f3c5558127432dea85453fc'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6242a74d222652a65b6039c10c584e4bd32f581e279d38c86e435f40a1abaac0fcde212f8b827a826d7ebef36e80310072b6636ffe840b341ae3cf636a2499c3
|
7
|
+
data.tar.gz: af688ddc396853533c69b4377c9fe3e4dc3308d8cb9c11d8ef0113c39aa806c8f78d6b22562853aafc26ac89c89d75f0b4604fbc74b8a062c83c2afd1773f4e1
|
data/.github/workflows/pdd.yml
CHANGED
data/.github/workflows/xcop.yml
CHANGED
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
@@ -24,11 +24,11 @@
|
|
24
24
|
source 'https://rubygems.org'
|
25
25
|
gemspec
|
26
26
|
|
27
|
-
gem 'minitest', '5.
|
27
|
+
gem 'minitest', '5.19.0', require: false
|
28
28
|
gem 'rake', '13.0.6', require: false
|
29
29
|
gem 'rdoc', '6.5.0', require: false
|
30
|
-
gem 'rspec-rails', '
|
31
|
-
gem 'rubocop', '1.
|
32
|
-
gem 'rubocop-rspec', '2.
|
30
|
+
gem 'rspec-rails', '6.0.3', require: false
|
31
|
+
gem 'rubocop', '1.56.0', require: false
|
32
|
+
gem 'rubocop-rspec', '2.23.2', require: false
|
33
33
|
gem 'simplecov', '0.22.0', require: false
|
34
34
|
gem 'webmock', '3.18.1', require: false
|
data/lib/glogin/codec.rb
CHANGED
@@ -25,6 +25,7 @@ require 'securerandom'
|
|
25
25
|
require 'openssl'
|
26
26
|
require 'digest/sha1'
|
27
27
|
require 'base58'
|
28
|
+
require 'base64'
|
28
29
|
|
29
30
|
# Codec.
|
30
31
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
@@ -36,9 +37,13 @@ module GLogin
|
|
36
37
|
# When can't decode.
|
37
38
|
class DecodingError < StandardError; end
|
38
39
|
|
39
|
-
|
40
|
+
# Ctor.
|
41
|
+
# +secret+: The secret to do the encoding
|
42
|
+
# +base64+: If TRUE, Base-64 will be used, otherwise Base-58
|
43
|
+
def initialize(secret = '', base64: false)
|
40
44
|
raise 'Secret can\'t be nil' if secret.nil?
|
41
45
|
@secret = secret
|
46
|
+
@base64 = base64
|
42
47
|
end
|
43
48
|
|
44
49
|
def decrypt(text)
|
@@ -49,8 +54,12 @@ module GLogin
|
|
49
54
|
cpr = cipher
|
50
55
|
cpr.decrypt
|
51
56
|
cpr.key = digest(cpr.key_len)
|
52
|
-
|
53
|
-
|
57
|
+
if @base64
|
58
|
+
raise DecodingError, 'This is not Base64' unless %r{^[a-zA-Z0-9\\+/=]+$}.match?(text)
|
59
|
+
else
|
60
|
+
raise DecodingError, 'This is not Base58' unless /^[a-zA-Z0-9]+$/.match?(text)
|
61
|
+
end
|
62
|
+
plain = @base64 ? Base64.decode64(text) : Base58.base58_to_binary(text)
|
54
63
|
raise DecodingError if plain.empty?
|
55
64
|
decrypted = cpr.update(plain)
|
56
65
|
decrypted << cpr.final
|
@@ -75,7 +84,7 @@ module GLogin
|
|
75
84
|
salt = SecureRandom.base64(Random.rand(8..32))
|
76
85
|
encrypted = cpr.update("#{salt} #{text}")
|
77
86
|
encrypted << cpr.final
|
78
|
-
Base58.binary_to_base58(encrypted)
|
87
|
+
@base64 ? Base64.encode64(encrypted).gsub("\n", '') : Base58.binary_to_base58(encrypted)
|
79
88
|
end
|
80
89
|
end
|
81
90
|
|
data/lib/glogin/version.rb
CHANGED
data/test/glogin/test_codec.rb
CHANGED
@@ -54,6 +54,13 @@ class TestCodec < Minitest::Test
|
|
54
54
|
assert(!text.include?("\n"), text)
|
55
55
|
end
|
56
56
|
|
57
|
+
def test_encrypts_using_base64
|
58
|
+
codec = GLogin::Codec.new('6hFGrte5LLmwi', base64: true)
|
59
|
+
text = 'Hello, world!'
|
60
|
+
enc = codec.encrypt(text)
|
61
|
+
assert_equal(text, codec.decrypt(enc))
|
62
|
+
end
|
63
|
+
|
57
64
|
def test_decrypts_broken_text
|
58
65
|
assert_raises GLogin::Codec::DecodingError do
|
59
66
|
GLogin::Codec.new('the key').decrypt('этот текст не был зашифрован')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glogin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: base58
|