def GenerateCSRFToken(user_id, time):
    'Generates a CSRF token based on a secret key, id and time.'
    precondition.AssertType(user_id, Text)
    precondition.AssertOptionalType(time, int)
    time = (time or rdfvalue.RDFDatetime.Now().AsMicrosecondsSinceEpoch())
    secret = config.CONFIG.Get('AdminUI.csrf_secret_key', None)
    if (secret is None):
        raise ValueError('CSRF secret not available.')
    digester = hmac.new(secret.encode('ascii'), digestmod=hashlib.sha256)
    digester.update(user_id.encode('ascii'))
    digester.update(CSRF_DELIMITER)
    digester.update(str(time).encode('ascii'))
    digest = digester.digest()
    token = base64.urlsafe_b64encode((b'%s%s%d' % (digest, CSRF_DELIMITER, time)))
    return token.rstrip(b'=')
Generates a CSRF token based on a secret key, id and time.
def GenerateCSRFToken(user_id, time):
    
    precondition.AssertType(user_id, Text)
    precondition.AssertOptionalType(time, int)
    time = (time or rdfvalue.RDFDatetime.Now().AsMicrosecondsSinceEpoch())
    secret = config.CONFIG.Get('AdminUI.csrf_secret_key', None)
    if (secret is None):
        raise ValueError('CSRF secret not available.')
    digester = hmac.new(secret.encode('ascii'), digestmod=hashlib.sha256)
    digester.update(user_id.encode('ascii'))
    digester.update(CSRF_DELIMITER)
    digester.update(str(time).encode('ascii'))
    digest = digester.digest()
    token = base64.urlsafe_b64encode((b'%s%s%d' % (digest, CSRF_DELIMITER, time)))
    return token.rstrip(b'=')