Package br.net.woodstock.rockframework.security.sign.impl

Source Code of br.net.woodstock.rockframework.security.sign.impl.DelegateTSAClient

/*
* This file is part of rockframework.
*
* rockframework is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* rockframework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>;.
*/
package br.net.woodstock.rockframework.security.sign.impl;

import java.security.GeneralSecurityException;
import java.security.MessageDigest;

import br.net.woodstock.rockframework.core.util.Assert;
import br.net.woodstock.rockframework.security.digest.DigestType;
import br.net.woodstock.rockframework.security.timestamp.TimeStamp;
import br.net.woodstock.rockframework.security.timestamp.TimeStampClient;

import com.itextpdf.text.pdf.security.TSAClient;

public class DelegateTSAClient implements TSAClient {

  private static final int  PADDING_SIZE  = 32;

  private static final int  TOKEN_SIZE    = 4096;

  private TimeStampClient    client;

  private DigestType      digestType;

  private byte[]        timeStampToken;

  private int          tokenSizeEstimate;

  public DelegateTSAClient(final TimeStampClient client, final DigestType digestType) {
    super();
    Assert.notNull(client, "client");
    Assert.notNull(digestType, "digestType");
    this.client = client;
    this.digestType = digestType;

    this.tokenSizeEstimate = DelegateTSAClient.TOKEN_SIZE;
  }

  @Override
  public byte[] getTimeStampToken(final byte[] imprint) throws Exception {
    TimeStamp timeStamp = this.client.getTimeStamp(imprint);
    this.timeStampToken = timeStamp.getEncoded();
    this.tokenSizeEstimate = this.timeStampToken.length + DelegateTSAClient.PADDING_SIZE;
    return this.timeStampToken;
  }

  @Override
  public int getTokenSizeEstimate() {
    return this.tokenSizeEstimate;
  }

  @Override
  public MessageDigest getMessageDigest() throws GeneralSecurityException {
    MessageDigest messageDigest = MessageDigest.getInstance(this.digestType.getAlgorithm());
    return messageDigest;
  }

}
TOP

Related Classes of br.net.woodstock.rockframework.security.sign.impl.DelegateTSAClient

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.