mirror of https://github.com/shred/acme4j
Add a convenience method to write CSR to an OutputStream
parent
ebbec52a6e
commit
7213eede8c
|
@ -14,6 +14,8 @@
|
||||||
package org.shredzone.acme4j.util;
|
package org.shredzone.acme4j.util;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
import java.security.KeyPair;
|
import java.security.KeyPair;
|
||||||
import java.security.PrivateKey;
|
import java.security.PrivateKey;
|
||||||
|
@ -189,7 +191,7 @@ public class CSRBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes the signed certificate request to a file.
|
* Writes the signed certificate request to a {@link Writer}.
|
||||||
*
|
*
|
||||||
* @param w
|
* @param w
|
||||||
* {@link Writer} to write the PEM file to
|
* {@link Writer} to write the PEM file to
|
||||||
|
@ -204,6 +206,16 @@ public class CSRBuilder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes the signed certificate request to an {@link OutputStream}.
|
||||||
|
*
|
||||||
|
* @param out
|
||||||
|
* {@link OutputStream} to write the PEM file to
|
||||||
|
*/
|
||||||
|
public void write(OutputStream out) throws IOException {
|
||||||
|
write(new OutputStreamWriter(out, "utf-8"));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
|
@ -16,6 +16,7 @@ package org.shredzone.acme4j.util;
|
||||||
import static org.hamcrest.Matchers.*;
|
import static org.hamcrest.Matchers.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
@ -180,6 +181,14 @@ public class CSRBuilderTest {
|
||||||
// Verify that both keypairs are the same
|
// Verify that both keypairs are the same
|
||||||
assertThat(builder.getCSR(), not(sameInstance(readCsr)));
|
assertThat(builder.getCSR(), not(sameInstance(readCsr)));
|
||||||
assertThat(builder.getEncoded(), is(equalTo(readCsr.getEncoded())));
|
assertThat(builder.getEncoded(), is(equalTo(readCsr.getEncoded())));
|
||||||
|
|
||||||
|
// OutputStream is identical?
|
||||||
|
byte[] pemBytes;
|
||||||
|
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
|
||||||
|
builder.write(baos);
|
||||||
|
pemBytes = baos.toByteArray();
|
||||||
|
}
|
||||||
|
assertThat(new String(pemBytes, "utf-8"), is(equalTo(pem)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue