import hmac
import hashlib
import base64
import re


def get_cookie(val, secret):
    """Create session cookie string for session ID."""
    # https://docs.python.org/3/library/hmac.html
    _signature = hmac.new(str.encode(secret),
                          msg=str.encode(val),
                          digestmod=hashlib.sha256).digest()
    _signature_enc = base64.b64encode(_signature)
    _cookie = 's:' + val + '.' + _signature_enc.decode()
    _cookie = re.sub(r'\=+$', '', _cookie)  # remove trailing = characters
    return _cookie