Class: Imageproxy::Signature
- Inherits:
-
Object
- Object
- Imageproxy::Signature
- Defined in:
- lib/imageproxy/signature.rb
Class Method Summary collapse
- .correct?(signature, path, secret) ⇒ Boolean
- .create(path, secret) ⇒ Object
- .remove_signature_from(path) ⇒ Object
Class Method Details
.correct?(signature, path, secret) ⇒ Boolean
21 22 23 24 |
# File 'lib/imageproxy/signature.rb', line 21 def self.correct?(signature, path, secret) created = create(path, secret) signature != nil && path != nil && secret != nil && (created == signature || created == signature.tr('+/', '-_')) end |
.create(path, secret) ⇒ Object
6 7 8 |
# File 'lib/imageproxy/signature.rb', line 6 def self.create(path, secret) Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'), secret, remove_signature_from(path))).strip.tr('+/', '-_') end |
.remove_signature_from(path) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/imageproxy/signature.rb', line 10 def self.remove_signature_from(path) #TODO: do this in fewer passes path. sub(%r{&signature(=[^&]*)?(?=&|$)}, ""). sub(%r{\?signature(=[^&]*)?&}, "?"). sub(%r{\?signature(=[^&]*)?$}, ""). sub(%r{/signature/[^\?/]+/}, "/"). sub(%r{/signature/[^\?/]+\?}, "?"). sub(%r{/signature/[^\?/]+}, "") end |