diff -r 000000000000 -r 716af5f2ebd1 samples/messagedigest/src-test/test/CountingDigestor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/messagedigest/src-test/test/CountingDigestor.java Sat Jun 14 09:52:23 2008 +0200 @@ -0,0 +1,35 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package test; + +import java.nio.ByteBuffer; +import org.apidesign.spi.security.Digestor; + +/** + * + * @author jarda + */ +public final class CountingDigestor extends Digestor { + + @Override + protected byte[] digest(int[] data) { + int i = data[0]; + byte[] arr = { (byte) (i & 255), (byte) ((i >> 8) & 255), (byte) ((i >> 16) & 255), (byte) ((i >> 24) & 255) }; + return arr; + } + + @Override + protected int[] create(String algorithm) { + return "cnt".equals(algorithm) ? new int[1] : null; // NOI18N + } + + @Override + protected void update(int[] data, ByteBuffer input) { + data[0] += input.remaining(); + input.position(input.position() + input.remaining()); + } + +}