Moved stream crypto to crypto component.

This commit is contained in:
akwizgran
2014-12-29 19:55:05 +00:00
parent 02a485ace0
commit f316d64afa
33 changed files with 504 additions and 354 deletions

View File

@@ -0,0 +1,14 @@
package org.briarproject.api.crypto;
import java.io.IOException;
public interface StreamDecrypter {
/**
* Reads a frame, decrypts its payload into the given buffer and returns
* the payload length, or -1 if no more frames can be read from the stream.
* @throws java.io.IOException if an error occurs while reading the frame,
* or if authenticated decryption fails.
*/
int readFrame(byte[] payload) throws IOException;
}

View File

@@ -0,0 +1,18 @@
package org.briarproject.api.crypto;
import java.io.InputStream;
import org.briarproject.api.transport.StreamContext;
public interface StreamDecrypterFactory {
/** Creates a {@link StreamDecrypter} for decrypting a transport stream. */
StreamDecrypter createStreamDecrypter(InputStream in, int maxFrameLength,
StreamContext ctx);
/**
* Creates a {@link StreamDecrypter} for decrypting an invitation stream.
*/
StreamDecrypter createInvitationStreamDecrypter(InputStream in,
int maxFrameLength, byte[] secret, boolean alice);
}

View File

@@ -0,0 +1,13 @@
package org.briarproject.api.crypto;
import java.io.IOException;
public interface StreamEncrypter {
/** Encrypts the given frame and writes it to the stream. */
void writeFrame(byte[] payload, int payloadLength, boolean finalFrame)
throws IOException;
/** Flushes the stream. */
void flush() throws IOException;
}

View File

@@ -0,0 +1,18 @@
package org.briarproject.api.crypto;
import java.io.OutputStream;
import org.briarproject.api.transport.StreamContext;
public interface StreamEncrypterFactory {
/** Creates a {@link StreamEncrypter} for encrypting a transport stream. */
StreamEncrypter createStreamEncrypter(OutputStream out,
int maxFrameLength, StreamContext ctx);
/**
* Creates a {@link StreamEncrypter} for encrypting an invitation stream.
*/
StreamEncrypter createInvitationStreamEncrypter(OutputStream out,
int maxFrameLength, byte[] secret, boolean alice);
}