@Test public void should_generate_a_time_stamp_request() throws TimeStampException, TSPException, CertificateEncodingException, OperatorCreationException { byte[] hash = new byte[20]; final TimeStampResponse timeStampResponse = mock(TimeStampResponse.class); final ArgumentCaptor<TimeStampRequest> timeStampRequestArgumentCaptor = ArgumentCaptor.forClass(TimeStampRequest.class); given(timeStampSignature.sign(timeStampRequestArgumentCaptor.capture())).willReturn(timeStampResponse); timestampGenerator.generateToken(hash, DigestType.SHA1, BigInteger.TEN); final TimeStampRequest capture = timeStampRequestArgumentCaptor.getValue(); assertThat(capture.getNonce()).isEqualTo(BigInteger.TEN); assertThat(capture.getMessageImprintDigest()).isEqualTo(hash); }
public byte[] generateToken(byte[] hash, DigestType digestType, BigInteger nonce) throws TimeStampException { final TimeStampRequestGenerator reqGen = new TimeStampRequestGenerator(); reqGen.setCertReq(true); final TimeStampRequest request = reqGen.generate(digestToOid(digestType), hash, nonce); try { TimeStampResponse timeStampResponse = timeStampSignature.sign(request); timeStampResponse.validate(request); return timeStampResponse.getEncoded(); } catch (OperatorCreationException | TSPException | CertificateEncodingException | IOException e) { throw new TimeStampException("unable to generate timestamp token", e); } }
TimestampGenerator { public byte[] generateToken(byte[] hash, DigestType digestType, BigInteger nonce) throws TimeStampException { final TimeStampRequestGenerator reqGen = new TimeStampRequestGenerator(); reqGen.setCertReq(true); final TimeStampRequest request = reqGen.generate(digestToOid(digestType), hash, nonce); try { TimeStampResponse timeStampResponse = timeStampSignature.sign(request); timeStampResponse.validate(request); return timeStampResponse.getEncoded(); } catch (OperatorCreationException | TSPException | CertificateEncodingException | IOException e) { throw new TimeStampException("unable to generate timestamp token", e); } } }
TimestampGenerator { public byte[] generateToken(byte[] hash, DigestType digestType, BigInteger nonce) throws TimeStampException { final TimeStampRequestGenerator reqGen = new TimeStampRequestGenerator(); reqGen.setCertReq(true); final TimeStampRequest request = reqGen.generate(digestToOid(digestType), hash, nonce); try { TimeStampResponse timeStampResponse = timeStampSignature.sign(request); timeStampResponse.validate(request); return timeStampResponse.getEncoded(); } catch (OperatorCreationException | TSPException | CertificateEncodingException | IOException e) { throw new TimeStampException("unable to generate timestamp token", e); } } TimestampGenerator(TimeStampSignature timeStampSignature); }
TimestampGenerator { public byte[] generateToken(byte[] hash, DigestType digestType, BigInteger nonce) throws TimeStampException { final TimeStampRequestGenerator reqGen = new TimeStampRequestGenerator(); reqGen.setCertReq(true); final TimeStampRequest request = reqGen.generate(digestToOid(digestType), hash, nonce); try { TimeStampResponse timeStampResponse = timeStampSignature.sign(request); timeStampResponse.validate(request); return timeStampResponse.getEncoded(); } catch (OperatorCreationException | TSPException | CertificateEncodingException | IOException e) { throw new TimeStampException("unable to generate timestamp token", e); } } TimestampGenerator(TimeStampSignature timeStampSignature); byte[] generateToken(byte[] hash, DigestType digestType, BigInteger nonce); }
TimestampGenerator { public byte[] generateToken(byte[] hash, DigestType digestType, BigInteger nonce) throws TimeStampException { final TimeStampRequestGenerator reqGen = new TimeStampRequestGenerator(); reqGen.setCertReq(true); final TimeStampRequest request = reqGen.generate(digestToOid(digestType), hash, nonce); try { TimeStampResponse timeStampResponse = timeStampSignature.sign(request); timeStampResponse.validate(request); return timeStampResponse.getEncoded(); } catch (OperatorCreationException | TSPException | CertificateEncodingException | IOException e) { throw new TimeStampException("unable to generate timestamp token", e); } } TimestampGenerator(TimeStampSignature timeStampSignature); byte[] generateToken(byte[] hash, DigestType digestType, BigInteger nonce);  }