Class: DynamicImage::DigestVerifier
- Inherits:
-
Object
- Object
- DynamicImage::DigestVerifier
- Defined in:
- lib/dynamic_image/digest_verifier.rb
Overview
DynamicImage Digest Verifier
Signs and verifies the digests embedded in image URLs. The engine sets up the instance the application uses and exposes it as DynamicImage.digest_verifier. The helpers sign with it and the controller verifies with it, so there is rarely a reason to use this directly.
Adapted from ActiveSupport::MessageVerifier, without the handling for arbitrary data structures and without
shipping the serialized data to the client.
Instance Method Summary collapse
-
#generate(data) ⇒ String
Generates a digest for a string.
-
#initialize(secret, options = {}) ⇒ DigestVerifier
constructor
A new instance of DigestVerifier.
-
#verify(data, digest) ⇒ true
Verifies that digest is valid for data.
Constructor Details
#initialize(secret, options = {}) ⇒ DigestVerifier
Returns a new instance of DigestVerifier.
25 26 27 28 |
# File 'lib/dynamic_image/digest_verifier.rb', line 25 def initialize(secret, = {}) @secret = secret @digest = [:digest] || "SHA1" end |
Instance Method Details
#generate(data) ⇒ String
Generates a digest for a string.
34 35 36 |
# File 'lib/dynamic_image/digest_verifier.rb', line 34 def generate(data) generate_digest(data) end |
#verify(data, digest) ⇒ true
Verifies that digest is valid for data.
44 45 46 47 48 |
# File 'lib/dynamic_image/digest_verifier.rb', line 44 def verify(data, digest) return true if valid_digest?(data, digest) raise DynamicImage::Errors::InvalidSignature end |