All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.jsonwebtoken.impl.lang.Converters Maven / Gradle / Ivy

/*
 * Copyright © 2020 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.impl.lang;

import io.jsonwebtoken.impl.io.Codec;
import io.jsonwebtoken.impl.security.JwtX509StringConverter;

import java.math.BigInteger;
import java.net.URI;
import java.security.cert.X509Certificate;
import java.util.List;
import java.util.Set;

public final class Converters {

    public static final Converter URI = Converters.forEncoded(URI.class, new UriStringConverter());

    public static final Converter BASE64URL_BYTES = Converters.forEncoded(byte[].class, Codec.BASE64URL);

    public static final Converter X509_CERTIFICATE =
            Converters.forEncoded(X509Certificate.class, JwtX509StringConverter.INSTANCE);

    public static final Converter BIGINT_UBYTES = new BigIntegerUBytesConverter();
    public static final Converter BIGINT = Converters.forEncoded(BigInteger.class,
            compound(BIGINT_UBYTES, Codec.BASE64URL));

    //prevent instantiation
    private Converters() {
    }

    public static  Converter forType(Class clazz) {
        return new RequiredTypeConverter<>(clazz);
    }

    public static  Converter, Object> forSet(Converter elementConverter) {
        return CollectionConverter.forSet(elementConverter);
    }

    public static  Converter, Object> forList(Converter elementConverter) {
        return CollectionConverter.forList(elementConverter);
    }

    public static  Converter forEncoded(Class elementType, Converter elementConverter) {
        return new EncodedObjectConverter<>(elementType, elementConverter);
    }

    public static  Converter compound(final Converter aConv, final Converter bConv) {
        return new CompoundConverter<>(aConv, bConv);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy