Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'pkix/src/test/java/org/spongycastle/tsp/test/SHA256DigestCalculator.java')
-rw-r--r--pkix/src/test/java/org/spongycastle/tsp/test/SHA256DigestCalculator.java44
1 files changed, 44 insertions, 0 deletions
diff --git a/pkix/src/test/java/org/spongycastle/tsp/test/SHA256DigestCalculator.java b/pkix/src/test/java/org/spongycastle/tsp/test/SHA256DigestCalculator.java
new file mode 100644
index 00000000..ee5fc3d9
--- /dev/null
+++ b/pkix/src/test/java/org/spongycastle/tsp/test/SHA256DigestCalculator.java
@@ -0,0 +1,44 @@
+package org.spongycastle.tsp.test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
+
+import org.spongycastle.asn1.nist.NISTObjectIdentifiers;
+import org.spongycastle.asn1.x509.AlgorithmIdentifier;
+import org.spongycastle.crypto.Digest;
+import org.spongycastle.crypto.digests.SHA256Digest;
+import org.spongycastle.operator.DigestCalculator;
+
+
+class SHA256DigestCalculator
+ implements DigestCalculator
+{
+ private ByteArrayOutputStream bOut = new ByteArrayOutputStream();
+
+ public AlgorithmIdentifier getAlgorithmIdentifier()
+ {
+ return new AlgorithmIdentifier(NISTObjectIdentifiers.id_sha256);
+ }
+
+ public OutputStream getOutputStream()
+ {
+ return bOut;
+ }
+
+ public byte[] getDigest()
+ {
+ byte[] bytes = bOut.toByteArray();
+
+ bOut.reset();
+
+ Digest sha256 = new SHA256Digest();
+
+ sha256.update(bytes, 0, bytes.length);
+
+ byte[] digest = new byte[sha256.getDigestSize()];
+
+ sha256.doFinal(digest, 0);
+
+ return digest;
+ }
+}