caren-api 0.9.3 → 0.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/caren-api.gemspec +1 -1
  3. data/lib/caren/caren.rb +12 -10
  4. metadata +2 -2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.3
1
+ 0.9.4
data/caren-api.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "caren-api"
8
- s.version = "0.9.3"
8
+ s.version = "0.9.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Andre Foeken"]
data/lib/caren/caren.rb CHANGED
@@ -178,9 +178,7 @@ module Caren
178
178
  # Timestamp is UNIX timestamp seconds since 1970
179
179
  def sign timestamp, path=nil, string=nil, private_key=self.private_key
180
180
  path = URI.parse(path).path if path
181
- encrypted_digest = private_key.sign( DIGEST_ALGORITHMS.first, "#{path}#{string}#{timestamp}".strip )
182
- signature = CGI.escape(Base64.encode64(encrypted_digest))
183
- return signature
181
+ return sign_string("#{path}#{string}#{timestamp}",private_key)
184
182
  end
185
183
 
186
184
  # Check the signature of the response from rest-client
@@ -195,14 +193,8 @@ module Caren
195
193
  verify_string(signature, "#{path}#{string}#{timestamp}", public_key)
196
194
  end
197
195
 
198
- def verify_string provided_string, expected_string, public_key=self.caren_public_key
199
- provided_string = Base64.decode64(CGI.unescape(provided_string.to_s))
200
- DIGEST_ALGORITHMS.map{ |algorithm| public_key.verify( algorithm, provided_string, expected_string.strip ) }.any?
201
- end
202
-
203
196
  def create_photo_signature url_shortcut, external_or_caren_id, private_key=self.private_key
204
- digest = OpenSSL::PKey::RSA.new(private_key).sign( DIGEST_ALGORITHMS.first, url_shortcut.to_s + external_or_caren_id.to_s )
205
- return CGI.escape(Base64.encode64(digest))
197
+ return sign_string(url_shortcut.to_s + external_or_caren_id.to_s, private_key)
206
198
  end
207
199
 
208
200
  # Verify photo url signature using the caren public key
@@ -211,6 +203,16 @@ module Caren
211
203
  verify_string(signature, url_shortcut.to_s + external_id.to_s, public_key)
212
204
  end
213
205
 
206
+ def sign_string provided_string, key=self.private_key
207
+ digest = OpenSSL::PKey::RSA.new(key).sign( DIGEST_ALGORITHMS.first, provided_string.strip )
208
+ return CGI.escape(Base64.encode64(digest))
209
+ end
210
+
211
+ def verify_string provided_string, expected_string, key=self.caren_public_key
212
+ provided_string = Base64.decode64(CGI.unescape(provided_string.to_s))
213
+ DIGEST_ALGORITHMS.map{ |algorithm| key.verify( algorithm, provided_string, expected_string.strip ) }.any?
214
+ end
215
+
214
216
  private
215
217
 
216
218
  # Raise a Caren exception on errors
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caren-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -269,7 +269,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
269
269
  version: '0'
270
270
  segments:
271
271
  - 0
272
- hash: 2880785186653608564
272
+ hash: -4558201187329960637
273
273
  required_rubygems_version: !ruby/object:Gem::Requirement
274
274
  none: false
275
275
  requirements: