rubyment 0.4.25421176 → 0.4.25421266

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rubyment.rb +42 -27
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c689632d21680d8cfef43e14447f3bfc425d50c4
4
- data.tar.gz: c8061a2fd5fd6cddd9e100218da29cd26b273bbf
3
+ metadata.gz: f3cf5f393692d86f56ec7ae005f248e37f27984d
4
+ data.tar.gz: 81765d975abbb790820c0de5db2b5a1f61ff5c8a
5
5
  SHA512:
6
- metadata.gz: 914ddf325040d68c4682f460b02d11c0c75d00cd36f259bc68c0579471ca2299cff04464c7ee4065a23b6391ce68dcc82b8069b094bd5415482e72cf28c08009
7
- data.tar.gz: 002f2b57542e083a5321fe8da41f05f1558c9b06ffde9f5b3fbf844892968c7be2c992807027c885343ccd759530471ff100c2b04632716fe0707e81e8a42efc
6
+ metadata.gz: 46f41aaeadd44170dbc8472520198f97043b719dc3a1b6ae3fe2678de5a22e565ad118584192a95c34903cdf521108b79889cc1177512e4c175ae6961ece36b4
7
+ data.tar.gz: da2b1a63e53cddb54b654d8c353b08a655ffa554dcf2d5863aef9efe78afc999143c2e184e242b9ae2d42d52455471dc43c05fdcdd189822237c44bf4decdced
data/lib/rubyment.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  # Collection of Ruby functions
4
- # * output
5
- # normally outputs to STDERR, with
4
+ # === Output
5
+ # normally outputs to +STDERR+, with
6
6
  # no mercy
7
7
  # STDOUT, just qualified output:
8
8
  # only if the function is expected
@@ -431,23 +431,23 @@ class Rubyment
431
431
  end
432
432
 
433
433
 
434
- # decrypt encrypted (string), having password (string), iv (string),
435
- # big_file(bool) is a flag to set padding to 0.
434
+ # decipher the data encoded by enc
436
435
  #
437
- # planned changes:
438
- # add metadata information to encrypted
439
- # decipher.key = Digest::SHA256.hexdigest is not the best security.
440
- # encrypted could be called base64_encrypted
441
- # iv could be called base64_iv
442
- # get only one string, not encrypted and iv (see enc planned changes)
443
- # remove dependence on the uniqueness of ending
436
+ # @param [Array] args, an +Array+ whose elements are expected to be:
437
+ # +password+:: [String, nil] password to be used to encryption.
438
+ # +base64_iv+:: [String, nil] initialization vectors encoded with Base64
439
+ # +base64_encrypted+:: [String, nil] ciphered data (without metadata) encoded with Base64
440
+ # +ending+:: [nil] deprecated
441
+ # +base64_salt+:: [String, nil] #generate_pbkdf2_key salt encoded with Base64
442
+ # +base64_iter+:: [String, nil] #generate_pbkdf2_key iterations encoded with Base64
444
443
  #
444
+ # @return [String] decoded data
445
445
  def dec args=ARGV
446
446
  require 'openssl'
447
447
  require 'base64'
448
448
  memory = @memory
449
449
  static_end_key = memory[:static_end_key]
450
- password, iv, encrypted, ending, base64_salt, base64_iter = args
450
+ password, base64_iv, base64_encrypted, ending, base64_salt, base64_iter = args
451
451
  salt = Base64.decode64 base64_salt
452
452
  iter = Base64.decode64 base64_iter
453
453
  ending = ending.to_s.split("\0").first || static_end_key
@@ -460,8 +460,8 @@ class Rubyment
460
460
  decipher.padding = 0
461
461
 
462
462
  decipher.key = key || (Digest::SHA256.hexdigest password)
