libis-tools 0.9.19 → 0.9.20

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
  SHA1:
3
- metadata.gz: 84e2ba68f4feadddd920416358116a88db072a3c
4
- data.tar.gz: deea70214ee81612b8245552a78cbed501fa2033
3
+ metadata.gz: b02d1a5db6228befa73d14fb34880fc50c1c3205
4
+ data.tar.gz: 45cd0d340b39e2f585d0aeb25076b439132f2af7
5
5
  SHA512:
6
- metadata.gz: 2ed8ec0e8fc72699698f20efd81eef387acf382f7b730839c256117fd03df39e508d0f5d655a5e1ce11266cad3d1eb3adb4c0da3001d3b1a9fd28142d6052dbd
7
- data.tar.gz: db3f33e89f52053b28c1f84df50bbbc7f0833d024ce349b1eaf5d83fdccb51135ddbbacc5417b9a30b9c8c7d8b41a71bf384a891cd9a76ed0878ef38f50ac876
6
+ metadata.gz: 660ddb441d546e37e4170cd236853dcf5273063873dee76647a79ee9c6f0386a9fdb010c8a91f4e1ce175060278ddb6e0b3153c8ec67ef47ccc232c2beace443
7
+ data.tar.gz: 68d181a6f3c644f38561947f13dd138fb69973d12b3c213f0fee24b454f228e4840bdfec611ba1a8c1e9fc17b502faa31857fbd37ab4723745faec041e230436
@@ -29,19 +29,19 @@ module Libis
29
29
  #
30
30
  # @param [String] file_path_or_string path of the file to calculate the digest for
31
31
  def digest(file_path_or_string)
32
- @hasher.file(file_path_or_string).digest!
32
+ hashit(file_path_or_string).digest!
33
33
  end
34
34
 
35
35
  # Calculate the hexadecimal digest of a file.
36
36
  # @param (see #digest)
37
37
  def hexdigest(file_path_or_string)
38
- @hasher.file(file_path_or_string).hexdigest!
38
+ hashit(file_path_or_string).hexdigest!
39
39
  end
40
40
 
41
41
  # Calculate the base64 digest of a file.
42
42
  # @param (see #digest)
43
43
  def base64digest(file_path_or_string)
44
- @hasher.file(file_path_or_string).base64digest!
44
+ hashit(file_path_or_string).base64digest!
45
45
  end
46
46
 
47
47
  # Calculate the binary digest of a file.
@@ -75,7 +75,12 @@ module Libis
75
75
  private
76
76
 
77
77
  def hashit(file_path_or_string)
78
- @hasher.file(file_path_or_string)
78
+ if File.exist?(file_path_or_string)
79
+ @hasher.file(file_path_or_string)
80
+ else
81
+ @hasher.reset.update(file_path_or_string)
82
+ end
83
+ @hasher
79
84
  end
80
85
 
81
86
  end
@@ -1,5 +1,5 @@
1
1
  module Libis
2
2
  module Tools
3
- VERSION = '0.9.19'
3
+ VERSION = '0.9.20'
4
4
  end
5
5
  end
@@ -4,8 +4,6 @@ require 'libis/tools/checksum'
4
4
 
5
5
  describe 'Checksum' do
6
6
 
7
- file = File.absolute_path(File.join(File.dirname(__FILE__), 'data', 'test.data'))
8
-
9
7
  def hex2base64(hexdigest)
10
8
  [[hexdigest].pack('H*')].pack('m0')
11
9
  end
@@ -14,118 +12,56 @@ describe 'Checksum' do
14
12
  [hexdigest].pack('H*')
15
13
  end
16
14
 
17
- it 'should calculate MD5 checksum' do
18
-
19
- checksum_type = :MD5
20
- digest = 'fe249d8dd45a39793f315fb0734ffe2c'
21
- expect(::Libis::Tools::Checksum.hexdigest(file, checksum_type)).to eq digest
22
- expect(::Libis::Tools::Checksum.base64digest(file, checksum_type)).to eq hex2base64(digest)
23
- expect(::Libis::Tools::Checksum.digest(file, checksum_type)).to eq hex2string(digest)
24
-
25
- checksum = ::Libis::Tools::Checksum.new(checksum_type)
26
-
27
- expect(checksum.hexdigest(file)).to eq digest
28
- expect(checksum.base64digest(file)).to eq hex2base64(digest)
29
- expect(checksum.digest(file)).to eq hex2string(digest)
30
-
31
- end
32
-
33
- it 'should calculate RMD160 checksum' do
34
-
35
- unless defined? JRUBY_VERSION
36
-
37
- checksum_type = :RMD160
38
-
39
- digest = '17c9eaad9ccbaad0e030c2c5d60fd9d58255cc39'
40
- expect(::Libis::Tools::Checksum.hexdigest(file, checksum_type)).to eq digest
41
- expect(::Libis::Tools::Checksum.base64digest(file, checksum_type)).to eq hex2base64(digest)
42
- expect(::Libis::Tools::Checksum.digest(file, checksum_type)).to eq hex2string(digest)
43
-
44
- checksum = ::Libis::Tools::Checksum.new(checksum_type)
45
-
46
- expect(checksum.hexdigest(file)).to eq digest
47
- expect(checksum.base64digest(file)).to eq hex2base64(digest)
48
- expect(checksum.digest(file)).to eq hex2string(digest)
49
-
50
- end
51
-
52
- end
53
-
54
- it 'should calculate SHA1 checksum' do
55
-
56
- checksum_type = :SHA1
57
-
58
- digest = 'e8f322d186699807a98a0cefb5015acf1554f954'
59
- expect(::Libis::Tools::Checksum.hexdigest(file, checksum_type)).to eq digest
60
- expect(::Libis::Tools::Checksum.base64digest(file, checksum_type)).to eq hex2base64(digest)
61
- expect(::Libis::Tools::Checksum.digest(file, checksum_type)).to eq hex2string(digest)
62
-
63
- checksum = ::Libis::Tools::Checksum.new(checksum_type)
64
-
65
- expect(checksum.hexdigest(file)).to eq digest
66
- expect(checksum.base64digest(file)).to eq hex2base64(digest)
67
- expect(checksum.digest(file)).to eq hex2string(digest)
68
-
69
- end
70
-
71
- it 'should calculate SHA256 checksum' do
72
-
73
- checksum_type = :SHA256
74
-
75
- digest = '2a742e643dd79427738bdc0ebd0d2837f998fe2101a964c2d5014905d331bbc4'
76
- expect(::Libis::Tools::Checksum.hexdigest(file, checksum_type)).to eq digest
77
- expect(::Libis::Tools::Checksum.base64digest(file, checksum_type)).to eq hex2base64(digest)
78
- expect(::Libis::Tools::Checksum.digest(file, checksum_type)).to eq hex2string(digest)
15
+ it 'should not know how to calculate ABC checksum' do
79
16
 
80
- checksum = ::Libis::Tools::Checksum.new(checksum_type)
17
+ checksum_type = :ABC
81
18
 
82
- expect(checksum.hexdigest(file)).to eq digest
83
- expect(checksum.base64digest(file)).to eq hex2base64(digest)
84
- expect(checksum.digest(file)).to eq hex2string(digest)
19
+ expect {
20
+ ::Libis::Tools::Checksum.hexdigest('abc', checksum_type)
21
+ }.to raise_error(RuntimeError, "Checksum type 'ABC' not supported.")
85
22
 
86
23
  end
87
24
 
88
- it 'should calculate SHA384 checksum' do
89
-
90
- checksum_type = :SHA384
25
+ let(:filename) { File.join(File.dirname(__FILE__), 'data', 'test.data') }
91
26
 
92
- digest = '71083b74394f49db6149ad9147103f7693ec823183750ce32a2215bbd7ee5e75212e2d794243c7e76c7318a4ddcf9a56'
93
- expect(::Libis::Tools::Checksum.hexdigest(file, checksum_type)).to eq digest
94
- expect(::Libis::Tools::Checksum.base64digest(file, checksum_type)).to eq hex2base64(digest)
95
- expect(::Libis::Tools::Checksum.digest(file, checksum_type)).to eq hex2string(digest)
96
-
97
- checksum = ::Libis::Tools::Checksum.new(checksum_type)
98
-
99
- expect(checksum.hexdigest(file)).to eq digest
100
- expect(checksum.base64digest(file)).to eq hex2base64(digest)
101
- expect(checksum.digest(file)).to eq hex2string(digest)
27
+ CHECKSUM_RESULTS = {
28
+ MD5: 'fe249d8dd45a39793f315fb0734ffe2c',
29
+ SHA1: 'e8f322d186699807a98a0cefb5015acf1554f954',
30
+ SHA256: '2a742e643dd79427738bdc0ebd0d2837f998fe2101a964c2d5014905d331bbc4',
31
+ SHA384: '71083b74394f49db6149ad9147103f7693ec823183750ce32a2215bbd7ee5e75212e2d794243c7e76c7318a4ddcf9a56',
32
+ SHA512: '10964f5272729c2670ccad67754284fb06cca1387270c184c2edbcd032700548297916c8e109a10e019c25b86c646e95a3456c465f83d571502889f97b483e6f'
33
+ }
102
34
 
35
+ # noinspection RubyResolve
36
+ unless defined? JRUBY_VERSION
37
+ CHECKSUM_RESULTS[:RMD160] = '17c9eaad9ccbaad0e030c2c5d60fd9d58255cc39'
103
38
  end
104
39
 
105
- it 'should calculate SHA512 checksum' do
106
-
107
- checksum_type = :SHA512
40
+ filename = File.join(File.dirname(__FILE__), 'data', 'test.data')
41
+ file = File.absolute_path(filename)
42
+ string = File.read(filename)
43
+ SUBJECTS = {
44
+ string: string,
45
+ file: file
46
+ }
108
47
 
109
- digest = '10964f5272729c2670ccad67754284fb06cca1387270c184c2edbcd032700548297916c8e109a10e019c25b86c646e95a3456c465f83d571502889f97b483e6f'
110
- expect(::Libis::Tools::Checksum.hexdigest(file, checksum_type)).to eq digest
111
- expect(::Libis::Tools::Checksum.base64digest(file, checksum_type)).to eq hex2base64(digest)
112
- expect(::Libis::Tools::Checksum.digest(file, checksum_type)).to eq hex2string(digest)
48
+ CHECKSUM_RESULTS.each do |checksum_type, digest|
113
49
 
114
- checksum = ::Libis::Tools::Checksum.new(checksum_type)
50
+ SUBJECTS.each do |subject_type, subject|
115
51
 
116
- expect(checksum.hexdigest(file)).to eq digest
117
- expect(checksum.base64digest(file)).to eq hex2base64(digest)
118
- expect(checksum.digest(file)).to eq hex2string(digest)
119
-
120
- end
52
+ it "should calculate #{checksum_type} from #{subject_type}" do
53
+ expect(::Libis::Tools::Checksum.hexdigest(subject, checksum_type)).to eq digest
54
+ expect(::Libis::Tools::Checksum.base64digest(subject, checksum_type)).to eq hex2base64(digest)
55
+ expect(::Libis::Tools::Checksum.digest(subject, checksum_type)).to eq hex2string(digest)
121
56
 
122
- it 'should not know how to calculate ABC checksum' do
57
+ checksum = ::Libis::Tools::Checksum.new(checksum_type)
123
58
 
124
- checksum_type = :ABC
59
+ expect(checksum.hexdigest(subject)).to eq digest
60
+ expect(checksum.base64digest(subject)).to eq hex2base64(digest)
61
+ expect(checksum.digest(subject)).to eq hex2string(digest)
62
+ end
125
63
 
126
- expect {
127
- ::Libis::Tools::Checksum.hexdigest(file, checksum_type)
128
- }.to raise_error(RuntimeError, "Checksum type 'ABC' not supported.")
64
+ end
129
65
 
130
66
  end
131
67
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libis-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.19
4
+ version: 0.9.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kris Dekeyser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-05 00:00:00.000000000 Z
11
+ date: 2016-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler