sym 3.0.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/exe/keychain CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- lib_path = File.expand_path(File.dirname(__FILE__) + '/../lib')
3
+ lib_path = File.expand_path("#{File.dirname(__FILE__)}/../lib")
4
4
  $LOAD_PATH << lib_path if File.exist?(lib_path) && !$LOAD_PATH.include?(lib_path)
5
5
 
6
6
  require 'sym'
@@ -9,7 +9,7 @@ require 'sym/app/keychain'
9
9
  require 'colored2'
10
10
 
11
11
  def usage
12
- puts 'Usage: ' + 'keychain'.bold.blue + ' name [ add <contents> | find | delete ]'.bold.green
12
+ puts "Usage: #{'keychain'.bold.blue}#{' name [ add <contents> | find | delete ]'.bold.green}"
13
13
  exit 0
14
14
  end
15
15
 
data/exe/sym CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  require_relative '../lib/ruby_warnings'
5
5
 
6
- lib_path = File.expand_path(File.dirname(__FILE__) + '/../lib')
6
+ lib_path = File.expand_path("#{File.dirname(__FILE__)}/../lib")
7
7
  $LOAD_PATH << lib_path if File.exist?(lib_path) && !$LOAD_PATH.include?(lib_path)
8
8
 
9
9
  require 'sym'
@@ -13,9 +13,9 @@ require 'sym/app'
13
13
  begin
14
14
  exit ::Sym::App::CLI.new(ARGV.dup).execute
15
15
  rescue Interrupt => e
16
- STDERR.flush
16
+ $stderr.flush
17
17
  warn "Interrupt, #{e.message}, exiting."
18
- STDERR.flush
18
+ $stderr.flush
19
19
  exit 1
20
20
  end
21
21
 
data/lib/sym/app.rb CHANGED
@@ -16,15 +16,14 @@ module Sym
16
16
  #
17
17
  module App
18
18
  class << self
19
- attr_accessor :exit_code
20
- attr_accessor :stdin, :stdout, :stderr
19
+ attr_accessor :exit_code, :stdin, :stdout, :stderr
21
20
  end
22
21
 
23
22
  self.exit_code = 0
24
23
 
25
- self.stdin = STDIN
26
- self.stdout = STDOUT
27
- self.stderr = STDERR
24
+ self.stdin = $stdin
25
+ self.stdout = $stdout
26
+ self.stderr = $stderr
28
27
 
29
28
  def self.out
30
29
  self.stderr
@@ -44,7 +43,7 @@ module Sym
44
43
 
45
44
  lines = []
46
45
 
47
- error_type = "#{(type || exception.class.name)}"
46
+ error_type = "#{type || exception.class.name}"
48
47
  error_details = (details || exception.message)
49
48
 
50
49
  operation = command ? "to #{command.class.short_name.to_s.humanize.downcase}" : ''
@@ -55,7 +54,7 @@ module Sym
55
54
  lines << exception.backtrace.join("\n").red.bold if config[:trace]
56
55
  lines << "\n"
57
56
  else
58
- lines << " ✖ Sym Error #{operation}:".bold.red + (reason ? " #{reason} ".red.italic: " #{error_details}")[0..70] + ' '.normal + "\n"
57
+ lines << "#{" ✖ Sym Error #{operation}:".bold.red}#{(reason ? " #{reason} ".red.italic: " #{error_details}")[0..70]}#{' '.normal}\n"
59
58
  lines << "#{comments}" if comments
60
59
  end
61
60
 
data/lib/sym/app/cli.rb CHANGED
@@ -58,7 +58,7 @@ module Sym
58
58
 
59
59
  attr_accessor :opts, :application, :outputs, :stdin, :stdout, :stderr, :kernel, :args
60
60
 
61
- def initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = nil)
61
+ def initialize(argv, stdin = $stdin, stdout = $stdout, stderr = $stderr, kernel = nil)
62
62
  self.args = argv
63
63
  self.stdin = stdin
64
64
  self.stdout = stdout
@@ -79,15 +79,13 @@ module Sym
79
79
  end
80
80
 
81
81
  # Deal with SYM_ARGS and -A
82
- if opts[:sym_args]
83
- if non_empty_array?(sym_args)
82
+ if opts[:sym_args] && non_empty_array?(sym_args)
84
83
  args << sym_args
85
84
  args.flatten!
86
85
  args.compact!
87
86
  args.delete('-A')
88
87
  args.delete('--sym-args')
89
88
  self.opts = parse(args)
90
- end
91
89
  end
92
90
 
93
91
  # Disable coloring if requested, or if piping STDOUT
