package net.pterodactylus.fcp;
+import com.google.common.base.Charsets;
+
/**
* The “ModifyPeerNote” command modifies a peer note.
*
*/
public class ModifyPeerNote extends FcpMessage {
+ private static final FreenetBase64 BASE64_ENCODER = new FreenetBase64();
+
public ModifyPeerNote(String identifier, String nodeIdentifier) {
super("ModifyPeerNote");
setField("Identifier", identifier);
}
public void setNoteText(String noteText) {
- setField("NoteText", noteText);
+ setField("NoteText", BASE64_ENCODER.encode(noteText.getBytes(Charsets.UTF_8)));
}
public void setPeerNoteType(PeerNoteType peerNoteType) {
package net.pterodactylus.fcp;
+import com.google.common.base.Charsets;
+
/**
* The “PeerNote” message contains a private note that has been entered for a
* darknet peer.
*/
public class PeerNote extends BaseMessage {
+ private static final FreenetBase64 BASE64_DECODER = new FreenetBase64();
+
/** The type for base64 encoded peer notes. */
public static final int TYPE_PRIVATE_PEER_NOTE = 1;
* @return The note text
*/
public String getNoteText() {
- return getField("NoteText");
+ return new String(BASE64_DECODER.decode(getField("NoteText")), Charsets.UTF_8);
}
/**
--- /dev/null
+package net.pterodactylus.fcp;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+
+import org.junit.Test;
+
+/**
+ * Unit test for {@link ModifyPeerNote}.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class ModifyPeerNoteTest {
+
+ private static final String IDENTIFIER = "identifier";
+ private static final String NODE_IDENTIFIER = "node_identifier";
+ private static final String ENCODED_NOTE_TEXT = "VWJlck5vZGUgKHVudGlsIEkgaGF2ZSByZWFsIHBlZXJzKQ==";
+ private static final String DECODED_NOTE_TEXT = "UberNode (until I have real peers)";
+
+ @Test
+ public void noteTextIsEncodedCorrectly() {
+ ModifyPeerNote modifyPeerNote = new ModifyPeerNote(IDENTIFIER, NODE_IDENTIFIER);
+ modifyPeerNote.setNoteText(DECODED_NOTE_TEXT);
+ assertThat(modifyPeerNote.getField("NoteText"), is(ENCODED_NOTE_TEXT));
+ }
+
+
+}
--- /dev/null
+package net.pterodactylus.fcp;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+
+import org.junit.Test;
+
+/**
+ * Unit test for {@link PeerNote}.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class PeerNoteTest {
+
+ @Test
+ public void peerNoteIsDecodedCorrectly() {
+ FcpMessage receivedMessage = new FcpMessage("PeerNote");
+ receivedMessage.setField("NoteText", "VWJlck5vZGUgKHVudGlsIEkgaGF2ZSByZWFsIHBlZXJzKQ==");
+ PeerNote peerNote = new PeerNote(receivedMessage);
+ assertThat(peerNote.getNoteText(), is("UberNode (until I have real peers)"));
+ }
+
+}