aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/gnunet/util/PeerIdentity.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/gnunet/util/PeerIdentity.java')
-rw-r--r--src/main/java/org/gnunet/util/PeerIdentity.java69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/main/java/org/gnunet/util/PeerIdentity.java b/src/main/java/org/gnunet/util/PeerIdentity.java
new file mode 100644
index 0000000..46a67cd
--- /dev/null
+++ b/src/main/java/org/gnunet/util/PeerIdentity.java
@@ -0,0 +1,69 @@
1/*
2 This file is part of GNUnet.
3 (C) 2011, 2012 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19 */
20
21package org.gnunet.util;
22
23
24import org.gnunet.construct.FixedSizeIntegerArray;
25import org.gnunet.construct.Message;
26
27import java.util.Arrays;
28
29
30/**
31 * Identity of a peer, stored as 512-bit public key.
32 */
33public class PeerIdentity implements Message {
34
35 @FixedSizeIntegerArray(length = 64, signed = false, bitSize = 8)
36 public byte[] data;
37
38 static final String HEXES = "0123456789ABCDEF";
39
40 /**
41 * Creates a zero-filled peer identity
42 */
43 public PeerIdentity() {
44 data = new byte[64];
45 }
46
47 public String getHex() {
48 final StringBuilder hex = new StringBuilder( 2 * data.length );
49 for (final byte b : data) {
50 hex.append(HEXES.charAt((b & 0xF0) >> 4))
51 .append(HEXES.charAt((b & 0x0F)));
52 }
53 return hex.toString();
54 }
55
56 public String toString() {
57 return Strings.dataToString(data);
58 }
59
60 @Override
61 public boolean equals(Object obj) {
62 return obj != null && obj instanceof PeerIdentity && Arrays.equals(((PeerIdentity) obj).data, this.data);
63 }
64
65 @Override
66 public int hashCode() {
67 return Arrays.hashCode(data);
68 }
69}