module Suzuri
Defined in:
suzuri.crClass Method Summary
-
.decode(token : String, key : String | Bytes, ttl : Time::Span | Nil = nil) : Token
Decodes a Suzuri token.
-
.encode(payload : String | Bytes, key : String | Bytes, timestamp : Time = Time.utc, compress_level = 3, compress_threshold : UInt64 = 512) : String
Encodes a Suzuri token.
Class Method Detail
Decodes a Suzuri token.
Examples:
# Decode
Suzuri.decode(token, KEY) # => Suzuri::Token
# Decode with a ttl constraint
Suzuri.decode(token, KEY, 5.minutes) # => Suzuri::Error::TokenExpired
def self.encode(payload : String | Bytes, key : String | Bytes, timestamp : Time = Time.utc, compress_level = 3, compress_threshold : UInt64 = 512) : String
#
Encodes a Suzuri token.
Examples:
# Encode
Suzuri.encode("hello world", KEY) # => "wB3AKYBaTwJc..."
# Encode with compression disabled
Suzuri.encode("hello world", KEY, compress_threshold: UInt64::MAX) # => "xAJyiEKfPLPi..."
# Encode with a custom creation timestamp
Suzuri.encode("hello world", KEY, Time.utc(1985-10-26)) # => "mArTYmcfLyYy..."
# Encode with a higher compression level. Value can be 1-19. Default is 3.
Suzuri.encode("hello world", KEY, compress_level: 10) # => "puI8lSpoAox5..."