gem-checksum 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +19 -0
- data/Gemfile +3 -0
- data/LICENSE +20 -0
- data/README.md +4 -0
- data/Rakefile +1 -0
- data/gem-checksum.gemspec +23 -0
- data/lib/gem_checksum.rb +5 -0
- data/lib/gem_checksum/checker.rb +36 -0
- data/lib/gem_checksum/version.rb +3 -0
- data/lib/rubygems/commands/checksum_command.rb +62 -0
- data/lib/rubygems_plugin.rb +3 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
OWZhNmU3Mzg3ZGFmZWQ4MjlmZGQ4YmMxM2RhMDVlOTAxOTBjMzRhNw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MjdkOTI3NzAyNWM2MWE1NGFjYjlhN2ZmMDEwM2QyY2MwZTI5ZTg1NA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZjhlMDRhNThjMTZlZGFhNzBmMGY4M2E4ZWM3ZjE0MjE4ZDVkMzlkY2MyNjUx
|
10
|
+
ODhiNzIzOWIzMTliMzE5NmI4NDQ4OTE3Mzk0MjU3ODZjMzE2Mzc1OTYwMDNi
|
11
|
+
OWQyZDhjOTdiNzA2ODVhMWIxZDRiMzhkYzMzYTRlZWY3YmM3YmQ=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZjM4YWNmODEwN2M1ZjNmY2Q4ZGY4YWQyZWYyNjMyOTJjNjFhMWEzODA4MmY4
|
14
|
+
OTk2MWFiOWFiZGRmYmNmYjEwYzMxZmViODg2ZDI4OWRmYTNlODM3MmMxMjli
|
15
|
+
MjM2MzYwOTFmOWE2MTJjYTJiMDljYTYyZWE3MjVkZjRmOTQzMDE=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Benjamin Fleischer
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'gem_checksum/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "gem-checksum"
|
8
|
+
spec.version = GemChecksum::VERSION
|
9
|
+
spec.authors = ["Benjamin Fleischer"]
|
10
|
+
spec.email = ["github@benjaminfleischer.com"]
|
11
|
+
spec.description = %q{gem checksum [gem]}
|
12
|
+
spec.summary = %q{calculates and verifies checksums for rubygems}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
data/lib/gem_checksum.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'digest/sha2'
|
2
|
+
module GemChecksum
|
3
|
+
class Checker
|
4
|
+
|
5
|
+
def initialize(gem_path)
|
6
|
+
@gem_path = gem_path
|
7
|
+
end
|
8
|
+
|
9
|
+
# Generate SHA512 hexdigest
|
10
|
+
def generate_checksum
|
11
|
+
@checksum ||= ::Digest::SHA512.new.hexdigest(read_gem)
|
12
|
+
end
|
13
|
+
|
14
|
+
def write_checksum(checksum_folder)
|
15
|
+
fails "No such directory #{checksum_folder.inspect}" unless ::File.directory?(checksum_folder)
|
16
|
+
checksum_path = ::File.join(checksum_folder, "#{gem_file_name}.sha512")
|
17
|
+
::File.open(checksum_path, 'w' ) {|f| f.write(generate_checksum) }
|
18
|
+
"Wrote checksum to #{checksum_path}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def validate_checksum(checksum)
|
22
|
+
generate_checksum == checksum
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def read_gem
|
28
|
+
::File.binread(@gem_path)
|
29
|
+
end
|
30
|
+
|
31
|
+
def gem_file_name
|
32
|
+
@gem_file_name ||= @gem_path.split(::File::SEPARATOR).find{|part| part =~ /\.gem\Z/ }
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'gem_checksum'
|
2
|
+
require 'rubygems/command'
|
3
|
+
class Gem::Commands::ChecksumCommand < Gem::Command
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
super 'checksum', 'Calculate the checksum for a gem'
|
7
|
+
|
8
|
+
add_option('--compare-to',
|
9
|
+
'Boolean compare to the generated checksum') do
|
10
|
+
|value, options|
|
11
|
+
options[:compare_to] = value
|
12
|
+
end
|
13
|
+
|
14
|
+
add_option('--checksum-folder',
|
15
|
+
'Folder to write generated checksum to') do
|
16
|
+
|value, options|
|
17
|
+
options[:checksum_folder] = value
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
def arguments
|
23
|
+
"GEM_NAME the name of the gem you wish to hash"
|
24
|
+
end
|
25
|
+
|
26
|
+
def usage
|
27
|
+
"#{program_name} GEM_NAME"
|
28
|
+
end
|
29
|
+
|
30
|
+
def description
|
31
|
+
<<END
|
32
|
+
Calculcates the checksum for a gem
|
33
|
+
END
|
34
|
+
end
|
35
|
+
|
36
|
+
def execute
|
37
|
+
gem_path = next_optional_arg
|
38
|
+
fail "No .gem path passed in" if gem_path.nil?
|
39
|
+
checker = GemChecksum::Checker.new(gem_path)
|
40
|
+
|
41
|
+
say checksum = checker.generate_checksum
|
42
|
+
|
43
|
+
say checker.write_checksum(next_optional_arg) if options[:checksum_folder]
|
44
|
+
|
45
|
+
if options[:compare_to]
|
46
|
+
compare_to = next_optional_arg
|
47
|
+
if checker.validate_checksum(compare_to)
|
48
|
+
say "Checksum validated"
|
49
|
+
else
|
50
|
+
say "Calculated checksum not equal to given checksum: " <<
|
51
|
+
"\nExpected:\t#{compare_to}\nCalculcated:\t#{checksum}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def next_optional_arg
|
59
|
+
options[:args].shift
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gem-checksum
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Benjamin Fleischer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: gem checksum [gem]
|
42
|
+
email:
|
43
|
+
- github@benjaminfleischer.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- gem-checksum.gemspec
|
54
|
+
- lib/gem_checksum.rb
|
55
|
+
- lib/gem_checksum/checker.rb
|
56
|
+
- lib/gem_checksum/version.rb
|
57
|
+
- lib/rubygems/commands/checksum_command.rb
|
58
|
+
- lib/rubygems_plugin.rb
|
59
|
+
homepage: ''
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.0.8
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: calculates and verifies checksums for rubygems
|
83
|
+
test_files: []
|
84
|
+
has_rdoc:
|