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

io.gatling.recorder.internal.bouncycastle.crypto.parsers.XIESPublicKeyParser Maven / Gradle / Ivy

package io.gatling.recorder.internal.bouncycastle.crypto.parsers;

import java.io.IOException;
import java.io.InputStream;

import io.gatling.recorder.internal.bouncycastle.crypto.KeyParser;
import io.gatling.recorder.internal.bouncycastle.crypto.params.AsymmetricKeyParameter;
import io.gatling.recorder.internal.bouncycastle.crypto.params.X25519PublicKeyParameters;
import io.gatling.recorder.internal.bouncycastle.crypto.params.X448PublicKeyParameters;
import io.gatling.recorder.internal.bouncycastle.util.io.Streams;

public class XIESPublicKeyParser
    implements KeyParser
{
    private final boolean isX25519;

    public XIESPublicKeyParser(boolean isX25519)
    {
        this.isX25519 = isX25519;
    }

    public AsymmetricKeyParameter readKey(InputStream stream)
        throws IOException
    {
        int size = isX25519 ? 32 : 56;
        byte[] V = new byte[size];
        
        Streams.readFully(stream, V, 0, V.length);

        // cast due to JVM compatibility
        return isX25519 ? (AsymmetricKeyParameter)new X25519PublicKeyParameters(V, 0) : (AsymmetricKeyParameter)new X448PublicKeyParameters(V, 0);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy