cose 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/README.md +32 -2
- data/lib/cose/key.rb +27 -0
- data/lib/cose/key/base.rb +2 -4
- data/lib/cose/key/rsa.rb +33 -0
- data/lib/cose/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05132ebf44cbd8025419363e4f7225a55e28896b9db9c61e490866bdf7ca7d1d
|
4
|
+
data.tar.gz: 5656845e945fa562609f59c05a417a433c2d92f771395727634d7ea1ebc71838
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8c048d5f991c86a246d2ab7384717be17f86edaddbcd4c1f4ce2dbd3b8b25d66b85831ce3b9c5d02f0ce033abeac84b457397d5bb1df540aebd3693b659ee60
|
7
|
+
data.tar.gz: '01953ba4ed4d5734ad0044b3e8735dad85f95407663ad52c04a1d306094c8cdf6b01943c55813eb87ae56688098a6d8cef364c096e9d393b4f1ff2a7873bafd4'
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [v0.4.0] - 2019-03-12
|
4
|
+
|
5
|
+
### Added
|
6
|
+
|
7
|
+
- RSA public key deserialization
|
8
|
+
- Key type-agnostic deserialization
|
9
|
+
|
10
|
+
### Changed
|
11
|
+
|
12
|
+
- Keys `.from_cbor` methods changed to `.deserialize`
|
13
|
+
|
3
14
|
## [v0.3.0] - 2019-03-09
|
4
15
|
|
5
16
|
### Added
|
@@ -28,6 +39,7 @@
|
|
28
39
|
- EC2 key object
|
29
40
|
- Works with ruby 2.5
|
30
41
|
|
42
|
+
[v0.4.0]: https://github.com/cedarcode/cose-ruby/compare/v0.3.0...v0.4.0/
|
31
43
|
[v0.3.0]: https://github.com/cedarcode/cose-ruby/compare/v0.2.0...v0.3.0/
|
32
44
|
[v0.2.0]: https://github.com/cedarcode/cose-ruby/compare/v0.1.0...v0.2.0/
|
33
45
|
[v0.1.0]: https://github.com/cedarcode/cose-ruby/compare/5725d9b5db978f19a21bd59182f092d31a118eff...v0.1.0/
|
data/README.md
CHANGED
@@ -25,12 +25,31 @@ Or install it yourself as:
|
|
25
25
|
|
26
26
|
### Key Objects
|
27
27
|
|
28
|
+
```ruby
|
29
|
+
cbor_data = "..."
|
30
|
+
|
31
|
+
key = COSE::Key.deserialize(cbor_data)
|
32
|
+
|
33
|
+
case key.class
|
34
|
+
when COSE::Key::EC2
|
35
|
+
key.curve
|
36
|
+
key.x_coordinate
|
37
|
+
key.y_coordinate
|
38
|
+
key.d_coordinate
|
39
|
+
when COSE::Key::RSA
|
40
|
+
key.modulus_n
|
41
|
+
key.public_exponent_e
|
42
|
+
when COSE::Key::Symmetric
|
43
|
+
key.key_value
|
44
|
+
end
|
45
|
+
```
|
46
|
+
|
28
47
|
#### EC2
|
29
48
|
|
30
49
|
```ruby
|
31
50
|
cbor_data = "..."
|
32
51
|
|
33
|
-
key = COSE::Key::EC2.
|
52
|
+
key = COSE::Key::EC2.deserialize(cbor_data)
|
34
53
|
|
35
54
|
key.curve
|
36
55
|
key.x_coordinate
|
@@ -43,11 +62,22 @@ key.d_coordinate
|
|
43
62
|
```ruby
|
44
63
|
cbor_data = "..."
|
45
64
|
|
46
|
-
key = COSE::Key::Symmetric.
|
65
|
+
key = COSE::Key::Symmetric.deserialize(cbor_data)
|
47
66
|
|
48
67
|
key.key_value
|
49
68
|
```
|
50
69
|
|
70
|
+
#### RSA
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
cbor_data = "..."
|
74
|
+
|
75
|
+
key = COSE::Key::RSA.deserialize(cbor_data)
|
76
|
+
|
77
|
+
key.modulus_n
|
78
|
+
key.public_exponent_e
|
79
|
+
```
|
80
|
+
|
51
81
|
### Signing Objects
|
52
82
|
|
53
83
|
#### COSE_Sign
|
data/lib/cose/key.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require "cbor"
|
2
|
+
require "cose/key/ec2"
|
3
|
+
require "cose/key/rsa"
|
4
|
+
require "cose/key/symmetric"
|
5
|
+
|
6
|
+
module COSE
|
7
|
+
class UnknownKeyType < StandardError; end
|
8
|
+
|
9
|
+
module Key
|
10
|
+
LABEL_KTY = 1
|
11
|
+
|
12
|
+
def self.deserialize(data)
|
13
|
+
map = CBOR.decode(data)
|
14
|
+
|
15
|
+
case map[LABEL_KTY]
|
16
|
+
when COSE::Key::EC2::KTY_EC2
|
17
|
+
COSE::Key::EC2.from_map(map)
|
18
|
+
when COSE::Key::RSA::KTY_RSA
|
19
|
+
COSE::Key::RSA.from_map(map)
|
20
|
+
when COSE::Key::Symmetric::KTY_SYMMETRIC
|
21
|
+
COSE::Key::Symmetric.from_map(map)
|
22
|
+
else
|
23
|
+
raise UnknownKeyType, "Unsupported or unknown key type #{map[LABEL_KTY]}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/cose/key/base.rb
CHANGED
@@ -5,14 +5,12 @@ require "cbor"
|
|
5
5
|
module COSE
|
6
6
|
module Key
|
7
7
|
class Base
|
8
|
-
|
9
|
-
|
10
|
-
def self.from_cbor(cbor)
|
8
|
+
def self.deserialize(cbor)
|
11
9
|
from_map(CBOR.decode(cbor))
|
12
10
|
end
|
13
11
|
|
14
12
|
def self.enforce_type(map, kty, error_message)
|
15
|
-
if map[
|
13
|
+
if map[LABEL_KTY] != kty
|
16
14
|
raise error_message
|
17
15
|
end
|
18
16
|
end
|
data/lib/cose/key/rsa.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "cose/key/base"
|
4
|
+
|
5
|
+
module COSE
|
6
|
+
module Key
|
7
|
+
class RSA < Base
|
8
|
+
LABEL_N = -1
|
9
|
+
LABEL_E = -2
|
10
|
+
|
11
|
+
KTY_RSA = 3
|
12
|
+
|
13
|
+
attr_reader :modulus_n, :public_exponent_e
|
14
|
+
|
15
|
+
def initialize(modulus_n:, public_exponent_e:)
|
16
|
+
if !modulus_n
|
17
|
+
raise ArgumentError, "Required modulus_n is missing"
|
18
|
+
elsif !public_exponent_e
|
19
|
+
raise ArgumentError, "Required public_exponent_e is missing"
|
20
|
+
else
|
21
|
+
@modulus_n = modulus_n
|
22
|
+
@public_exponent_e = public_exponent_e
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.from_map(map)
|
27
|
+
enforce_type(map, KTY_RSA, "Not an RSA key")
|
28
|
+
|
29
|
+
new(modulus_n: map[LABEL_N], public_exponent_e: map[LABEL_E])
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/cose/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cose
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gonzalo Rodriguez
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-03-
|
12
|
+
date: 2019-03-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cbor
|
@@ -124,8 +124,10 @@ files:
|
|
124
124
|
- lib/cose.rb
|
125
125
|
- lib/cose/encrypt.rb
|
126
126
|
- lib/cose/encrypt0.rb
|
127
|
+
- lib/cose/key.rb
|
127
128
|
- lib/cose/key/base.rb
|
128
129
|
- lib/cose/key/ec2.rb
|
130
|
+
- lib/cose/key/rsa.rb
|
129
131
|
- lib/cose/key/symmetric.rb
|
130
132
|
- lib/cose/mac.rb
|
131
133
|
- lib/cose/mac0.rb
|