package me.footlights.core.data;

import java.nio.ByteBuffer;


/**
 * Encrypted block data.
 * @author Jonathan Anderson (jon@footlights.me)
 */
public class EncryptedBlock
{
	public static class Builder
	{
		public EncryptedBlock build()
		{
			return new EncryptedBlock(ciphertext, name, link);
		}

		public Builder setCiphertext(ByteBuffer ciphertext)
		{
			this.ciphertext = ciphertext;
			return this;
		}
		public Builder setName(String name)
		{
			this.name = name;
			return this;
		}
		public Builder setLink(Link link)
		{
			this.link = link;
			return this;
		}

		private Builder() {}

		private ByteBuffer ciphertext;
		private String name;
		private Link link;
	}

	public static Builder newBuilder() { return new Builder(); }

	/** The name of the block. */
	public String name() { return name; }

	/** The ciphertext itself. */
	public ByteBuffer ciphertext() { return ciphertext.asReadOnlyBuffer(); }

	/** A link to the ciphertext. */
	public Link link() { return link; }


	private EncryptedBlock(ByteBuffer ciphertext, String name, Link link)
	{
		this.ciphertext = ciphertext.asReadOnlyBuffer();
		this.name = name;
		this.link = link;
	}

	private final ByteBuffer ciphertext;
	private final String name;
	private final Link link;
}

@@ -277,22 +277,16 @@
 hertext,
- name,
  link);%0A
@@ -405,91 +405,8 @@
 %09%09%7D%0A
-%09%09public Builder setName(String name)%0A%09%09%7B%0A%09%09%09this.name = name;%0A%09%09%09return this;%0A%09%09%7D%0A
 %09%09pu
@@ -544,31 +544,8 @@
 xt;%0A
-%09%09private String name;%0A
 %09%09pr
@@ -690,20 +690,37 @@
  return 
-name
+link.uri().toString()
 ; %7D%0A%0A%09/*
@@ -946,21 +946,8 @@
 xt, 
-String name, 
 Link
@@ -955,16 +955,112 @@
 link)%0A%09%7B
+%0A%09%09if (link == null) throw new NullPointerException(%22Link to EncryptedBlock must not be null%22);%0A
 %0A%09%09this.
@@ -1107,28 +1107,8 @@
 ();%0A
-%09%09this.name = name;%0A
 %09%09th
@@ -1169,36 +1169,8 @@
 xt;%0A
-%09private final String name;%0A
 %09pri

Fix names for EncryptedBlock (use Fingerprint).