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

org.bouncycastle.tls.PskIdentity Maven / Gradle / Ivy

Go to download

The Bouncy Castle Java APIs for the TLS, including a JSSE provider. The APIs are designed primarily to be used in conjunction with the BC FIPS provider. The APIs may also be used with other providers although if being used in a FIPS context it is the responsibility of the user to ensure that any other providers used are FIPS certified and used appropriately.

There is a newer version: 2.0.19
Show newest version
package org.bouncycastle.tls;

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

public class PskIdentity
{
    protected byte[] identity;
    protected long obfuscatedTicketAge;

    public PskIdentity(byte[] identity, long obfuscatedTicketAge)
    {
        if (null == identity)
        {
            throw new IllegalArgumentException("'identity' cannot be null");
        }
        if (identity.length < 1 || !TlsUtils.isValidUint16(identity.length))
        {
            throw new IllegalArgumentException("'identity' should have length from 1 to 65535");
        }
        if (!TlsUtils.isValidUint32(obfuscatedTicketAge))
        {
            throw new IllegalArgumentException("'obfuscatedTicketAge' should be a uint32");
        }

        this.identity = identity;
        this.obfuscatedTicketAge = obfuscatedTicketAge;
    }

    public byte[] getIdentity()
    {
        return identity;
    }

    public long getObfuscatedTicketAge()
    {
        return obfuscatedTicketAge;
    }

    public void encode(OutputStream output) throws IOException
    {
        TlsUtils.writeOpaque16(identity, output);
        TlsUtils.writeUint32(obfuscatedTicketAge, output);
    }

    public static PskIdentity parse(InputStream input) throws IOException
    {
        byte[] identity = TlsUtils.readOpaque16(input, 1);
        long obfuscatedTicketAge = TlsUtils.readUint32(input);
        return new PskIdentity(identity, obfuscatedTicketAge);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy