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 LTS provider but may also be used with other providers providing cryptographic services.

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

    }


}