samples/messagedigest/src/org/apidesign/spi/security/Digestor.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:52:22 +0200
changeset 43 a161a4cdb597
permissions -rw-r--r--
Repackaging to org.apidesign packages
     1 /*
     2  * To change this template, choose Tools | Templates
     3  * and open the template in the editor.
     4  */
     5 
     6 package org.apidesign.spi.security;
     7 
     8 import org.apidesign.impl.security.spi.DigestorAccessor;
     9 import java.nio.ByteBuffer;
    10 
    11 /**
    12  *
    13  * @author  Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    14  */
    15 public abstract class Digestor<Data> {
    16    protected abstract byte[] digest(Data data);
    17    protected abstract Data create(String algorithm); 
    18    protected abstract void update(Data data, ByteBuffer input);
    19    
    20    
    21    static {
    22        new DigestorAccessor() {
    23             @Override
    24             protected <Data> byte[] digest(Digestor<Data> dig, Data data) {
    25                 return dig.digest(data);
    26             }
    27 
    28             @Override
    29             protected <Data> Data create(Digestor<Data> dig, String algorithm) {
    30                 return dig.create(algorithm);
    31             }
    32 
    33             @Override
    34             protected <Data> void update(Digestor<Data> dig, Data data, ByteBuffer input) {
    35                 dig.update(data, input);
    36             }
    37         };
    38    }
    39 }