jtulach@44: /* jtulach@44: * To change this template, choose Tools | Templates jtulach@44: * and open the template in the editor. jtulach@44: */ jtulach@44: jtulach@44: package test; jtulach@44: jtulach@44: import java.nio.ByteBuffer; jtulach@44: import org.apidesign.spi.security.Digestor; jtulach@44: jtulach@44: /** jtulach@44: * jtulach@50: * @author jarda jtulach@44: */ jtulach@44: public final class CountingDigestor extends Digestor { jtulach@50: jtulach@44: @Override jtulach@44: protected byte[] digest(int[] data) { jtulach@44: int i = data[0]; jtulach@44: byte[] arr = { (byte) (i & 255), (byte) ((i >> 8) & 255), (byte) ((i >> 16) & 255), (byte) ((i >> 24) & 255) }; jtulach@44: return arr; jtulach@44: } jtulach@44: jtulach@44: @Override jtulach@44: protected int[] create(String algorithm) { jtulach@44: return "cnt".equals(algorithm) ? new int[1] : null; // NOI18N jtulach@44: } jtulach@44: jtulach@44: @Override jtulach@44: protected void update(int[] data, ByteBuffer input) { jtulach@44: data[0] += input.remaining(); jtulach@44: input.position(input.position() + input.remaining()); jtulach@44: } jtulach@50: jtulach@44: }