module Suzuri

Defined in:

suzuri.cr

Class Method Summary

Class Method Detail

def self.decode(token : String, key : String | Bytes, ttl : Time::Span? = nil) : Token #

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..."