@@ -99,7 +97,7 @@ module Sym
99
97
  rescue StandardError => e
100
98
  log :error, "#{e.message}" if opts
101
99
  error exception: e
102
- quit!(127) if stdin == STDIN
100
+ quit!(127) if stdin == $stdin
103
101
  end
104
102
 
105
103
  self.application = ::Sym::Application.new(self.opts, stdin, stdout, stderr, kernel)
@@ -19,7 +19,7 @@ module Sym
19
19
  o.separator ' 5) use -i to paste/type the key interactively'.dark
20
20
  o.separator ' 6) default key file (if present) at '.dark + Sym.default_key_file.magenta.bold
21
21
  o.separator ' '
22
- o.separator ' ' + key_spec + ' = -k/--key [ key | file | keychain | env variable name ]'.green.bold
22
+ o.separator " #{key_spec}#{' = -k/--key [ key | file | keychain | env variable name ]'.green.bold}"
23
23
  o.separator ' -i/--interactive'.green.bold
24
24
  o.separator ''
25
25
  o.separator ' Encrypt/Decrypt from STDIN/file/args, to STDOUT/file:'.dark
@@ -48,7 +48,7 @@ module Sym
48
48
  o.separator 'Modes:'.yellow
49
49
  o.bool '-e', '--encrypt', ' encrypt mode'
50
50
  o.bool '-d', '--decrypt', ' decrypt mode'
51
- o.string '-t', '--edit', '[file] '.blue + ' edit encrypted file in an $EDITOR', default: nil
51
+ o.string '-t', '--edit', "#{'[file] '.blue} edit encrypted file in an $EDITOR", default: nil
52
52
  o.string '-n', '--negate', '[file] '.blue + " encrypts any regular #{'file'.green} into #{'file.enc'.green}" + "\n" +
53
53
  " conversely decrypts #{'file.enc'.green} into #{'file'.green}."
54
54
  o.separator ' '
@@ -57,25 +57,25 @@ module Sym
57
57
  o.bool '-p', '--password', ' encrypt the key with a password'
58
58
 
59
59
  if Sym::App.osx?
60
- o.string '-x', '--keychain', '[key-name] '.blue + 'write the key to OS-X Keychain'
60
+ o.string '-x', '--keychain', "#{'[key-name] '.blue}write the key to OS-X Keychain"
61
61
  end
62
62
 
63
63
  o.separator ' '
64
64
  o.separator 'Read existing private key from:'.yellow
65
- o.string '-k', '--key', '[key-spec]'.blue + ' private key, key file, or keychain'
65
+ o.string '-k', '--key', "#{'[key-spec]'.blue} private key, key file, or keychain"
66
66
  o.bool '-i', '--interactive', ' Paste or type the key interactively'
67
67
 
68
68
  o.separator ' '
69
69
  o.separator 'Password Cache:'.yellow
70
70
  o.bool '-c', '--cache-passwords', ' enable password cache'
71
- o.integer '-z', '--cache-timeout', '[seconds]'.blue + ' expire passwords after'
71
+ o.integer '-z', '--cache-timeout', "#{'[seconds]'.blue} expire passwords after"
72
72
  o.string '-r', '--cache-provider', '[provider]'.blue + ' cache provider, one of ' + "#{Sym::App::Password::Providers.provider_list}"
73
73
 
74
74
  o.separator ' '
75
75
  o.separator 'Data to Encrypt/Decrypt:'.yellow
76
- o.string '-s', '--string', '[string]'.blue + ' specify a string to encrypt/decrypt'
77
- o.string '-f', '--file', '[file] '.blue + ' filename to read from'
78
- o.string '-o', '--output', '[file] '.blue + ' filename to write to'
76
+ o.string '-s', '--string', "#{'[string]'.blue} specify a string to encrypt/decrypt"
77
+ o.string '-f', '--file', "#{'[file] '.blue} filename to read from"
78
+ o.string '-o', '--output', "#{'[file] '.blue} filename to write to"
79
79
 
80
80
  o.separator ' '
81
81
  o.separator 'Flags:'.yellow
@@ -95,8 +95,7 @@ module Sym
95
95
  " user home available, you may need to force set user's home to any existing\n" +
96
96
  " directory using the #{'--user-home'.bold.blue} flag.\n"
97
97
 
98
- o.string '-B', '--bash-support', '[file]'.blue + ' append bash completion & utils to a file'+ "\n" +
99
- ' such as ~/.bash_profile or ~/.bashrc'
98
+ o.string '-B', '--bash-support', "#{'[file]'.blue} append bash completion & utils to a file\n such as ~/.bash_profile or ~/.bashrc"
100
99
  o.string '-u', '--user-home', '[DIR]'.blue + " Overrides #{'${HOME}'.green} ==> supports AWS Lambda\n"
