sri 0.1.0 → 1.0.0

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
  SHA256:
3
- metadata.gz: e24ddf1e4de1a67fb34d4e3ba40afd3420bf4e7f3595abc106d1f7b7aeee2884
4
- data.tar.gz: 3d31c02ea58afbd40725fe5933e63c3e36525c39360f91be5316f0129df43d32
3
+ metadata.gz: 6ea17f4b2d6c472826369e0a68b676aceea40d7484740243bf5c7f908821f483
4
+ data.tar.gz: 19f4ceee35a37e26d997d50d23e844119b1bc4ef3ff549d1f8360743ac0c72b9
5
5
  SHA512:
6
- metadata.gz: 925301a5c5f76b47377cd800d8c80b7fc6cd1dcaf3f674ec9dde5fc8434b3731ce18e9aa0cf7509cf4d1e39162fdb688de99c745f41ab46e484aa75ccb4bf338
7
- data.tar.gz: 2bb032b021dfa22f39627625dca169afd7f18823fac1cabc25714a4ae63763399a7b252643cbbe090c551ce8f6be02608089d90b27577cca0e7188d23db9bc3f
6
+ metadata.gz: cb40276b84511fa91202c73061f1a74a9915ca22633ff8ddd0620874141a035bf272d147e986a66218f69379f53cc12bf4509f1713862a87bb8d141cec0a713b
7
+ data.tar.gz: 2fcfb1b3c325355fa9879c3864d6e08b973ae8077156ff03f3ae71aa259da43564b71901a38e0b3bd332d5239369bbb207c50387df5c9f02906abb6787056e93
data/Gemfile.lock CHANGED
@@ -2,16 +2,13 @@ PATH
2
2
  remote: .
3
3
  specs:
4
4
  sri (0.1.0)
5
+ clamp (~> 1.3.1)
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
8
9
  specs:
9
- coderay (1.1.2)
10
+ clamp (1.3.1)
10
11
  diff-lcs (1.3)
11
- method_source (0.9.2)
12
- pry (0.12.2)
13
- coderay (~> 1.1.0)
14
- method_source (~> 0.9.0)
15
12
  rake (10.5.0)
16
13
  rspec (3.9.0)
17
14
  rspec-core (~> 3.9.0)
@@ -32,7 +29,6 @@ PLATFORMS
32
29
 
33
30
  DEPENDENCIES
34
31
  bundler (~> 2.0)
35
- pry
36
32
  rake (~> 10.0)
37
33
  rspec (~> 3.0)
38
34
  sri!
data/README.md CHANGED
@@ -1,35 +1,41 @@
1
- # Sri
1
+ # SRI Generator
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sri`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ A way to generate Sub-Resource Integrity hashes on the command-line*
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ \* As long as you have Ruby installed!
6
6
 
7
- ## Installation
7
+ ## Install
8
8
 
9
- Add this line to your application's Gemfile:
9
+ Install with:
10
10
 
11
- ```ruby
12
- gem 'sri'
11
+ ```
12
+ gem install sri
13
13
  ```
14
14
 
15
- And then execute:
16
-
17
- $ bundle
15
+ ## Usage
18
16
 
19
- Or install it yourself as:
17
+ This gem comes with an executable called `generate-sri`. You can run it like this:
20
18
 
21
- $ gem install sri
19
+ ```
20
+ generate-sri -h sha512 ~/path/to/a/file
21
+ ```
22
22
 
23
- ## Usage
23
+ Or like this:
24
24
 
25
- TODO: Write usage instructions here
25
+ ```
26
+ cat ~/path/to/a/file | generate-sri -h sha512
27
+ ```
26
28
 
27
- ## Development
29
+ You may pass one of these through as the `-h` option:
28
30
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
31
+ * sha256
32
+ * sha384
33
+ * sha512
30
34
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
35
+ ## Rationale
32
36
 
33
- ## Contributing
37
+ It is easier for me to remember "generate-sri" than it is to remember:
34
38
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sri.
39
+ ```
40
+ cat ~/path/to/a/file | openssl digst -sha384 -binary | base64
41
+ ```
data/exe/generate-sri CHANGED
@@ -1,5 +1,23 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'sri'
4
+ require 'clamp'
4
5
 
5
- puts %Q{integrity="sha512-#{SRI.from_file(ARGV[0])}"}
6
+ Clamp do
7
+ option ["-h", "--hash"], "[sha256 | sha384 | sha512]", "hashing algorithm to use", required: true, attribute_name: :algorithm
8
+ parameter "[FILE]", "source file", optional: true
9
+
10
+ def execute
11
+ data = if file
12
+ File.read(file)
13
+ else
14
+ STDIN.read
15
+ end
16
+
17
+ puts SRI.generate_hash(algorithm, data)
18
+ end
19
+ end
20
+
21
+
22
+
23
+ # puts %Q{integrity="sha512-#{SRI.from_file(ARGV[0])}"}
data/lib/sri.rb CHANGED
@@ -2,12 +2,17 @@ require "sri/version"
2
2
  require "openssl"
3
3
 
4
4
  module SRI
5
- def self.from_file(file)
6
- generate_hash(File.read(File.expand_path(file)))
7
- end
5
+ def self.generate_hash(algorithm, content)
6
+ digest_class = case algorithm
7
+ when "sha256"
8
+ OpenSSL::Digest::SHA256
9
+ when "sha384"
10
+ OpenSSL::Digest::SHA384
11
+ when "sha512"
12
+ OpenSSL::Digest::SHA512
13
+ end
8
14
 
9
- def self.generate_hash(content)
10
- digest = OpenSSL::Digest::SHA512.new
15
+ digest = digest_class.new
11
16
  digest << content
12
17
  digest.base64digest
13
18
  end
data/lib/sri/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sri
2
- VERSION = "0.1.0"
2
+ VERSION = "1.0.0"
3
3
  end
data/sri.gemspec CHANGED
@@ -19,6 +19,8 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
+ spec.add_dependency 'clamp', '~> 1.3.1'
23
+
22
24
  spec.add_development_dependency "bundler", "~> 2.0"
23
25
  spec.add_development_dependency "rake", "~> 10.0"
24
26
  spec.add_development_dependency "rspec", "~> 3.0"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sri
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Bigg
@@ -10,6 +10,20 @@ bindir: exe
10
10
  cert_chain: []
11
11
  date: 2019-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: clamp
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.3.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.3.1
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement