covert 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 90aa90ca29e52c1a1310fac23fd33c1f31b369d2ae6f8356963c30f7810a6862
4
- data.tar.gz: 662422c58628c014f87fcd53e440c4d55b9b5d41a01051f4c9eb7c77b3c39e70
3
+ metadata.gz: 69d9e93d903d41b36fa34c2984440225a18c68c837abb58f79a7ecfe452a0994
4
+ data.tar.gz: 52fdf5e022870b6ab6b1c6ff6798dbbaa2882e8964387091d1fa3db3c76f5c3b
5
5
  SHA512:
6
- metadata.gz: 1284badb03b840c79449ef139fbd864a9b984cbb9d3cfcbfbd1518f1fa2833aac053ee5716b87b7566b1654ec75f2847230d31b1f0cff76787a8414c4881e7b6
7
- data.tar.gz: 1c22ecd1222ba5b07c5b252f9175dd39b722192c9c170aee69ff751fe3d60a20e88c4e4fa4c644eae8cdcda551d7720b7d7ba86cced3181294bdc840f5384f74
6
+ metadata.gz: 883171eb85fad23570d86d12580ba690d0a1c4ba04b731b337df402bb7cf9cc2f245d8bda5576d205b0f7b7af9ac847d7b58b3fc872e317e87ecfe324cfdc2aa
7
+ data.tar.gz: 3973ceab4a67822d7be4dc2b8bbbd4d44bc3d0b06df06b86f5e01720af3f6d5930ebcf8d98c747363930dcc7591973d9c30b3145bd9a0f3fa2df2402239ce4e2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- covert (0.1.0)
4
+ covert (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Covert
2
2
 
3
+ [![CircleCI](https://circleci.com/gh/merqloveu/covert.svg?style=svg)](https://circleci.com/gh/merqloveu/covert)
4
+ [![Gem Version](https://badge.fury.io/rb/covert.svg)](https://badge.fury.io/rb/covert)
5
+
3
6
  Covert makes your string securely obfuscated.
4
7
 
5
8
  ## Installation
@@ -25,6 +28,8 @@ Or install it yourself as:
25
28
  Covert.configure do |config|
26
29
  config.cipher_key = 'blah!'
27
30
  config.cipher = 'AES-256-CBC' # default
31
+ config.hmac_key = 'blah!'
32
+ config.hmac_digest = 'SHA256' # default
28
33
  end
29
34
  ```
30
35
 
@@ -38,6 +43,56 @@ Covert.obfuscate('mystring') #=> "7hSfzDwp2JXZcieFpGCndA=="
38
43
  Covert.unobfuscate('7hSfzDwp2JXZcieFpGCndA==') #=> "mystring"
39
44
  ```
40
45
 
46
+ ### Hmac
47
+ ```ruby
48
+ Covert.hmac('hmac') #=> "13ca4d5b9cdc1485834a05d926913d919d3c83de29c99314a7dbccafdc8be8ac"
49
+ ```
50
+
51
+ ## Benchmark
52
+
53
+ Comparison with gem `obfuscate` with Blowfish algo.
54
+
55
+ ```ruby
56
+ require 'obfuscate'
57
+ require 'covert'
58
+ require 'benchmark'
59
+ require 'securerandom'
60
+
61
+ Obfuscate.setup :salt => 'a very weak salt indead.'
62
+
63
+ Covert.configure do |config|
64
+ config.cipher_key = 'blah!'
65
+ end
66
+
67
+ puts Benchmark.bm { |bm|
68
+ ids = []
69
+ bm.report("obfuscate x1000:") {
70
+ 1000.times { ids << Obfuscate.obfuscate( SecureRandom.uuid, {:mode => :block} ) }
71
+ }
72
+
73
+ bm.report("clarify x1000:") {
74
+ ids.each { |id| Obfuscate.clarify( id, {:mode => :block} ) }
75
+ }
76
+
77
+ ids = []
78
+ bm.report("myobfuscate x1000:") {
79
+ 1000.times { ids << Covert.obfuscate(SecureRandom.uuid) }
80
+ }
81
+
82
+ bm.report("myclarify x1000:") {
83
+ ids.each { |id| Covert.unobfuscate(id) }
84
+ }
85
+ }
86
+ ```
87
+
88
+ ```shell
89
+ user system total real
90
+ Obfuscate.obfuscate x1000: 7.883860 0.044474 7.928334 ( 7.944916)
91
+ Obfuscate.clarify x1000: 7.841752 0.016152 7.857904 ( 7.873886)
92
+ Covert.obfuscate x1000: 0.011217 0.012656 0.023873 ( 0.024485)
93
+ Covert.unobfuscate x1000: 0.003891 0.000358 0.004249 ( 0.004359)
94
+ ```
95
+
41
96
  ## Development
42
97
 
43
98
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/lib/covert/config.rb CHANGED
@@ -5,11 +5,13 @@ module Covert
5
5
  # Covert configuration
6
6
  #
7
7
  class Config
8
- attr_accessor :cipher_key, :cipher
8
+ attr_accessor :cipher_key, :cipher, :hmac_key, :hmac_digest
9
9
 
10
10
  def initialize
11
11
  @cipher_key = nil
12
12
  @cipher = 'AES-256-CBC'
13
+ @hmac_key = nil
14
+ @hmac_digest = 'SHA256'
13
15
  end
14
16
  end
15
17
  end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Covert
4
+ class Hmac
5
+ class << self
6
+ def call(value:)
7
+ new(value).call
8
+ end
9
+ end
10
+
11
+ def initialize(value)
12
+ @value = value
13
+ end
14
+
15
+ def call
16
+ OpenSSL::HMAC.hexdigest(digest, key, value)
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :value
22
+
23
+ def key
24
+ Covert.config.hmac_key
25
+ end
26
+
27
+ def digest
28
+ Covert.config.hmac_digest
29
+ end
30
+ end
31
+ end
@@ -1,3 +1,3 @@
1
1
  module Covert
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/covert.rb CHANGED
@@ -9,6 +9,7 @@ module Covert
9
9
  class Error < StandardError; end
10
10
 
11
11
  autoload :Config, 'covert/config.rb'
12
+ autoload :Hmac, 'covert/hmac.rb'
12
13
  autoload :Obfuscation, 'covert/obfuscation.rb'
13
14
  autoload :Obfuscate, 'covert/obfuscate.rb'
14
15
  autoload :Unobfuscate, 'covert/unobfuscate.rb'
@@ -31,6 +32,14 @@ module Covert
31
32
  end
32
33
  end
33
34
 
35
+ # @param [String] str String for HMAC encoding
36
+ # @example Generate HMAC code
37
+ # Covert.hmac("mystring") #=> "cddb0db23f469c8bf072b21fd837149bd6ace9ab771cceef14c9e517cc93282e"
38
+ # @return [String] HMAC encoded string
39
+ def self.hmac(str)
40
+ Hmac.call(value: str)
41
+ end
42
+
34
43
  # @param [String] str String to obfuscate
35
44
  # @example Obfuscate a String
36
45
  # Covert.obfuscate("mystring") #=> "7hSfzDwp2JXZcieFpGCndA=="
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: covert
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Merkulov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-02-22 00:00:00.000000000 Z
11
+ date: 2022-02-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Fast & secure way to provide obfuscated ids and text.
14
14
  email:
@@ -30,6 +30,7 @@ files:
30
30
  - covert.gemspec
31
31
  - lib/covert.rb
32
32
  - lib/covert/config.rb
33
+ - lib/covert/hmac.rb
33
34
  - lib/covert/obfuscate.rb
34
35
  - lib/covert/obfuscation.rb
35
36
  - lib/covert/unobfuscate.rb