cose-key 0.0.3 → 0.0.4

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: 3cb49170acb17ea18e9ef50d25a4d1a04ffd1f92777dd0093d7d59ababaf558d
4
- data.tar.gz: a239aef8a89fa66df33a57c77abd9a108a108e984100da0389ba4f62994a42d5
3
+ metadata.gz: c784f5570d8b6a8e70be5fab055c530c93fc11ae9c403f512b4104a82a48a14a
4
+ data.tar.gz: 80b22fce793a2855c191b86fd31bb553c461191d2707a81453a095bd8c1e6bd3
5
5
  SHA512:
6
- metadata.gz: 1bdbcf363e1050948b07694c4957b73b44e52c1e042775a30fe68d058c98b9b9419d7c79e80bf1c848de7dd195665d30fd2461f7295c433104cdf21098734c34
7
- data.tar.gz: bcfb14988ad3b698f7399fd4ea3c200d6ca01ac72b3033fc7b60eb468212ad6dcba4c58c3e3aa40aa61767d98c2e3ff365ed835e93c1b5d82ac3438a6dcc99e7
6
+ metadata.gz: 97b1bbeafae1df9a0389e0168402b4f985723050a79f50323c35752861232d9d0591890dc20d414f8362518e3e5fd11f9a3e91a2128e2826869bc4bd746c3e7d
7
+ data.tar.gz: 7c0c92e1a663b35b1021e284bb8bf11c20452ce6fbf1192d946aa780d21e2c30fa2917c07f32bcca8e6666badb5d39c3e64b562840c3c8bcd1c4f149f42a519a
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
data/lib/cose/key/ec2.rb CHANGED
@@ -6,13 +6,16 @@ module COSE
6
6
  Y = -3
7
7
  D = -4
8
8
 
9
- ES256 = -7
10
- ES384 = -35
11
- ES512 = -36
12
-
13
- P256 = 1
14
- P384 = 2
15
- P521 = 3
9
+ ALGS = {
10
+ ES256: -7,
11
+ ES384: -35,
12
+ ES512: -36
13
+ }
14
+ CRVS = {
15
+ P256: 1,
16
+ P384: 2,
17
+ P521: 3
18
+ }
16
19
 
17
20
  attr_accessor :crv, :x, :y, :d
18
21
 
@@ -24,37 +27,43 @@ module COSE
24
27
  self.d = attrs[D]
25
28
  end
26
29
 
27
- def curve_name
28
- case crv
29
- when P256
30
+ def alg_key
31
+ ALGS.invert[alg] or
32
+ raise 'Unknown Algorithm'
33
+ end
34
+
35
+ def crv_key
36
+ CRVS.invert[crv] or
37
+ raise 'Unknown Curve'
38
+ end
39
+
40
+ def crv_name
41
+ case crv_key
42
+ when :P256
30
43
  'prime256v1'
31
- when P384
44
+ when :P384
32
45
  'secp384r1'
33
- when P521
46
+ when :P521
34
47
  'secp521r1'
35
- else
36
- raise 'Unknown Curve'
37
48
  end
38
49
  end
39
50
 
40
51
  def digest
41
- case alg
42
- when ES256
52
+ case alg_key
53
+ when :ES256
43
54
  OpenSSL::Digest::SHA256
44
- when ES384
55
+ when :ES384
45
56
  OpenSSL::Digest::SHA384
46
- when ES512
57
+ when :ES512
47
58
  OpenSSL::Digest::SHA512
48
- else
49
- raise 'Unknown Algorithm'
50
59
  end.new
51
60
  end
52
61
 
53
62
  def to_key
54
- key = OpenSSL::PKey::EC.new curve_name
63
+ key = OpenSSL::PKey::EC.new crv_name
55
64
  key.private_key = OpenSSL::BN.new(d, 2) if d
56
65
  key.public_key = OpenSSL::PKey::EC::Point.new(
57
- OpenSSL::PKey::EC::Group.new(curve_name),
66
+ OpenSSL::PKey::EC::Group.new(crv_name),
58
67
  OpenSSL::BN.new([
59
68
  '04' +
60
69
  x.unpack('H*').first +
data/lib/cose/key/rsa.rb CHANGED
@@ -10,12 +10,14 @@ module COSE
10
10
  DQ = -7
11
11
  QI = -8
12
12
 
13
- PS256 = -37
14
- PS384 = -38
15
- PS512 = -39
16
- RSAES_OAEP_SHA1 = -40
17
- RSAES_OAEP_SHA256 = -41
18
- RSAES_OAEP_SHA512 = -42
13
+ ALGS = {
14
+ PS256: -37,
15
+ PS384: -38,
16
+ PS512: -39,
17
+ RSAES_OAEP_SHA1: -40,
18
+ RSAES_OAEP_SHA256: -41,
19
+ RSAES_OAEP_SHA512: -42
20
+ }
19
21
 
20
22
  attr_accessor :n, :e, :d, :p, :q, :dp, :dq, :qi
21
23
 
@@ -31,18 +33,21 @@ module COSE
31
33
  self.qi = attrs[QI]
32
34
  end
33
35
 
36
+ def alg_key
37
+ ALGS.invert[alg] or
38
+ raise 'Unknown Algorithm'
39
+ end
40
+
34
41
  def digest
35
- case alg
36
- when RSAES_OAEP_SHA1
42
+ case alg_key
43
+ when :RSAES_OAEP_SHA1
37
44
  OpenSSL::Digest::SHA1
38
- when PS256, RSAES_OAEP_SHA256
45
+ when :PS256, :RSAES_OAEP_SHA256
39
46
  OpenSSL::Digest::SHA256
40
- when PS384
47
+ when :PS384
41
48
  OpenSSL::Digest::SHA384
42
- when PS512, RSAES_OAEP_SHA512
49
+ when :PS512, :RSAES_OAEP_SHA512
43
50
  OpenSSL::Digest::SHA512
44
- else
45
- raise 'Unknown Algorithm'
46
51
  end.new
47
52
  end
48
53
 
data/lib/cose/key.rb CHANGED
@@ -24,24 +24,16 @@ module COSE
24
24
  self.base_iv = attrs[BASE_IV]
25
25
  end
26
26
 
27
- def digest
27
+ def alg_key
28
28
  raise 'Implement me'
29
29
  end
30
30
 
31
- def to_key
31
+ def digest
32
32
  raise 'Implement me'
33
33
  end
34
34
 
35
- def to_s
36
- raw
37
- end
38
-
39
- def to_pem
40
- to_key.to_pem
41
- end
42
-
43
- def to_text
44
- to_key.to_text
35
+ def to_key
36
+ raise 'Implement me'
45
37
  end
46
38
 
47
39
  class << self
@@ -21,8 +21,23 @@ RSpec.describe COSE::Key do
21
21
  it { should be_instance_of COSE::Key::EC2 }
22
22
  end
23
23
 
24
- describe '#curve_name' do
25
- subject { decoded.curve_name }
24
+ describe '#raw' do
25
+ subject { decoded.raw }
26
+ it { should == ec2_cbor }
27
+ end
28
+
29
+ describe '#alg_key' do
30
+ subject { decoded.alg_key }
31
+ it { should == :ES256 }
32
+ end
33
+
34
+ describe '#crv_key' do
35
+ subject { decoded.crv_key }
36
+ it { should == :P256 }
37
+ end
38
+
39
+ describe '#crv_name' do
40
+ subject { decoded.crv_name }
26
41
  it { should == 'prime256v1' }
27
42
  end
28
43
 
@@ -35,21 +50,6 @@ RSpec.describe COSE::Key do
35
50
  subject { decoded.to_key }
36
51
  it { should be_instance_of OpenSSL::PKey::EC }
37
52
  end
38
-
39
- # describe '#to_s' do
40
- # subject { decoded.to_s }
41
- # it { should == ec2_cbor }
42
- # end
43
-
44
- describe '#to_pem' do
45
- subject { decoded.to_pem }
46
- it { should == ec2_pem }
47
- end
48
-
49
- describe '#to_text' do
50
- subject { decoded.to_text }
51
- it { should == ec2_key.to_text }
52
- end
53
53
  end
54
54
 
55
55
  context 'for RSA keys' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cose-key
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - nov matake
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-08 00:00:00.000000000 Z
11
+ date: 2018-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cbor