summaryrefslogtreecommitdiff
path: root/src/org/noreply/fancydress/type3/routing/RoutingSMTP.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/noreply/fancydress/type3/routing/RoutingSMTP.java')
-rw-r--r--src/org/noreply/fancydress/type3/routing/RoutingSMTP.java63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/org/noreply/fancydress/type3/routing/RoutingSMTP.java b/src/org/noreply/fancydress/type3/routing/RoutingSMTP.java
new file mode 100644
index 0000000..acfe435
--- /dev/null
+++ b/src/org/noreply/fancydress/type3/routing/RoutingSMTP.java
@@ -0,0 +1,63 @@
+package org.noreply.fancydress.type3.routing;
+
+import org.noreply.fancydress.misc.Util;
+import org.noreply.fancydress.crypto.*;
+
+/**
+ * The SMTP routing as specified in the type III spec.
+ *
+ * SMTP packets are delivered by email by the handling server.
+ *
+ * The payload of a SMTP packet should be constructed according
+ * to the E2E spec.
+ *
+ * @see org.noreply.fancydress.type3.Payload
+ */
+public class RoutingSMTP extends RoutingDestination {
+ /**
+ * Recipient mailbox.
+ */
+ String mailbox;
+
+ /**
+ * Construct an SMTP routing.
+ */
+ public RoutingSMTP(String mailbox) {
+ super (RoutingType.SMTP);
+
+ // FIXME: syntax check mailbox
+
+ this.mailbox = mailbox;
+ }
+
+ /**
+ * Return the total length in octets of the routing information.
+ *
+ * @return total length in octets of the routing information
+ */
+ public int getRoutingInformationLength() {
+ return DECODINGHANDLE_LEN + mailbox.length();
+ }
+
+ /**
+ * Get the routing type of this instance.
+ *
+ * @return routing type
+ */
+ public byte[] getRoutingInformation() {
+ int length = getRoutingInformationLength();
+ byte[] result = new byte[length];
+ int pos = 0;
+
+ System.arraycopy(CryptoPrimitives.rand(DECODINGHANDLE_LEN), 0, result, pos, DECODINGHANDLE_LEN);
+ pos += DECODINGHANDLE_LEN;
+ System.arraycopy(Util.toOctets(mailbox), 0, result, pos, mailbox.length());
+ pos += mailbox.length();
+
+ if (pos != length)
+ throw new Error("Did not fill in expected amount of bytes!");
+
+ return result;
+ }
+}
+