463
- decipher.iv = Base64.decode64 iv
464
- plain = decipher.update(Base64.decode64 encrypted) + decipher.final
463
+ decipher.iv = Base64.decode64 base64_iv
464
+ plain = decipher.update(Base64.decode64 base64_encrypted) + decipher.final
465
465
  # split is not the ideal, if ever ending is duplicated it won't
466
466
  # work. also may be innefficient.
467
467
  (plain.split ending).first
@@ -547,14 +547,23 @@ class Rubyment
547
547
  shell_dec_output [pw_plain]
548
548
  end
549
549
 
550
- # encrypt data (string), with password (string)
551
- # returns [base64_iv, base64_encrypted]
550
+
551
+ # encode data into aes-128-cbc cipher protected by a key generated
552
+ # by #generate_pbkdf2_key, using given +password+, +salt+, +iter+
552
553
  #
553
- # planned changes:
554
- # add metadata information to encrypted
555
- # return only one string, having encrypted + metadata (having iv)
556
- # add string length to metadata
557
- # decipher.key = Digest::SHA256.hexdigest is not the best security.
554
+ # @param [Array] args, an +Array+ whose elements are expected to be:
555
+ # +password+:: [String, nil] password to be used to encryption.
556
+ # +data+:: [String, nil] data to be encoded data
557
+ # +ending+:: [nil] deprecated
558
+ # +salt+:: [String, nil] #generate_pbkdf2_key salt argument
559
+ # +iter+:: [String, nil] #generate_pbkdf2_key iterations argument
560
+ #
561
+ # @return @param [Array] an +Array+ whose elements are expected to be:
562
+ # +base64_encrypted+:: [String, nil] ciphered data (without metadata) encoded with Base64
563
+ # +base64_iv+:: [String] initialization vectors encoded with Base64
564
+ # +base64_salt+:: [String] #generate_pbkdf2_key salt encoded with Base64
565
+ # +base64_iter+:: [String] #generate_pbkdf2_key iterations encoded with Base64
566
+ # +base64_key+:: [String] #generate_pbkdf2_key return value
558
567
  #
559
568
  def enc args=ARGV
560
569
  require 'openssl'
@@ -762,10 +771,10 @@ class Rubyment
762
771
  # an alternative interface to dec -- reads password if
763
772
  # nil or empty.
764
773
  #
765
- # @param [Array] args Defaults to +ARGV+. Elements:
766
- # * +data+ [String, nil] data to be encrypted, If empty or nil, read (without
767
- # echo) from @memory[:stdin], which defaults to STDIN
768
- # * +password+ [String, nil] password to be used to encryption.
774
+ # @param [Array] args, an +Array+ whose elements are expected to be:
775
+ # +iv+:: [String, nil]
776
+ # If empty or nil, read (without echo) from @memory[:stdin], which defaults to STDIN
777
+ # +password+:: [String, nil] password to be used to encryption.
769
778
  # If empty or nil, read (without echo) from @memory[:stdin], which defaults to STDIN
770
779
  #
771
780
  # @return [TrueClass, FalseClass] depending on whether test succeeds.
@@ -809,8 +818,14 @@ class Rubyment
809
818
 
810
819
 
811
820
  # test for enc and dec.
812
- # good idea is to use this function once with the desired
813
- # data, password, and use the stderr output
821
+ #
822
+ # @param [Array] args, an +Array+ whose elements are expected to be:
823
+ # +data+:: [String, nil] data to be encrypted.
824
+ # If empty or nil, read (without echo) from @memory[:stdin], which defaults to STDIN
825
+ # +password+:: [String, nil] password to be used to encryption.
826
+ # If empty or nil, read (without echo) from @memory[:stdin], which defaults to STDIN
827
+ #
828
+ # @return [TrueClass, FalseClass] depending on whether test succeeds.
814
829
  def test__enc_dec args=ARGV
815
830
  stderr = @memory[:stderr]
816
831
  data, password = args
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyment
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.25421176
4
+ version: 0.4.25421266
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribamar Santarosa