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

org.bouncycastle.openpgp.PGPUserAttributeSubpacketVector 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 org.bouncycastle.bcpg.UserAttributeSubpacket;
import org.bouncycastle.bcpg.UserAttributeSubpacketTags;
import org.bouncycastle.bcpg.UserDataPacket;
import org.bouncycastle.bcpg.attr.ImageAttribute;

/**
 * Container for a list of user attribute subpackets.
 */
public class PGPUserAttributeSubpacketVector implements UserDataPacket
{
    public static PGPUserAttributeSubpacketVector fromSubpackets(UserAttributeSubpacket[] packets)
    {
        if (packets == null)
        {
            packets = new UserAttributeSubpacket[0];
        }
        return new PGPUserAttributeSubpacketVector(packets);
    }

    UserAttributeSubpacket[] packets;

    PGPUserAttributeSubpacketVector(
        UserAttributeSubpacket[]    packets)
    {
        this.packets = packets;
    }

    public UserAttributeSubpacket getSubpacket(
        int    type)
    {
        for (int i = 0; i != packets.length; i++)
        {
            if (packets[i].getType() == type)
            {
                return packets[i];
            }
        }
        
        return null;
    }
    
    public ImageAttribute getImageAttribute()
    {
        UserAttributeSubpacket    p = this.getSubpacket(UserAttributeSubpacketTags.IMAGE_ATTRIBUTE);
        
        if (p == null)
        {
            return null;
        }
                    
        return (ImageAttribute)p;
    }
    
    UserAttributeSubpacket[] toSubpacketArray()
    {
        return packets;
    }
    
    public boolean equals(
        Object o)
    {
        if (o == this)
        {
            return true;
        }
        
        if (o instanceof PGPUserAttributeSubpacketVector)
        {
            PGPUserAttributeSubpacketVector    other = (PGPUserAttributeSubpacketVector)o;
            
            if (other.packets.length != packets.length)
            {
                return false;
            }
            
            for (int i = 0; i != packets.length; i++)
            {
                if (!other.packets[i].equals(packets[i]))
                {
                    return false;
                }
            }
            
            return true;
        }
        
        return false;
    }
    
    public int hashCode()
    {
        int    code = 0;
        
        for (int i = 0; i != packets.length; i++)
        {
            code ^= packets[i].hashCode();
        }
        
        return code;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy