Simplified to does not contain the friend API, instead the SPI is directly define by the API
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
6 package org.apidesign.impl;
8 import java.nio.ByteBuffer;
9 import org.apidesign.spi.security.Digestor;
13 * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
15 public abstract class DigestorAccessor {
16 private static DigestorAccessor INSTANCE;
18 protected DigestorAccessor() {
19 if (this.getClass().getName().equals("org.apidesign.spi.security.DigestorAccessorImpl")) {
20 assert INSTANCE == null;
24 if (this.getClass().getName().equals("org.apidesign.api.security.DigestorAccessorImpl")) {
27 throw new IllegalStateException();
30 final DigestorAccessor getDefault() {
32 Class.forName(Digestor.class.getName(), true, DigestorAccessor.class.getClassLoader());
34 } catch (ClassNotFoundException ex) {
35 throw new IllegalStateException(ex);
39 protected abstract <Data> byte[] digest(Digestor<Data> dig, Data data);
40 protected abstract <Data> Data create(Digestor<Data> dig, String algorithm);
41 protected abstract <Data> void update(Digestor<Data> dig, Data data, ByteBuffer input);
44 protected final <Data> byte[] defaultDigest(Digestor<Data> dig, Data data) {
45 return getDefault().digest(dig, data);
47 protected final <Data> Data defaultCreate(Digestor<Data> dig, String algorithm) {
48 return getDefault().create(dig, algorithm);
50 protected final <Data> void defaultUpdate(Digestor<Data> dig, Data data, ByteBuffer input) {
51 getDefault().update(dig, data, input);