samples/messagedigest/src-test/test/CountingDigestor.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:52:23 +0200
changeset 44 716af5f2ebd1
child 46 c75861f07646
permissions -rw-r--r--
Switching to freeform project
     1 /*
     2  * To change this template, choose Tools | Templates
     3  * and open the template in the editor.
     4  */
     5 
     6 package test;
     7 
     8 import java.nio.ByteBuffer;
     9 import org.apidesign.spi.security.Digestor;
    10 
    11 /**
    12  *
    13  * @author jarda
    14  */
    15 public final class CountingDigestor extends Digestor<int[]> {
    16 
    17     @Override
    18     protected byte[] digest(int[] data) {
    19         int i = data[0];
    20         byte[] arr = { (byte) (i & 255), (byte) ((i >> 8) & 255), (byte) ((i >> 16) & 255), (byte) ((i >> 24) & 255) };
    21         return arr;
    22     }
    23 
    24     @Override
    25     protected int[] create(String algorithm) {
    26         return "cnt".equals(algorithm) ? new int[1] : null; // NOI18N
    27     }
    28 
    29     @Override
    30     protected void update(int[] data, ByteBuffer input) {
    31         data[0] += input.remaining();
    32         input.position(input.position() + input.remaining());
    33     }
    34 
    35 }