Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closeable ContentSigner #822

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,14 @@ public byte[] getSignature()
{
return contentSigner.getSignature();
}

@Override
public void close() throws Exception
{
output.close();
if (contentSigner != null)
{
contentSigner.close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* General interface for an operator that is able to create a signature from
* a stream of output.
*/
public interface ContentSigner
public interface ContentSigner extends AutoCloseable
{
/**
* Return the algorithm identifier describing the signature
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.bouncycastle.operator.bc;

import java.io.IOException;
import java.io.OutputStream;
import java.security.SecureRandom;
import java.util.Map;
Expand Down Expand Up @@ -51,7 +52,7 @@ public ContentSigner build(AsymmetricKeyParameter privateKey)

return new ContentSigner()
{
private BcSignerOutputStream stream = new BcSignerOutputStream(sig);
private final BcSignerOutputStream stream = new BcSignerOutputStream(sig);

public AlgorithmIdentifier getAlgorithmIdentifier()
{
Expand All @@ -74,6 +75,12 @@ public byte[] getSignature()
throw new RuntimeOperatorException("exception obtaining signature: " + e.getMessage(), e);
}
}

@Override
public void close() throws IOException
{
stream.close();
}
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public ContentSigner build(PrivateKey privateKey)

return new ContentSigner()
{
private OutputStream stream = OutputStreamFactory.createStream(sig);
private final OutputStream stream = OutputStreamFactory.createStream(sig);

public AlgorithmIdentifier getAlgorithmIdentifier()
{
Expand All @@ -148,6 +148,12 @@ public byte[] getSignature()
throw new RuntimeOperatorException("exception obtaining signature: " + e.getMessage(), e);
}
}

@Override
public void close() throws IOException
{
stream.close();
}
};
}
catch (GeneralSecurityException e)
Expand Down Expand Up @@ -189,7 +195,7 @@ private ContentSigner buildComposite(CompositePrivateKey privateKey)

return new ContentSigner()
{
OutputStream stream = sigStream;
final OutputStream stream = sigStream;

public AlgorithmIdentifier getAlgorithmIdentifier()
{
Expand Down Expand Up @@ -223,6 +229,15 @@ public byte[] getSignature()
throw new RuntimeOperatorException("exception obtaining signature: " + e.getMessage(), e);
}
}

@Override
public void close() throws Exception
{
if (stream != null)
{
stream.close();
}
}
};
}
catch (GeneralSecurityException e)
Expand Down