jwk 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,54 @@
1
+ describe JWK::OctKey do
2
+ let(:jwk) do
3
+ File.read('spec/support/oct.json')
4
+ end
5
+
6
+ describe '#to_pem' do
7
+ it 'raises' do
8
+ key = JWK::Key.from_json(jwk)
9
+ expect { key.to_pem }.to raise_error(NotImplementedError)
10
+ end
11
+ end
12
+
13
+ describe '#to_s' do
14
+ it 'returns the key' do
15
+ key = JWK::Key.from_json(jwk)
16
+ expect(key.to_s).to eq 'hello world'
17
+ end
18
+ end
19
+
20
+ describe '#to_openssl_key' do
21
+ it 'raises' do
22
+ key = JWK::Key.from_json(jwk)
23
+ expect { key.to_openssl_key }.to raise_error(NotImplementedError)
24
+ end
25
+ end
26
+
27
+ describe '#to_json' do
28
+ it 'responds with the JWK JSON key' do
29
+ key = JWK::Key.from_json(jwk)
30
+ expect(JSON.parse(key.to_json)).to eq JSON.parse(jwk)
31
+ end
32
+ end
33
+
34
+ describe '#kty' do
35
+ it 'equals oct' do
36
+ key = JWK::Key.from_json(jwk)
37
+ expect(key.kty).to eq 'oct'
38
+ end
39
+ end
40
+
41
+ describe '#public?' do
42
+ it 'is true' do
43
+ key = JWK::Key.from_json(jwk)
44
+ expect(key.public?).to be_truthy
45
+ end
46
+ end
47
+
48
+ describe '#private?' do
49
+ it 'is true' do
50
+ key = JWK::Key.from_json(jwk)
51
+ expect(key.private?).to be_truthy
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,92 @@
1
+ describe JWK::RSAKey do
2
+ let(:private_jwk) do
3
+ File.read('spec/support/rsa_private.json')
4
+ end
5
+
6
+ let(:public_jwk) do
7
+ File.read('spec/support/rsa_public.json')
8
+ end
9
+
10
+ let(:partial_jwk) do
11
+ File.read('spec/support/rsa_partial.json')
12
+ end
13
+
14
+ let(:private_pem) do
15
+ File.read('spec/support/rsa_private.pem')
16
+ end
17
+
18
+ let(:public_pem) do
19
+ File.read('spec/support/rsa_public.pem')
20
+ end
21
+
22
+ describe '#to_pem' do
23
+ it 'converts private keys to the right format' do
24
+ key = JWK::Key.from_json(private_jwk)
25
+ expect(key.to_pem).to eq private_pem
26
+ end
27
+
28
+ it 'converts public keys keys to the right format' do
29
+ key = JWK::Key.from_json(public_jwk)
30
+ expect(key.to_pem).to eq public_pem
31
+ end
32
+
33
+ it 'fails on private keys with missing parameters' do
34
+ key = JWK::Key.from_json(partial_jwk)
35
+ expect { key.to_pem }.to raise_error NotImplementedError
36
+ end
37
+ end
38
+
39
+ describe '#to_s' do
40
+ it 'converts to pem' do
41
+ key = JWK::Key.from_json(public_jwk)
42
+ expect(key.to_s).to eq(key.to_pem)
43
+ end
44
+ end
45
+
46
+ describe '#to_openssl_key' do
47
+ it 'converts the private key to an openssl object' do
48
+ key = JWK::Key.from_json(private_jwk)
49
+ expect(key.to_openssl_key).to be_a OpenSSL::PKey::RSA
50
+ end
51
+ end
52
+
53
+ describe '#to_json' do
54
+ it 'responds with the JWK JSON key' do
55
+ key = JWK::Key.from_json(private_jwk)
56
+ expect(JSON.parse(key.to_json)).to eq JSON.parse(private_jwk)
57
+ end
58
+ end
59
+
60
+ describe '#kty' do
61
+ it 'equals RSA' do
62
+ key = JWK::Key.from_json(private_jwk)
63
+ expect(key.kty).to eq 'RSA'
64
+ end
65
+ end
66
+
67
+ describe '#public?' do
68
+ it 'is true' do
69
+ key = JWK::Key.from_json(private_jwk)
70
+ expect(key.public?).to be_truthy
71
+ end
72
+ end
73
+
74
+ describe '#private?' do
75
+ it 'is true for private keys' do
76
+ key = JWK::Key.from_json(private_jwk)
77
+ expect(key.private?).to be_truthy
78
+ end
79
+
80
+ it 'is false for public keys' do
81
+ key = JWK::Key.from_json(public_jwk)
82
+ expect(key.private?).to be_falsey
83
+ end
84
+ end
85
+
86
+ describe '#x5t_s256' do
87
+ it 'responds with the x5t#S256 element of the JWK' do
88
+ key = JWK::Key.from_json('{"kty":"RSA","n":"1","e":"2","x5t#S256":"hello"}')
89
+ expect(key.x5t_s256).to eq 'hello'
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,5 @@
1
+ RSpec.describe JWK do
2
+ it 'has a version number' do
3
+ expect(JWK::VERSION).not_to be nil
4
+ end
5
+ end
@@ -0,0 +1,20 @@
1
+ require 'simplecov'
2
+ SimpleCov.start do
3
+ add_filter 'spec/'
4
+ end
5
+
6
+ require 'bundler/setup'
7
+ require 'jwk'
8
+
9
+ Dir['spec/support/**/*.rb'].each { |f| require File.expand_path(f) }
10
+
11
+ RSpec.configure do |config|
12
+ # Enable flags like --only-failures and --next-failure
13
+ config.example_status_persistence_file_path = '.rspec_status'
14
+
15
+ config.expect_with :rspec do |c|
16
+ c.syntax = :expect
17
+ end
18
+
19
+ config.order = 'random'
20
+ end
@@ -0,0 +1,7 @@
1
+ {
2
+ "kty":"EC",
3
+ "crv":"P-256",
4
+ "x":"gI0GAILBdu7T53akrFmMyGcsF3n5dO7MmwNBHKW5SV0",
5
+ "y":"SLW_xSffzlPWrHEVI30DHM_4egVwt3NQqeUD7nMFpps",
6
+ "d":"0_NxaRPUMQoAJt50Gz8YiTr8gRTwyEaCumd-MToTmIo"
7
+ }
@@ -0,0 +1,5 @@
1
+ -----BEGIN EC PRIVATE KEY-----
2
+ MHcCAQEEINPzcWkT1DEKACbedBs/GIk6/IEU8MhGgrpnfjE6E5iKoAoGCCqGSM49
3
+ AwEHoUQDQgAEgI0GAILBdu7T53akrFmMyGcsF3n5dO7MmwNBHKW5SV1Itb/FJ9/O
4
+ U9ascRUjfQMcz/h6BXC3c1Cp5QPucwWmmw==
5
+ -----END EC PRIVATE KEY-----
@@ -0,0 +1,6 @@
1
+ {
2
+ "kty":"EC",
3
+ "crv":"P-256",
4
+ "x":"gI0GAILBdu7T53akrFmMyGcsF3n5dO7MmwNBHKW5SV0",
5
+ "y":"SLW_xSffzlPWrHEVI30DHM_4egVwt3NQqeUD7nMFpps"
6
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "kty":"oct",
3
+ "k":"aGVsbG8gd29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 67WZFLir5z6zJ7FFBZX1Hcm1c8co8/SRf18mmNeGq3S0o3+C/xTW
27
+ -----END RSA PRIVATE KEY-----
@@ -0,0 +1,5 @@
1
+ {
2
+ "kty":"RSA",
3
+ "n":"oahUIoWw0K0usKNuOR6H4wkf4oBUXHTxRvgb48E-BVvxkeDNjbC4he8rUWcJoZmds2h7M70imEVhRU5djINXtqllXI4DFqcI1DgjT9LewND8MW2Krf3Spsk_ZkoFnilakGygTwpZ3uesH-PFABNIUYpOiN15dsQRkgr0vEhxN92i2asbOenSZeyaxziK72UwxrrKoExv6kc5twXTq4h-QChLOln0_mtUZwfsRaMStPs6mS6XrgxnxbWhojf663tuEQueGC-FCMfra36C9knDFGzKsNa7LZK2djYgyD3JR_MB_4NUJW_TqOQtwHYbxevoJArm-L5StowjzGy-_bq6Gw",
4
+ "e":"AQAB"
5
+ }
@@ -0,0 +1,9 @@
1
+ -----BEGIN PUBLIC KEY-----
2
+ MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoahUIoWw0K0usKNuOR6H
3
+ 4wkf4oBUXHTxRvgb48E+BVvxkeDNjbC4he8rUWcJoZmds2h7M70imEVhRU5djINX
4
+ tqllXI4DFqcI1DgjT9LewND8MW2Krf3Spsk/ZkoFnilakGygTwpZ3uesH+PFABNI
5
+ UYpOiN15dsQRkgr0vEhxN92i2asbOenSZeyaxziK72UwxrrKoExv6kc5twXTq4h+
6
+ QChLOln0/mtUZwfsRaMStPs6mS6XrgxnxbWhojf663tuEQueGC+FCMfra36C9knD
7
+ FGzKsNa7LZK2djYgyD3JR/MB/4NUJW/TqOQtwHYbxevoJArm+L5StowjzGy+/bq6
8
+ GwIDAQAB
9
+ -----END PUBLIC KEY-----
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jwk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Francesco Boffa
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-11-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
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
+ - !ruby/object:Gem::Dependency
42
+ name: simplecov
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: codeclimate-test-reporter
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: A Ruby implementation of the RFC 7517 JSON Web Keys (JWK) standard
70
+ email:
71
+ - fra.boffa@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".codeclimate.yml"
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".rubocop.yml"
80
+ - ".travis.yml"
81
+ - Gemfile
82
+ - LICENSE.md
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - docs/asn1.md
88
+ - jwk.gemspec
89
+ - lib/jwk.rb
90
+ - lib/jwk/asn1.rb
91
+ - lib/jwk/ec_key.rb
92
+ - lib/jwk/key.rb
93
+ - lib/jwk/oct_key.rb
94
+ - lib/jwk/rsa_key.rb
95
+ - lib/jwk/utils.rb
96
+ - lib/jwk/version.rb
97
+ - spec/jwk/asn1_spec.rb
98
+ - spec/jwk/ec_key_spec.rb
99
+ - spec/jwk/key_spec.rb
100
+ - spec/jwk/oct_key_spec.rb
101
+ - spec/jwk/rsa_key_spec.rb
102
+ - spec/jwk_spec.rb
103
+ - spec/spec_helper.rb
104
+ - spec/support/ec_private.json
105
+ - spec/support/ec_private.pem
106
+ - spec/support/ec_public.json
107
+ - spec/support/oct.json
108
+ - spec/support/rsa_partial.json
109
+ - spec/support/rsa_private.json
110
+ - spec/support/rsa_private.pem
111
+ - spec/support/rsa_public.json
112
+ - spec/support/rsa_public.pem
113
+ homepage: https://github.com/aomega08/jwk
114
+ licenses:
115
+ - MIT
116
+ metadata: {}
117
+ post_install_message:
118
+ rdoc_options: []
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ requirements: []
132
+ rubyforge_project:
133
+ rubygems_version: 2.6.11
134
+ signing_key:
135
+ specification_version: 4
136
+ summary: JSON Web Keys implementation in Ruby
137
+ test_files: []