/*
 * SonarQube
 * Copyright (C) 2009-2023 SonarSource SA
 * mailto:info AT sonarsource DOT com
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
package org.sonar.server.usertoken;

import org.sonar.db.user.TokenType;

public interface TokenGenerator {
  /**
   * Generate a token. It must be unique and non deterministic.<br />
   * Underlying algorithm, format and max length are
   * subject to change in subsequent SonarQube versions.
   * <br/>
   * Length does not exceed 40 characters (arbitrary value).
   * Token is composed of hexadecimal characters only (0-9, a-f)
   * <br/>
   * The token is sent through the userid field (login) of HTTP Basic authentication,
   *
   * Basic authentication is used to authenticate users from tokens, so the
   * constraints of userid field (login) must be respected. Basically the token
   * must not contain colon character ":".
   *
   */
  String generate(TokenType tokenType);

  /**
   * Hash a token.<br/>
   * Underlying algorithm, format and max length are
   * subject to change in subsequent SonarQube versions.
   * <br />
   * Length must not exceed 255 characters.
   * Hash is composed of hexadecimal characters only (0-9, a-f)
   */
  String hash(String token);
}
