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

org.bouncycastle.openpgp.PGPExtendedKeyAttribute Maven / Gradle / Ivy

Go to download

The Bouncy Castle Java APIs for the OpenPGP Protocol. 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.9
Show newest version
package org.bouncycastle.openpgp;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

import org.bouncycastle.gpg.SExpression;

public class PGPExtendedKeyAttribute
{
    private final List values;

    public List getValues()
    {
        return values;
    }

    private PGPExtendedKeyAttribute(List values)
    {
        this.values = values;
    }

    public static Builder builder()
    {
        return new Builder();
    }

    public static class Builder
    {

        ArrayList values = new ArrayList();

        public Builder addAttribute(Object value)
        {
            if (value instanceof String || value instanceof SExpression.QuotedString)
            {
                this.values.add(value.toString());
            }
            else if (value instanceof byte[])
            {
                this.values.add(value);
            }
            else if (value instanceof SExpression)
            {
                Builder b = new Builder();
                for (Iterator it = ((SExpression)value).getValues().iterator(); it.hasNext();)
                {
                    b.addAttribute(it.next());
                }
                this.values.add(b.build());
            }
            else
            {
                throw new IllegalArgumentException("expected either string or SExpression object.");
            }

            return this;
        }

        public PGPExtendedKeyAttribute build()
        {
            return new PGPExtendedKeyAttribute(Collections.unmodifiableList(values));
        }

    }


}