aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/linked/RawLinkedIdentity.java
blob: bfde3c3b998c6e3bda84e222834b0cc52c403721 (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
package org.sufficientlysecure.keychain.pgp.linked;

import org.spongycastle.util.Strings;
import org.sufficientlysecure.keychain.pgp.WrappedUserAttribute;

import java.net.URI;
import java.nio.ByteBuffer;

/** The RawLinkedIdentity contains raw parsed data from a Linked Identity subpacket. */
public class RawLinkedIdentity {

    public final int mNonce;
    public final URI mUri;

    protected RawLinkedIdentity(int nonce, URI uri) {
        mNonce = nonce;
        mUri = uri;
    }

    public byte[] getEncoded() {
        byte[] uriData = Strings.toUTF8ByteArray(mUri.toASCIIString());

        ByteBuffer buf = ByteBuffer.allocate(4 + uriData.length);

        buf.putInt(mNonce);
        buf.put(uriData);

        return buf.array();
    }

    public WrappedUserAttribute toUserAttribute () {
        return WrappedUserAttribute.fromSubpacket(WrappedUserAttribute.UAT_LINKED_ID, getEncoded());
    }

    public static int generateNonce() {
        // TODO make this actually random
        // byte[] data = new byte[4];
        // new SecureRandom().nextBytes(data);
        // return Hex.toHexString(data);

        // debug for now
        return 1234567;
    }

}