cose 0.2.0 → 0.3.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: 110dd14d01e9d95f2204f1f822e79193f0bfe058eaac32550e8db378acb53d56
4
- data.tar.gz: 446fd8dc498be1145266c8582d9b1fe4ad6d416b4a4f8f43dd7fd226fc52f17a
3
+ metadata.gz: 0eb0523fe9b7196988a95f1055ad305d36f6cad45337c344d9b2a55d2f42465e
4
+ data.tar.gz: 181105f066d6797199b8c495dfc3e4552248692e95c360a77fafad4c0a501046
5
5
  SHA512:
6
- metadata.gz: 32a204e8b5675c70900f6b255bf877d6951467b8e9508be9f133d4c5abe3aaad9e91a1e29535c25bded3777feb0a44a1c161a2544809ab0b1ce73a8b151921e5
7
- data.tar.gz: a80dba546e7fdaadddfb1e3fb05a0e8ce3066928d9e415d24268678cd2fd3fd39d03f6dc67b4243911fbdb2a3b7ab7d396f54510e7e72fa77fa79d8ecb797872
6
+ metadata.gz: 423c129d28fca26cdf359deff30dc9cb9a45dce499df15d2607010dc1cbdd4e3aacfb79609d90b6b4e0dff758cf0b375b93cc871a42e4871e89812e04088d0ad
7
+ data.tar.gz: 13add48d5e31fad84eb20d42805163de9a993ccec0b02bc0d6da0b4b19390db55064f58a1446421a227307e62b231d412e73bb7f0bb8919091316911d7a8cc10
data/.gitignore CHANGED
@@ -11,3 +11,5 @@
11
11
  .rspec_status
12
12
 
13
13
  /Gemfile.lock
14
+
15
+ .byebug_history
data/CHANGELOG.md CHANGED
@@ -1,6 +1,19 @@
1
1
  # Changelog
2
2
 
3
- ## [0.2.0] - 2019-03-04
3
+ ## [v0.3.0] - 2019-03-09
4
+
5
+ ### Added
6
+
7
+ - Support deserialization of security messages:
8
+ - COSE_Sign
9
+ - COSE_Sign1
10
+ - COSE_Mac
11
+ - COSE_Mac0
12
+ - COSE_Encrypt
13
+ - COSE_Encrypt0
14
+ - Works with ruby 2.6
15
+
16
+ ## [v0.2.0] - 2019-03-04
4
17
 
5
18
  ### Added
6
19
 
@@ -15,5 +28,6 @@
15
28
  - EC2 key object
16
29
  - Works with ruby 2.5
17
30
 
18
- [v0.2.0]: https://github.com/cedarcode/cose-ruby/compare/v0.1.0...v.0.2.0/
31
+ [v0.3.0]: https://github.com/cedarcode/cose-ruby/compare/v0.2.0...v0.3.0/
32
+ [v0.2.0]: https://github.com/cedarcode/cose-ruby/compare/v0.1.0...v0.2.0/
19
33
  [v0.1.0]: https://github.com/cedarcode/cose-ruby/compare/5725d9b5db978f19a21bd59182f092d31a118eff...v0.1.0/
data/README.md CHANGED
@@ -50,15 +50,118 @@ key.key_value
50
50
 
51
51
  ### Signing Objects
52
52
 
53
- _Pending_
53
+ #### COSE_Sign
54
+
55
+ ```ruby
56
+ cbor_data = "..."
57
+
58
+ sign = COSE::Sign.deserialize(cbor_data)
59
+
60
+ sign.protected_headers
61
+ sign.unprotected_headers
62
+ sign.payload
63
+
64
+ sign.signatures.each do |signature|
65
+ signature.protected_headers
66
+ signature.unprotected_headers
67
+ signature.signature
68
+ end
69
+ ```
70
+
71
+ #### COSE_Sign1
72
+
73
+ ```ruby
74
+ cbor_data = "..."
75
+
76
+ sign1 = COSE::Sign1.deserialize(cbor_data)
77
+
78
+ sign1.protected_headers
79
+ sign1.unprotected_headers
80
+ sign1.payload
81
+ sign1.signature
82
+ ```
54
83
 
55
84
  ### MAC Objects
56
85
 
57
- _Pending_
86
+ #### COSE_Mac
87
+
88
+ ```ruby
89
+ cbor_data = "..."
90
+
91
+ mac = COSE::Mac.deserialize(cbor_data)
92
+
93
+ mac.protected_headers
94
+ mac.unprotected_headers
95
+ mac.payload
96
+ mac.tag
97
+
98
+ mac.recipients.each do |recipient|
99
+ recipient.protected_headers
100
+ recipient.unprotected_headers
101
+ recipient.ciphertext
102
+
103
+ if recipient.recipients
104
+ recipient.recipients.each do |recipient|
105
+ recipient.protected_headers
106
+ recipient.unprotected_headers
107
+ recipient.ciphertext
108
+ end
109
+ end
110
+ end
111
+ ```
112
+
113
+ #### COSE_Mac0
114
+
115
+ ```ruby
116
+ cbor_data = "..."
117
+
118
+ mac0 = COSE::Mac0.deserialize(cbor_data)
119
+
120
+ mac0.protected_headers
121
+ mac0.unprotected_headers
122
+ mac0.payload
123
+ mac0.tag
124
+ ```
58
125
 
59
126
  ### Encryption Objects
60
127
 
61
- _Pending_
128
+ #### COSE_Encrypt
129
+
130
+ ```ruby
131
+ cbor_data = "..."
132
+
133
+ encrypt = COSE::Encrypt.deserialize(cbor_data)
134
+
135
+ encrypt.protected_headers
136
+ encrypt.unprotected_headers
137
+ encrypt.ciphertext
138
+
139
+ encrypt.recipients.each do |recipient|
140
+ recipient.protected_headers
141
+ recipient.unprotected_headers
142
+ recipient.ciphertext
143
+
144
+ if recipient.recipients
145
+ recipient.recipients.each do |recipient|
146
+ recipient.protected_headers
147
+ recipient.unprotected_headers
148
+ recipient.ciphertext
149
+ end
150
+ end
151
+ end
152
+ ```
153
+
154
+ #### COSE_Encrypt0
155
+
156
+ ```ruby
157
+ cbor_data = "..."
158
+
159
+ encrypt0 = COSE::Encrypt0.deserialize(cbor_data)
160
+
161
+ encrypt0.protected_headers
162
+ encrypt0.unprotected_headers
163
+ encrypt0.ciphertext
164
+ ```
62
165
 
63
166
  ## Development
64
167
 
data/cose.gemspec CHANGED
@@ -34,8 +34,8 @@ Gem::Specification.new do |spec|
34
34
  spec.add_dependency "cbor", "~> 0.5.9.2"
35
35
 
36
36
  spec.add_development_dependency "bundler", ">= 1.17", "< 3"
37
- spec.add_development_dependency "byebug", "~> 10.0"
37
+ spec.add_development_dependency "byebug", "~> 11.0"
38
38
  spec.add_development_dependency "rake", "~> 12.3"
39
39
  spec.add_development_dependency "rspec", "~> 3.8"
40
- spec.add_development_dependency "rubocop", "0.58.2"
40
+ spec.add_development_dependency "rubocop", "0.65.0"
41
41
  end
@@ -0,0 +1,19 @@
1
+ require "cose/security_message"
2
+ require "cose/recipient"
3
+
4
+ module COSE
5
+ class Encrypt < SecurityMessage
6
+ attr_reader :ciphertext, :recipients
7
+
8
+ def self.keyword_arguments_for_initialize(decoded)
9
+ { ciphertext: decoded[0], recipients: decoded[1].map { |s| COSE::Recipient.deserialize(s) } }
10
+ end
11
+
12
+ def initialize(ciphertext:, recipients:, **keyword_arguments)
13
+ super(**keyword_arguments)
14
+
15
+ @ciphertext = ciphertext
16
+ @recipients = recipients
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ require "cose/security_message"
2
+
3
+ module COSE
4
+ class Encrypt0 < SecurityMessage
5
+ attr_reader :ciphertext
6
+
7
+ def self.keyword_arguments_for_initialize(decoded)
8
+ { ciphertext: decoded[0] }
9
+ end
10
+
11
+ def initialize(ciphertext:, **keyword_arguments)
12
+ super(**keyword_arguments)
13
+
14
+ @ciphertext = ciphertext
15
+ end
16
+ end
17
+ end
data/lib/cose/mac.rb ADDED
@@ -0,0 +1,24 @@
1
+ require "cbor"
2
+ require "cose/security_message"
3
+
4
+ module COSE
5
+ class Mac < SecurityMessage
6
+ attr_reader :payload, :tag, :recipients
7
+
8
+ def self.keyword_arguments_for_initialize(decoded)
9
+ {
10
+ payload: CBOR.decode(decoded[0]),
11
+ tag: decoded[1],
12
+ recipients: decoded[2].map { |s| COSE::Recipient.deserialize(s) }
13
+ }
14
+ end
15
+
16
+ def initialize(payload:, tag:, recipients:, **keyword_arguments)
17
+ super(**keyword_arguments)
18
+
19
+ @payload = payload
20
+ @tag = tag
21
+ @recipients = recipients
22
+ end
23
+ end
24
+ end
data/lib/cose/mac0.rb ADDED
@@ -0,0 +1,19 @@
1
+ require "cbor"
2
+ require "cose/security_message"
3
+
4
+ module COSE
5
+ class Mac0 < SecurityMessage
6
+ attr_reader :payload, :tag
7
+
8
+ def self.keyword_arguments_for_initialize(decoded)
9
+ { payload: CBOR.decode(decoded[0]), tag: decoded[1] }
10
+ end
11
+
12
+ def initialize(payload:, tag:, **keyword_arguments)
13
+ super(**keyword_arguments)
14
+
15
+ @payload = payload
16
+ @tag = tag
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,24 @@
1
+ require "cose/security_message"
2
+
3
+ module COSE
4
+ class Recipient < SecurityMessage
5
+ attr_reader :ciphertext, :recipients
6
+
7
+ def self.keyword_arguments_for_initialize(decoded)
8
+ keyword_arguments = { ciphertext: decoded[0] }
9
+
10
+ if decoded[1]
11
+ keyword_arguments[:recipients] = decoded[1].map { |s| COSE::Recipient.deserialize(s) }
12
+ end
13
+
14
+ keyword_arguments
15
+ end
16
+
17
+ def initialize(ciphertext:, recipients: nil, **keyword_arguments)
18
+ super(**keyword_arguments)
19
+
20
+ @ciphertext = ciphertext
21
+ @recipients = recipients
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,26 @@
1
+ require "cbor"
2
+
3
+ module COSE
4
+ class SecurityMessage
5
+ attr_reader :protected_headers, :unprotected_headers
6
+
7
+ def self.deserialize(cbor)
8
+ decoded = CBOR.decode(cbor)
9
+
10
+ if decoded.respond_to?(:value)
11
+ decoded = decoded.value
12
+ end
13
+
14
+ new(
15
+ protected_headers: CBOR.decode(decoded[0]),
16
+ unprotected_headers: decoded[1],
17
+ **keyword_arguments_for_initialize(decoded[2..-1])
18
+ )
19
+ end
20
+
21
+ def initialize(protected_headers:, unprotected_headers:)
22
+ @protected_headers = protected_headers
23
+ @unprotected_headers = unprotected_headers
24
+ end
25
+ end
26
+ end
data/lib/cose/sign.rb ADDED
@@ -0,0 +1,20 @@
1
+ require "cbor"
2
+ require "cose/security_message"
3
+ require "cose/signature"
4
+
5
+ module COSE
6
+ class Sign < SecurityMessage
7
+ attr_reader :payload, :signatures
8
+
9
+ def self.keyword_arguments_for_initialize(decoded)
10
+ { payload: CBOR.decode(decoded[0]), signatures: decoded[1].map { |s| COSE::Signature.deserialize(s) } }
11
+ end
12
+
13
+ def initialize(payload:, signatures:, **keyword_arguments)
14
+ super(**keyword_arguments)
15
+
16
+ @payload = payload
17
+ @signatures = signatures
18
+ end
19
+ end
20
+ end
data/lib/cose/sign1.rb ADDED
@@ -0,0 +1,19 @@
1
+ require "cbor"
2
+ require "cose/security_message"
3
+
4
+ module COSE
5
+ class Sign1 < SecurityMessage
6
+ attr_reader :payload, :signature
7
+
8
+ def self.keyword_arguments_for_initialize(decoded)
9
+ { payload: CBOR.decode(decoded[0]), signature: decoded[1] }
10
+ end
11
+
12
+ def initialize(payload:, signature:, **keyword_arguments)
13
+ super(**keyword_arguments)
14
+
15
+ @payload = payload
16
+ @signature = signature
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ require "cose/security_message"
2
+
3
+ module COSE
4
+ class Signature < SecurityMessage
5
+ attr_reader :signature
6
+
7
+ def self.keyword_arguments_for_initialize(decoded)
8
+ { signature: decoded[0] }
9
+ end
10
+
11
+ def initialize(signature:, **keyword_arguments)
12
+ super(**keyword_arguments)
13
+
14
+ @signature = signature
15
+ end
16
+ end
17
+ end
data/lib/cose/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module COSE
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
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.2.0
4
+ version: 0.3.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-04 00:00:00.000000000 Z
12
+ date: 2019-03-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cbor
@@ -51,14 +51,14 @@ dependencies:
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: '11.0'
55
55
  type: :development
