Welcome to mirror list, hosted at ThFree Co, Russian Federation.

PGPUserAttributeSubpacketVector.java « openpgp « spongycastle « org « java « main « src « pg - gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 26d6c7368be2dd5e944939740b69bbedd02303fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package org.spongycastle.openpgp;

import org.spongycastle.bcpg.UserAttributeSubpacket;
import org.spongycastle.bcpg.UserAttributeSubpacketTags;
import org.spongycastle.bcpg.attr.ImageAttribute;

/**
 * Container for a list of user attribute subpackets.
 */
public class PGPUserAttributeSubpacketVector
{
    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;
    }
}