class Crypt::Signer

Overview

Sign and verify given data.

Defined in:

signer.cr

Constant Summary

INVALID_SIGN = "Not valid"
SIGN_SEP = "__--"

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(secret : String, digest : Symbol = :sha1) #

Create a Signer instance.


[View source]

Class Method Detail

def self.parse_data_and_digest(signed_data) : Tuple(String, String) #

[View source]

Instance Method Detail

def sign(value : String | Bytes) : String #

Generates signed data. Returns an URL and filename safe alphabet (RFC 4648).


[View source]
def valid?(data, digest) : Bool #

Compare data and digest.


[View source]
def verify(signed_data, error_message = INVALID_SIGN) : String #

Verify and decode. error_message allows to customize the error message when the signature is not valid.


[View source]
def verify_and_decode(signed_data : String) : String | Nil #

Verify and decode.

It is recommended to use #verify which has a more precise return (returns String or raises a SignatureError).


[View source]
def verify_raw(signed_data : String, error_message = INVALID_SIGN) : Bytes #

Verify and decode. error_message allows to customize the error message when the signature is not valid.

This method can produce a different error message than error_message.


[View source]
def verify_raw(signed_data : Bytes, error_message = INVALID_SIGN) : Bytes #

Verify and decode. error_message allows to customize the error message when the signature is not valid.

This method can produce a different error message than error_message.


[View source]