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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 47dc331e9d98417c38d66ddbeae5b6424284ede02d5a9e1680bc1c3eba6dd3f2
4
- data.tar.gz: abaa0b7082a1b641a21b1c5828e8ff775cefe0bd78bae72f01d8a5592098ea00
3
+ metadata.gz: d64766709045453b457180e430e7c21e92e0d2aa83aaf5045496dd579f20ecb4
4
+ data.tar.gz: '0829be0aa00b90774dfe10c2f2a0957dac27bb516f3c5558127432dea85453fc'
5
5
  SHA512:
6
- metadata.gz: 9212904c0f496ae545e401e995bc4d1e47e23c9c0d6644fda205a2cad7e46160244417455a3333501c8e542a2707985aea87319dd3fe7982b4b72a2e2d30fb9b
7
- data.tar.gz: e093b8ef78894ac6350d8b36f5cacd4251c04957a85b8742d0bd4c7170ff064f77da087172590c5f8715dbb6ba04efd887fa8f4c0821d8c7690d01f280f9a90c
6
+ metadata.gz: 6242a74d222652a65b6039c10c584e4bd32f581e279d38c86e435f40a1abaac0fcde212f8b827a826d7ebef36e80310072b6636ffe840b341ae3cf636a2499c3
7
+ data.tar.gz: af688ddc396853533c69b4377c9fe3e4dc3308d8cb9c11d8ef0113c39aa806c8f78d6b22562853aafc26ac89c89d75f0b4604fbc74b8a062c83c2afd1773f4e1
@@ -6,7 +6,7 @@ on:
6
6
  - master
7
7
  jobs:
8
8
  codecov:
9
- runs-on: ubuntu-20.04
9
+ runs-on: ubuntu-22.04
10
10
  steps:
11
11
  - uses: actions/checkout@v3
12
12
  - uses: ruby/setup-ruby@v1
@@ -5,7 +5,7 @@ on:
5
5
  pull_request:
6
6
  jobs:
7
7
  pdd:
8
- runs-on: ubuntu-20.04
8
+ runs-on: ubuntu-22.04
9
9
  steps:
10
10
  - uses: actions/checkout@v3
11
11
  - uses: g4s8/pdd-action@master
@@ -5,7 +5,7 @@ on:
5
5
  pull_request:
6
6
  jobs:
7
7
  xcop:
8
- runs-on: ubuntu-20.04
8
+ runs-on: ubuntu-22.04
9
9
  steps:
10
10
  - uses: actions/checkout@v3
11
11
  - uses: g4s8/xcop-action@master
data/.rubocop.yml CHANGED
@@ -20,8 +20,8 @@ Metrics/AbcSize:
20
20
  Metrics/BlockLength:
21
21
  Max: 30
22
22
  Metrics/CyclomaticComplexity:
23
- Max: 10
23
+ Max: 20
24
24
  Metrics/PerceivedComplexity:
25
- Max: 10
25
+ Max: 20
26
26
  Layout/EmptyLineAfterGuardClause:
27
27
  Enabled: false
data/Gemfile CHANGED
@@ -24,11 +24,11 @@
24
24
  source 'https://rubygems.org'
25
25
  gemspec
26
26
 
27
- gem 'minitest', '5.18.0', require: false
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', '5.1.2', require: false
31
- gem 'rubocop', '1.51.0', require: false
32
- gem 'rubocop-rspec', '2.22.0', require: false
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
- def initialize(secret = '')
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
- raise DecodingError unless /^[a-zA-Z0-9]+$/.match?(text)
53
- plain = Base58.base58_to_binary(text)
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
 
@@ -26,5 +26,5 @@
26
26
  # Copyright:: Copyright (c) 2017-2023 Yegor Bugayenko
27
27
  # License:: MIT
28
28
  module GLogin
29
- VERSION = '0.11.0'
29
+ VERSION = '0.12.0'
30
30
  end
@@ -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.11.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-05-23 00:00:00.000000000 Z
11
+ date: 2023-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base58