Commit b0550e04 authored by toaster's avatar toaster
Browse files

token store operations

git-svn-id: https://subversion.umiacs.umd.edu/ace/trunk@27 f1b3a171-7291-4a19-a512-95ad0ad9394a
parent 23ba20c1
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.umiacs.ace.ims.api;
import edu.umiacs.ace.ims.ws.ProofElement;
import edu.umiacs.ace.ims.ws.TokenResponse;
import edu.umiacs.ace.token.AceToken;
import edu.umiacs.ace.token.AceTokenBuilder;
import edu.umiacs.ace.util.HashValue;
/**
*
* @author toaster
*/
public class IMSUtil {
private static ThreadLocal<AceTokenBuilder> tokenBuilder = new ThreadLocal<AceTokenBuilder>()
{
@Override
protected AceTokenBuilder initialValue() {
return new AceTokenBuilder();
}
};
public static AceToken convertResponse(TokenResponse response, String ims) {
AceTokenBuilder bldr = tokenBuilder.get();
bldr.setDate(response.getTimestamp().toGregorianCalendar().getTime());
bldr.setDigestAlgorithm(response.getDigestService());
bldr.setRound(response.getRoundId());
bldr.setIms(ims);
bldr.setImsService(response.getTokenClassName());
for (ProofElement pe : response.getProofElements())
{
bldr.startProofLevel(pe.getHashes().size() + 1);
bldr.setLevelInheritIndex(pe.getIndex());
for (String hash : pe.getHashes())
{
bldr.addLevelHash(HashValue.asBytes(hash));
}
}
return bldr.createToken();
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.umiacs.ace.ims.api;
import edu.umiacs.ace.ims.ws.ProofElement;
import edu.umiacs.ace.ims.ws.TokenResponse;
import edu.umiacs.ace.token.TokenStoreWriter;
import java.io.OutputStream;
/**
*
* @author toaster
*/
public class TokenResponseStoreWriter extends TokenStoreWriter<TokenResponse> {
private String ims;
public TokenResponseStoreWriter( OutputStream os, String ims ) {
super(os);
this.ims = ims;
}
@Override
public void startToken( TokenResponse token ) {
setHeaderInformation(token.getDigestService(), ims,
token.getTokenClassName(), token.getRoundId(), token.getTimestamp());
for ( ProofElement pe : token.getProofElements() ) {
addHashLevel(pe.getIndex(), pe.getHashes());
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment