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.
- data/VERSION +1 -1
- data/caren-api.gemspec +1 -1
- data/lib/caren/caren.rb +12 -10
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.9.
|
1
|
+
0.9.4
|
data/caren-api.gemspec
CHANGED
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
|
-
|
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
|
-
|
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.
|
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:
|
272
|
+
hash: -4558201187329960637
|
273
273
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
274
274
|
none: false
|
275
275
|
requirements:
|