1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package io.github.tonywasher.joceanus.gordianknot.impl.bc.sign;
19
20 import io.github.tonywasher.joceanus.gordianknot.api.base.GordianException;
21 import io.github.tonywasher.joceanus.gordianknot.api.digest.spec.GordianDigestSpec;
22 import io.github.tonywasher.joceanus.gordianknot.api.sign.spec.GordianSignatureSpec;
23 import io.github.tonywasher.joceanus.gordianknot.impl.bc.digest.BouncyDigest;
24 import io.github.tonywasher.joceanus.gordianknot.impl.bc.keypair.BouncyKeyPair;
25 import io.github.tonywasher.joceanus.gordianknot.impl.core.base.GordianBaseFactory;
26 import io.github.tonywasher.joceanus.gordianknot.impl.core.sign.GordianCoreSignature;
27 import io.github.tonywasher.joceanus.gordianknot.impl.core.spec.sign.GordianCoreSignatureSpec;
28 import org.bouncycastle.crypto.Digest;
29 import org.bouncycastle.crypto.digests.NullDigest;
30
31
32
33
34 public abstract class BouncyDigestSignature
35 extends GordianCoreSignature {
36
37
38
39 private BouncyDigest theDigest;
40
41
42
43
44
45
46
47
48 BouncyDigestSignature(final GordianBaseFactory pFactory,
49 final GordianSignatureSpec pSpec) throws GordianException {
50 super(pFactory, pSpec);
51 theDigest = pSpec.getSignatureSpec() == null
52 ? new BouncyDigest(null, new NullDigest())
53 : (BouncyDigest) getDigestFactory().createDigest(((GordianCoreSignatureSpec) pSpec).getDigestSpec());
54 }
55
56
57
58
59
60
61
62
63 BouncyDigestSignature(final GordianBaseFactory pFactory,
64 final GordianSignatureSpec pSpec,
65 final Digest pDigest) {
66 super(pFactory, pSpec);
67 theDigest = new BouncyDigest(((GordianCoreSignatureSpec) pSpec).getDigestSpec(), pDigest);
68 }
69
70
71
72
73
74
75
76 protected void setDigest(final GordianDigestSpec pSpec) throws GordianException {
77 theDigest = pSpec == null
78 ? new BouncyDigest(null, new NullDigest())
79 : (BouncyDigest) getDigestFactory().createDigest(pSpec);
80 }
81
82 @Override
83 public void update(final byte[] pBytes,
84 final int pOffset,
85 final int pLength) {
86 theDigest.update(pBytes, pOffset, pLength);
87 }
88
89 @Override
90 public void update(final byte pByte) {
91 theDigest.update(pByte);
92 }
93
94 @Override
95 public void reset() {
96 theDigest.reset();
97 }
98
99
100
101
102
103
104 protected byte[] getDigest() {
105 return theDigest.finish();
106 }
107
108 @Override
109 protected BouncyKeyPair getKeyPair() {
110 return (BouncyKeyPair) super.getKeyPair();
111 }
112 }