Class: Fernet::Verifier
- Inherits:
-
Object
- Object
- Fernet::Verifier
- Defined in:
- lib/fernet/verifier.rb
Overview
Public: verifies Fernet Tokens
Defined Under Namespace
Classes: UnknownTokenVersion
Instance Attribute Summary collapse
-
#enforce_ttl ⇒ Object
Returns the value of attribute enforce_ttl.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#ttl ⇒ Object
Returns the value of attribute ttl.
Instance Method Summary collapse
-
#data ⇒ Object
Deprecated: returns the token’s message.
-
#initialize(opts = {}) ⇒ Verifier
constructor
Internal: initializes a Verifier.
-
#inspect ⇒ Object
(also: #to_s)
Public: String representation of this verifier, masks the secret to avoid leaks.
-
#message ⇒ Object
Public: Returns the token’s message.
-
#valid? ⇒ Boolean
Public: whether the verifier is valid.
Constructor Details
#initialize(opts = {}) ⇒ Verifier
Internal: initializes a Verifier
opts - a hash containing
-
secret - the secret used to create the token (required)
-
token - the fernet token string (required)
-
enforce_ttl - whether to enforce TTL, defaults to Configuration.enforce_ttl
-
ttl - number of seconds the token is valid
22 23 24 25 26 |
# File 'lib/fernet/verifier.rb', line 22 def initialize(opts = {}) @enforce_ttl = opts.has_key?(:enforce_ttl) ? opts[:enforce_ttl] : Configuration.enforce_ttl @opts = opts create_token! end |
Instance Attribute Details
#enforce_ttl ⇒ Object
Returns the value of attribute enforce_ttl.
12 13 14 |
# File 'lib/fernet/verifier.rb', line 12 def enforce_ttl @enforce_ttl end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
12 13 14 |
# File 'lib/fernet/verifier.rb', line 12 def token @token end |
#ttl ⇒ Object
Returns the value of attribute ttl.
13 14 15 |
# File 'lib/fernet/verifier.rb', line 13 def ttl @ttl end |
Instance Method Details
#data ⇒ Object
Deprecated: returns the token’s message
42 43 44 45 |
# File 'lib/fernet/verifier.rb', line 42 def data puts "[WARNING] data is deprecated. Use message instead" end |
#inspect ⇒ Object Also known as: to_s
Public: String representation of this verifier, masks the secret to avoid
leaks
49 50 51 |
# File 'lib/fernet/verifier.rb', line 49 def inspect "#<Fernet::Verifier @secret=[masked] @token=#{@token} @message=#{@message.inspect} @ttl=#{@ttl} @enforce_ttl=#{@enforce_ttl}>" end |
#message ⇒ Object
Public: Returns the token’s message
37 38 39 |
# File 'lib/fernet/verifier.rb', line 37 def @token..dup.force_encoding(Encoding::UTF_8) end |
#valid? ⇒ Boolean
Public: whether the verifier is valid. A verifier is valid if it’s token
is valid.
Returns a boolean set to true if the token is valid, false otherwise
32 33 34 |
# File 'lib/fernet/verifier.rb', line 32 def valid? @token.valid? end |