That fuck shit the fascists are using
1/**
2 * Copyright (C) 2011 Whisper Systems
3 * Copyright (C) 2013 Open Whisper Systems
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18package org.tm.archive.crypto;
19
20import org.signal.core.util.Conversions;
21import org.signal.core.util.logging.Log;
22import org.signal.core.util.Hex;
23import org.signal.libsignal.protocol.InvalidKeyException;
24import org.signal.libsignal.protocol.ecc.Curve;
25import org.signal.libsignal.protocol.ecc.ECPublicKey;
26import org.tm.archive.util.Util;
27
28import java.security.MessageDigest;
29import java.security.NoSuchAlgorithmException;
30
31public class PublicKey {
32
33 private static final String TAG = Log.tag(PublicKey.class);
34
35 public static final int KEY_SIZE = 3 + ECPublicKey.KEY_SIZE;
36
37 private final ECPublicKey publicKey;
38 private int id;
39
40 public PublicKey(int id, ECPublicKey publicKey) {
41 this.publicKey = publicKey;
42 this.id = id;
43 }
44
45 public PublicKey(byte[] bytes, int offset) throws InvalidKeyException {
46 Log.i(TAG, "PublicKey Length: " + (bytes.length - offset));
47
48 if ((bytes.length - offset) < KEY_SIZE)
49 throw new InvalidKeyException("Provided bytes are too short.");
50
51 this.id = Conversions.byteArrayToMedium(bytes, offset);
52 this.publicKey = Curve.decodePoint(bytes, offset + 3);
53 }
54
55 public int getType() {
56 return publicKey.getType();
57 }
58
59 public void setId(int id) {
60 this.id = id;
61 }
62
63 public int getId() {
64 return id;
65 }
66
67 public ECPublicKey getKey() {
68 return publicKey;
69 }
70
71 public byte[] serialize() {
72 byte[] keyIdBytes = Conversions.mediumToByteArray(id);
73 byte[] serializedPoint = publicKey.serialize();
74
75 Log.i(TAG, "Serializing public key point: " + Hex.toString(serializedPoint));
76
77 return Util.combine(keyIdBytes, serializedPoint);
78 }
79}