101
100
 
102
101
  o.separator ' '
@@ -50,6 +50,7 @@ module Sym
50
50
  extend Forwardable
51
51
 
52
52
  attr_accessor :application
53
+
53
54
  def_delegators :@application, :opts, :opts_slop, :key, :stdin, :stdout, :stderr, :kernel
54
55
 
55
56
  def initialize(application)
@@ -50,7 +50,7 @@ module Sym
50
50
 
51
51
  def append_completion_script(file, script)
52
52
  File.open(file, 'a') do |fd|
53
- fd.write(script + "\n")
53
+ fd.write("#{script}\n")
54
54
  end
55
55
  end
56
56
 
@@ -13,7 +13,7 @@ module Sym
13
13
 
14
14
  def execute
15
15
  if Sym.default_key? && Sym.default_key == self.key
16
- raise 'Refusing to import key specified in the default key file ' + Sym.default_key_file.italic
16
+ raise "Refusing to import key specified in the default key file #{Sym.default_key_file.italic}"
17
17
  end
18
18
  raise Sym::Errors::NoPrivateKeyFound.new("Unable to resolve private key from argument '#{opts[:key]}'") if self.key.nil?
19
19
  add_to_keychain_if_needed(self.key)
@@ -16,12 +16,12 @@ module Sym
16
16
  result: '75ngenJpB6zL47/8Wo7Ne6JN1pnOsqNEcIqblItpfg4='.green)
17
17
 
18
18
  output << example(comment: 'generate a new key with a cached password & save to the default key file',
19
- command: 'sym -gcpqo ' + Sym.default_key_file,
20
- echo: 'New Password : ' + '••••••••••'.green,
21
- result: 'Confirm Password : ' + '••••••••••'.green)
19
+ command: "sym -gcpqo #{Sym.default_key_file}",
20
+ echo: "New Password : #{'••••••••••'.green}",
21
+ result: "Confirm Password : #{'••••••••••'.green}")
22
22
 
23
23
  output << example(comment: 'encrypt a plain text string with default key file, and immediately decrypt it',
24
- command: 'sym -es ' + '"secret string"'.bold.yellow + ' | sym -d',
24
+ command: "sym -es #{'"secret string"'.bold.yellow} | sym -d",
25
25
  result: 'secret string'.green)
26
26
 
27
27
  output << example(comment: 'encrypt secrets file using key in the environment, and --negate option:',
@@ -35,7 +35,7 @@ module Sym
35
35
  result: 'secret string'.green)
36
36
 
37
37
  output << example(comment: 'encrypt/decrypt sym.yml using the default key file',
38
- command: 'sym -gcq > ' + Sym.default_key_file,
38
+ command: "sym -gcq > #{Sym.default_key_file}",
39
39
  echo: 'sym -n secrets.yml',
40
40
  result: 'sym -df secrets.yml.enc',
41
41
  )
@@ -6,7 +6,7 @@ module Sym
6
6
  class Handler
7
7
  attr_accessor :stdin, :stdout, :stderr, :kernel
8
8
 
9
- def initialize(stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = nil)
9
+ def initialize(stdin = $stdin, stdout = $stdout, stderr = $stderr, kernel = nil)
10
10
  self.stdin = stdin
11
11
  self.stdout = stdout
12
12
  self.stderr = stderr
@@ -27,7 +27,7 @@ module Sym
27
27
  end
28
28
 
29
29
  def prompt(message, color)
30
- unless STDIN.isatty && STDIN.tty?
30
+ unless $stdin.isatty && $stdin.tty?
31
31
  raise Sym::Errors::CantReadPasswordNoTTY.new('key requires a password, however STDIN is not a TTY')
32
32
  end
33
33
  highline(message, color)
@@ -6,7 +6,7 @@ module Sym
6
6
 
7
7
  attr_accessor :opts, :stdin, :stdout, :stderr, :kernel
8
8
 
9
- def initialize(opts, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = nil)
9
+ def initialize(opts, stdin = $stdin, stdout = $stdout, stderr = $stderr, kernel = nil)
10
10
  self.opts = opts
11
11
  self.stdin = stdin
12
12
  self.stdout = stdout
@@ -4,9 +4,7 @@ module Sym
4
4
  module Providers
5
5
 
6
6
  class << self
7
- attr_accessor :registry
8
- attr_accessor :providers
9
- attr_accessor :detected
7
+ attr_accessor :registry, :providers, :detected
10
8
 
11
9
  def register(provider_class)
12
10
  self.registry ||= {}
@@ -16,9 +16,8 @@ module Sym
16
16
  attr_accessor :name, :reducted, :input, :output
17
17
 
18
18
  def initialize(name:,
19
- reducted: false,
20
- input: ->(detector) { detector.opts[:key] },
21
- output:)
19
+ output:, reducted: false,
20
+ input: ->(detector) { detector.opts[:key] })
22
21
 
23
22
  self.name = name
24
23
  self.reducted = reducted
@@ -31,7 +31,7 @@ module Sym
31
31
  :password_cache,
32
32
  :stdin, :stdout, :stderr, :kernel
33
33
 
34
- def initialize(opts, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = nil)
34
+ def initialize(opts, stdin = $stdin, stdout = $stdout, stderr = $stderr, kernel = nil)
35
35
  self.stdin = stdin
36
36
  self.stdout = stdout
37
37
  self.stderr = stderr
@@ -224,9 +224,9 @@ module Sym
224
224
  detect_key_source
225
225
  if args.require_key? && !self.key
226
226
  log :error, 'Unable to determine the key, which appears to be required with current args'
227
- raise Sym::Errors::NoPrivateKeyFound, 'Private key is required when ' + (self.action ? self.action.to_s + 'ypting' : provided_flags.join(', '))
227
+ raise Sym::Errors::NoPrivateKeyFound, "Private key is required when #{self.action ? "#{self.action.to_s}ypting" : provided_flags.join(', ')}"
228
228
  end
229
- log :debug, "initialize_key_source: detected key ends with [...#{(key ? key[-5..-1] : 'nil').bold.magenta}]"
229
+ log :debug, "initialize_key_source: detected key ends with [...#{(key ? key[-5..] : 'nil').bold.magenta}]"
230
230
  log :debug, "opts: #{self.provided_value_options.to_s.green.bold}"
231
231
  log :debug, "flags: #{self.provided_flags.to_s.green.bold}"
232
232
  end
@@ -35,10 +35,6 @@ module Sym
35
35
 
36
36
  # See file +lib/sym.rb+ where these values are defined.
37
37
 
38
- attr_accessor :data_cipher, :password_cipher, :private_key_cipher
39
- attr_accessor :compression_enabled, :compression_level
40
- attr_accessor :password_cache_default_provider, :password_cache_timeout
41
- attr_accessor :password_cache_arguments
42
- attr_accessor :default_key_file, :encrypted_file_extension
38
+ attr_accessor :data_cipher, :password_cipher, :private_key_cipher, :compression_enabled, :compression_level, :password_cache_default_provider, :password_cache_timeout, :password_cache_arguments, :default_key_file, :encrypted_file_extension
43
39
  end
44
40
  end
data/lib/sym/constants.rb CHANGED
@@ -53,7 +53,7 @@ module Sym
53
53
 
54
54
  module Log
55
55
  NIL = Logger.new(nil).freeze # empty logger
56
- LOG = Logger.new(STDERR).freeze
56
+ LOG = Logger.new($stderr).freeze
57
57
  end
58
58
  end
59
59
  end
data/lib/sym/data.rb CHANGED
@@ -11,11 +11,11 @@ module Sym
11
11
  # the result of `Marshal.dump(data)` using Zlib, and then doing `#urlsafe_encode64` encoding
12
12
  # to convert it to a string,
13
13
  module Data
14
- def encode(data, compress = true)
14
+ def encode(data, compress: true)
15
15
  Encoder.new(data, compress).data_encoded
16
16
  end
17
17
 
18
- def decode(data_encoded, compress = nil)
18
+ def decode(data_encoded, compress: nil)
19
19
  Decoder.new(data_encoded, compress).data
20
20
  end
21
21
  end
@@ -72,7 +72,7 @@ module Sym
72
72
  key_len = cipher.key_len
73
73
  salt ||= OpenSSL::Random.random_bytes 16
74
74
  iter = 20_000
75
- digest = OpenSSL::Digest::SHA256.new
75
+ digest = OpenSSL::Digest.new('SHA256')
76
76
  key = OpenSSL::PKCS5.pbkdf2_hmac(password, salt, iter, key_len, digest)
77
77
  return key, salt
78
78
  end
@@ -85,15 +85,15 @@ module Sym
85
85
  iv: iv)
86
86
 
87
87
  block.call(cipher_struct) if block
88
-
88
+
89
89
  encrypted_data = update_cipher(cipher_struct.cipher, data)
90
90
  arguments = { encrypted_data: encrypted_data,
91
91
  iv: cipher_struct.iv,
92
92
  cipher_name: cipher_struct.cipher.name,
93
93
  salt: cipher_struct.salt,
94
94
  compress: !compression_enabled }
95
- wrapper_struct = WrapperStruct.new(arguments)
96
- encode(wrapper_struct, false)
95
+ wrapper_struct = WrapperStruct.new(**arguments)
96
+ encode(wrapper_struct, compress: false)
97
97
  end
98
98
 
99
99
  # Expects key to be a base64 encoded key data
@@ -109,7 +109,7 @@ module Sym
109
109
 
110
110
  def encode_incoming_data(data)
111
111
  compression_enabled = !data.respond_to?(:size) || (data.size > 100 && encryption_config.compression_enabled)
112
- data = encode(data, compression_enabled)
112
+ data = encode(data, compress: compression_enabled)
113
113
  [data, compression_enabled]
114
114
  end
115
115
 
@@ -13,8 +13,8 @@ class Object
13
13
  unless self.methods.include?(:present?)
14
14
  def present?
15
15
  return false if self.nil?
16
- if self.is_a?(String)
17
- return false if self == ''
16
+ if self.is_a?(String) && (self == '')
17
+ return false
18
18
  end
19
19
  true
20
20
  end
data/lib/sym/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Sym
2
- VERSION = '3.0.0'
2
+ VERSION = '3.0.1'
3
3
  DESCRIPTION = <<~eof
4
4
 
5
5
  Sym is a ruby library (gem) that offers both the command line interface
data/sym.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.bindir = 'exe'
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ['lib']
21
- spec.required_ruby_version = '>= 2.3'
21
+ spec.required_ruby_version = '>= 2.6'
22
22
  spec.post_install_message = <<~EOF
23
23
 
24
24
  Thank you for installing Sym!
@@ -60,7 +60,9 @@ Gem::Specification.new do |spec|
60
60
  spec.add_development_dependency 'relaxed-rubocop'
61
61
  spec.add_development_dependency 'rspec', '~> 3'
62
62
  spec.add_development_dependency 'rspec-its'
63
- spec.add_development_dependency 'rubocop', '0.81.0'
63
+ spec.add_development_dependency 'rubocop' # , '0.81.0'
64
+ spec.add_development_dependency 'rubocop-rspec' # , '0.81.0'
65
+ spec.add_development_dependency 'rubocop-rake' # , '0.81.0'
64
66
  spec.add_development_dependency 'simplecov'
65
67
  spec.add_development_dependency 'codecov'
66
68
  spec.add_development_dependency 'yard'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sym
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Konstantin Gredeskoul
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-15 00:00:00.000000000 Z
11
+ date: 2021-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colored2
@@ -196,16 +196,44 @@ dependencies:
196
196
  name: rubocop
197
197
  requirement: !ruby/object:Gem::Requirement
198
198
  requirements:
199
- - - '='
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: rubocop-rspec
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
200
221
  - !ruby/object:Gem::Version
201
- version: 0.81.0
222
+ version: '0'
223
+ - !ruby/object:Gem::Dependency
224
+ name: rubocop-rake
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - ">="
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
202
230
  type: :development
203
231
  prerelease: false
204
232
  version_requirements: !ruby/object:Gem::Requirement
205
233
  requirements:
206
- - - '='
234
+ - - ">="
207
235
  - !ruby/object:Gem::Version
208
- version: 0.81.0
236
+ version: '0'
209
237
  - !ruby/object:Gem::Dependency
210
238
  name: simplecov
211
239
  requirement: !ruby/object:Gem::Requirement
@@ -294,12 +322,14 @@ files:
294
322
  - ".gitignore"
295
323
  - ".rspec"
296
324
  - ".rubocop.yml"
325
+ - ".rubocop_todo.yml"
297
326
  - ".travis.yml"
298
327
  - ".yardopts"
299
328
  - CHANGELOG.md
300
329
  - Gemfile
301
330
  - LICENSE
302
331
  - README.adoc
332
+ - README.pdf
303
333
  - Rakefile
304
334
  - SYM-CLI.md
305
335
  - bin/changelog
@@ -388,14 +418,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
388
418
  requirements:
389
419
  - - ">="
390
420
  - !ruby/object:Gem::Version
391
- version: '2.3'
421
+ version: '2.6'
392
422
  required_rubygems_version: !ruby/object:Gem::Requirement
393
423
  requirements:
394
424
  - - ">="
395
425
  - !ruby/object:Gem::Version
396
426
  version: '0'
397
427
  requirements: []
398
- rubygems_version: 3.1.4
428
+ rubygems_version: 3.2.8
399
429
  signing_key:
400
430
  specification_version: 4
401
431
  summary: Dead-simple and easy to use encryption library on top of OpenSSL, offering