mirror of
https://github.com/google/nomulus.git
synced 2025-06-09 14:04:45 +02:00
Simplify the Ghostryde API
First step of RDE encoding refactoring. Creates a single InputStream (OutputStream) to decode (encode) Ghostryde files. This replaces the 3 InputStreams (OutputStreams) that were needed before. Also removes a lot of classes, and removes the "injection" of the Ghostryde class. It's an encoding, there's no point in injecting it. Finally, removed the buffer-size configuration and replaced with a static final const value. It's just a buffer size - it doesn't actually affect much. There are much more "important" fields that weren't configured (such as the compression algorithm and whether or not to do integrity checks) ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=202319102
This commit is contained in:
parent
bee3d6a5a4
commit
6ff48b7dae
15 changed files with 347 additions and 589 deletions
|
@ -34,7 +34,6 @@ import java.io.IOException;
|
|||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import org.bouncycastle.openpgp.PGPPublicKey;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Rule;
|
||||
import org.junit.experimental.theories.DataPoints;
|
||||
import org.junit.experimental.theories.Theories;
|
||||
|
@ -61,18 +60,6 @@ public class GhostrydeGpgIntegrationTest extends ShardableTestCase {
|
|||
new GpgCommand("gpg2"),
|
||||
};
|
||||
|
||||
@DataPoints
|
||||
public static BufferSize[] bufferSizes = new BufferSize[] {
|
||||
new BufferSize(1),
|
||||
new BufferSize(7),
|
||||
};
|
||||
|
||||
@DataPoints
|
||||
public static Filename[] filenames = new Filename[] {
|
||||
new Filename("lol.txt"),
|
||||
// new Filename("(◕‿◕).txt"), // gpg displays this with zany hex characters.
|
||||
};
|
||||
|
||||
@DataPoints
|
||||
public static Content[] contents = new Content[] {
|
||||
new Content("(◕‿◕)"),
|
||||
|
@ -82,21 +69,16 @@ public class GhostrydeGpgIntegrationTest extends ShardableTestCase {
|
|||
};
|
||||
|
||||
@Theory
|
||||
public void test(GpgCommand cmd, BufferSize bufferSize, Filename filename, Content content)
|
||||
throws Exception {
|
||||
public void test(GpgCommand cmd, Content content) throws Exception {
|
||||
assumeTrue(hasCommand(cmd.get() + " --version"));
|
||||
Keyring keyring = new FakeKeyringModule().get();
|
||||
PGPPublicKey publicKey = keyring.getRdeStagingEncryptionKey();
|
||||
File file = new File(gpg.getCwd(), "love.gpg");
|
||||
byte[] data = content.get().getBytes(UTF_8);
|
||||
DateTime mtime = DateTime.parse("1984-12-18T00:30:00Z");
|
||||
|
||||
Ghostryde ghost = new Ghostryde(bufferSize.get());
|
||||
try (OutputStream output = new FileOutputStream(file);
|
||||
Ghostryde.Encryptor encryptor = ghost.openEncryptor(output, publicKey);
|
||||
Ghostryde.Compressor kompressor = ghost.openCompressor(encryptor);
|
||||
OutputStream os = ghost.openOutput(kompressor, filename.get(), mtime)) {
|
||||
os.write(data);
|
||||
OutputStream ghostrydeEncoder = Ghostryde.encoder(output, publicKey)) {
|
||||
ghostrydeEncoder.write(data);
|
||||
}
|
||||
|
||||
Process pid = gpg.exec(cmd.get(), "--list-packets", "--keyid-format", "long", file.getPath());
|
||||
|
@ -106,13 +88,13 @@ public class GhostrydeGpgIntegrationTest extends ShardableTestCase {
|
|||
assertThat(stdout).contains(":compressed packet:");
|
||||
assertThat(stdout).contains(":encrypted data packet:");
|
||||
assertThat(stdout).contains("version 3, algo 1, keyid A59C132F3589A1D5");
|
||||
assertThat(stdout).contains("name=\"" + filename.get() + "\"");
|
||||
assertThat(stdout).contains("name=\"" + Ghostryde.INNER_FILENAME + "\"");
|
||||
assertThat(stderr).contains("encrypted with 2048-bit RSA key, ID A59C132F3589A1D5");
|
||||
|
||||
pid = gpg.exec(cmd.get(), "--use-embedded-filename", file.getPath());
|
||||
stderr = CharStreams.toString(new InputStreamReader(pid.getErrorStream(), UTF_8));
|
||||
assertWithMessage(stderr).that(pid.waitFor()).isEqualTo(0);
|
||||
File dataFile = new File(gpg.getCwd(), filename.get());
|
||||
File dataFile = new File(gpg.getCwd(), Ghostryde.INNER_FILENAME);
|
||||
assertThat(dataFile.exists()).isTrue();
|
||||
assertThat(slurp(dataFile)).isEqualTo(content.get());
|
||||
}
|
||||
|
@ -133,30 +115,6 @@ public class GhostrydeGpgIntegrationTest extends ShardableTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
private static class BufferSize {
|
||||
private final int value;
|
||||
|
||||
BufferSize(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
int get() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
private static class Filename {
|
||||
private final String value;
|
||||
|
||||
Filename(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
String get() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
private static class Content {
|
||||
private final String value;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue