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 +4 -4
- data/Gemfile.lock +2 -6
- data/README.md +25 -19
- data/exe/generate-sri +19 -1
- data/lib/sri.rb +10 -5
- data/lib/sri/version.rb +1 -1
- data/sri.gemspec +2 -0
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ea17f4b2d6c472826369e0a68b676aceea40d7484740243bf5c7f908821f483
|
4
|
+
data.tar.gz: 19f4ceee35a37e26d997d50d23e844119b1bc4ef3ff549d1f8360743ac0c72b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
#
|
1
|
+
# SRI Generator
|
2
2
|
|
3
|
-
|
3
|
+
A way to generate Sub-Resource Integrity hashes on the command-line*
|
4
4
|
|
5
|
-
|
5
|
+
\* As long as you have Ruby installed!
|
6
6
|
|
7
|
-
##
|
7
|
+
## Install
|
8
8
|
|
9
|
-
|
9
|
+
Install with:
|
10
10
|
|
11
|
-
```
|
12
|
-
gem
|
11
|
+
```
|
12
|
+
gem install sri
|
13
13
|
```
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
$ bundle
|
15
|
+
## Usage
|
18
16
|
|
19
|
-
|
17
|
+
This gem comes with an executable called `generate-sri`. You can run it like this:
|
20
18
|
|
21
|
-
|
19
|
+
```
|
20
|
+
generate-sri -h sha512 ~/path/to/a/file
|
21
|
+
```
|
22
22
|
|
23
|
-
|
23
|
+
Or like this:
|
24
24
|
|
25
|
-
|
25
|
+
```
|
26
|
+
cat ~/path/to/a/file | generate-sri -h sha512
|
27
|
+
```
|
26
28
|
|
27
|
-
|
29
|
+
You may pass one of these through as the `-h` option:
|
28
30
|
|
29
|
-
|
31
|
+
* sha256
|
32
|
+
* sha384
|
33
|
+
* sha512
|
30
34
|
|
31
|
-
|
35
|
+
## Rationale
|
32
36
|
|
33
|
-
|
37
|
+
It is easier for me to remember "generate-sri" than it is to remember:
|
34
38
|
|
35
|
-
|
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
|
-
|
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.
|
6
|
-
|
7
|
-
|
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
|
-
|
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
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:
|
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
|