56
56
  prerelease: false
57
57
  version_requirements: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '10.0'
61
+ version: '11.0'
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: rake
64
64
  requirement: !ruby/object:Gem::Requirement
@@ -93,14 +93,14 @@ dependencies:
93
93
  requirements:
94
94
  - - '='
95
95
  - !ruby/object:Gem::Version
96
- version: 0.58.2
96
+ version: 0.65.0
97
97
  type: :development
98
98
  prerelease: false
99
99
  version_requirements: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - '='
102
102
  - !ruby/object:Gem::Version
103
- version: 0.58.2
103
+ version: 0.65.0
104
104
  description:
105
105
  email:
106
106
  - gonzalo@cedarcode.com
@@ -122,9 +122,18 @@ files:
122
122
  - bin/setup
123
123
  - cose.gemspec
124
124
  - lib/cose.rb
125
+ - lib/cose/encrypt.rb
126
+ - lib/cose/encrypt0.rb
125
127
  - lib/cose/key/base.rb
126
128
  - lib/cose/key/ec2.rb
127
129
  - lib/cose/key/symmetric.rb
130
+ - lib/cose/mac.rb
131
+ - lib/cose/mac0.rb
132
+ - lib/cose/recipient.rb
133
+ - lib/cose/security_message.rb
134
+ - lib/cose/sign.rb
135
+ - lib/cose/sign1.rb
136
+ - lib/cose/signature.rb
128
137
  - lib/cose/version.rb
129
138
  homepage: https://github.com/cedarcode/cose-ruby
130
139
  licenses:
@@ -148,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
157
  - !ruby/object:Gem::Version
149
158
  version: '0'
150
159
  requirements: []
151
- rubygems_version: 3.0.2
160
+ rubygems_version: 3.0.3
152
161
  signing_key:
153
162
  specification_version: 4
154
163
  summary: COSE (RFC 8152) ruby library