<commit_before>/*
 * Copyright (C) 2014 jsonwebtoken.io
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.jsonwebtoken;

import java.security.Key;
import java.util.Date;

/**
 * A parser for reading JWT strings, used to convert them into a {@link Jwt} object representing the expanded JWT.
 *
 * @since 0.1
 */
public interface JwtParser {

    public static final char SEPARATOR_CHAR = '.';

    /**
     * Ensures that the specified {@code jti} value is present when parsing the JWT.  If not present,
     * an exception will be thrown indicating that the JWT is invalid and may not be used.
     *
     * @param id
     * @return the parser method for chaining.
     */
    JwtParser requireId(String id);

    /**
     * Ensures that the specified {@code sub} value is present when parsing the JWT.  If not present,
     * an exception will be thrown indicating that the JWT is invalid and may not be used.
     *
     * @param subject
     * @return the parser for method chaining.
     */
    JwtParser requireSubject(String subject);

    /**
     * Ensures that the specified {@code aud} value is present when parsing the JWT.  If not present,
     * an exception will be thrown indicating that the JWT is invalid and may not be used.
     *
     * @param audience
     * @return the parser for method chaining.
     */
    JwtParser requireAudience(String audience);

    /**
     * Ensures that the specified {@code iss} value is present when parsing the JWT.  If not present,
     * an exception will be thrown indicating that the JWT is invalid and may not be used.
     *
     * @param issuer
     * @return the parser for method chaining.
     */
    JwtParser requireIssuer(String issuer);

    /**
     * Ensures that the specified {@code iat} value is present when parsing the JWT.  If not present,
     * an exception will be thrown indicating that the JWT is invalid and may not be used.
     *
     * @param issuedAt
     * @return the parser for method chaining.
     */
    JwtParser requireIssuedAt(Date issuedAt);

    /**
     * Ensures that the specified {@code exp} value is present when parsing the JWT.  If not present,
     * an exception will be thrown indicating that the JWT is invalid and may not be used.
     *
     * @param expiration
     * @return the parser for method chaining.
     */
    JwtParser requireExpiration(Date expiration);

    /**
     * Ensures that the specified {@code nbf} value is present when parsing the JWT.  If not present,
     * an exception will be thrown indicating that the JWT is invalid and may not be used.
     *
     * @param notBefore
     * @return the parser for method chaining
     */
    JwtParser requireNotBefore(Date notBefore);

    /**
     * Ensures that the specified {@code claimName} value is present when parsing the JWT.  If not present,
     * an exception will be thrown indicating that the JWT is invalid and may not be used.
     *
     * If a particular claim is required and the JWT being parsed does not have that claim set,
     * a {@Link MissingClaimException} will be thrown.
     *
     * If a particular claim is required and the JWT being parsed has a value that is different than
     * the required value, a {@link IncorrectClaimException} will be thrown.
     *
     * @param claimName
     * @param value
     * @return the parser for method chaining.
     */
    JwtParser require(String claimName, Object value);

    /**
     * Sets the signing key used to verify any discovered JWS digital signature.  If the specified JWT string is not
     * a JWS (no signature), this key is not used.
     *
     * <p>Note that this key <em>MUST</em> be a valid key for the signature algorithm found in the JWT header
     * (as the {@code alg} header parameter).</p>
     *
     * <p>This method overwrites any previously set key.</p>
     *
     * @param key the algorithm-specific signature verification key used to validate any discovered JWS digital
     *            signature.
     * @return the parser for method chaining.
     */
    JwtParser setSigningKey(byte[] key);

    /**
     * Sets the signing key used to verify any discovered JWS digital signature.  If the specified JWT string is not
     * a JWS (no signature), this key is not used.<commit_msg>Update to javadocs to make more clear.<commit_after>/*
 * Copyright (C) 2014 jsonwebtoken.io
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.jsonwebtoken;

import java.security.Key;
import java.util.Date;

/**
 * A parser for reading JWT strings, used to convert them into a {@link Jwt} object representing the expanded JWT.
 *
 * @since 0.1
 */
public interface JwtParser {

    public static final char SEPARATOR_CHAR = '.';

