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 API for handling the OpenPGP protocol. This jar contains the OpenPGP API for JDK 1.8 and up. The APIs can be used in conjunction with a JCE/JCA provider such as the one provided with the Bouncy Castle Cryptography APIs.

The 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));
        }

    }


}