    /**
     * Ensures that the specified {@code jti} exists in the parsed JWT.  If missing or if the parsed
     * value does not equal the specified value, an exception will be thrown indicating that the
     * JWT is invalid and may not be used.
     *
     * @param id
     * @return the parser method for chaining.
     * @see MissingClaimException
     * @see IncorrectClaimException
     */
    JwtParser requireId(String id);

    /**
     * Ensures that the specified {@code sub} exists in the parsed JWT.  If missing or if the parsed
     * value does not equal the specified value, an exception will be thrown indicating that the
     * JWT is invalid and may not be used.
     *
     * @param subject
     * @return the parser for method chaining.
     * @see MissingClaimException
     * @see IncorrectClaimException
     */
    JwtParser requireSubject(String subject);

    /**
     * Ensures that the specified {@code aud} exists in the parsed JWT.  If missing or if the parsed
     * value does not equal the specified value, an exception will be thrown indicating that the
     * JWT is invalid and may not be used.
     *
     * @param audience
     * @return the parser for method chaining.
     * @see MissingClaimException
     * @see IncorrectClaimException
     */
    JwtParser requireAudience(String audience);

    /**
     * Ensures that the specified {@code iss} exists in the parsed JWT.  If missing or if the parsed
     * value does not equal the specified value, an exception will be thrown indicating that the
     * JWT is invalid and may not be used.
     *
     * @param issuer
     * @return the parser for method chaining.
     * @see MissingClaimException
     * @see IncorrectClaimException
     */
    JwtParser requireIssuer(String issuer);

    /**
     * Ensures that the specified {@code iat} exists in the parsed JWT.  If missing or if the parsed
     * value does not equal the specified value, an exception will be thrown indicating that the
     * JWT is invalid and may not be used.
     *
     * @param issuedAt
     * @return the parser for method chaining.
     * @see MissingClaimException
     * @see IncorrectClaimException
     */
    JwtParser requireIssuedAt(Date issuedAt);

    /**
     * Ensures that the specified {@code exp} exists in the parsed JWT.  If missing or if the parsed
     * value does not equal the specified value, an exception will be thrown indicating that the
     * JWT is invalid and may not be used.
     *
     * @param expiration
     * @return the parser for method chaining.
     * @see MissingClaimException
     * @see IncorrectClaimException
     */
    JwtParser requireExpiration(Date expiration);

    /**
     * Ensures that the specified {@code nbf} exists in the parsed JWT.  If missing or if the parsed
     * value does not equal the specified value, an exception will be thrown indicating that the
     * JWT is invalid and may not be used.
     *
     * @param notBefore
     * @return the parser for method chaining
     * @see MissingClaimException
     * @see IncorrectClaimException
     */
    JwtParser requireNotBefore(Date notBefore);

    /**
     * Ensures that the specified {@code claimName} exists in the parsed JWT.  If missing or if the parsed
     * value does not equal the specified value, an exception will be thrown indicating that the
     * JWT is invalid and may not be used.
     *
     * @param claimName
     * @param value
     * @return the parser for method chaining.
     * @see MissingClaimException
     * @see IncorrectClaimException
     */
    JwtParser require(String claimName, Object value);

    /**
     * Sets the signing key used to verify any discovered JWS digital signature.  If the specified JWT string is not
     * a JWS (no signature), this key is not used.
     *
     * <p>Note that this key <em>MUST</em> be a valid key for the signature algorithm found in the JWT header
     * (as the {@code alg} header parameter).</p>
     *
     * <p>This method overwrites any previously set key.</p>
     *
     * @param key the algorithm-specific signature verification key used to validate any discovered JWS digital
     *            signature.
     * @return the parser for method chaining.
     */
    JwtParser setSigningKey(byte[] key);

    /**
     * Sets the signing key used to verify any discovered JWS digital signature.  If the specified JWT string is not
     * a JWS (no signature), this key is not used.
{'fraction_non_alphanumeric': 0.06769200626959247, 'fraction_numerical': 0.001959247648902821, 'mean_word_length': 2.72863403944485, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7310987', 'n_tokens_mistral': 2728, 'n_tokens_neox': 2665, 'n_words': 1305}