2 package org.apidesign.api.security;
4 import java.nio.ByteBuffer;
5 import java.util.ServiceLoader;
6 import org.apidesign.spi.security.Digestor;
8 /** Simplified version of a Digest class that allows to compute a fingerprint
11 * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
13 // BEGIN: day.end.bridges.Digest
14 public final class Digest {
15 private final DigestImplementation<?> impl;
17 /** Factory method is better than constructor */
18 private Digest(DigestImplementation<?> impl) {
22 /** Factory method to create digest for an algorithm.
24 public static Digest getInstance(String algorithm) {
25 for (Digestor<?> digestor : ServiceLoader.load(Digestor.class)) {
26 DigestImplementation<?> impl = DigestImplementation.create(digestor, algorithm);
28 return new Digest(impl);
31 throw new IllegalArgumentException(algorithm);
35 // these methods are kept the same as in original MessageDigest,
36 // but for simplicity choose just some from the original API
39 public byte[] digest(ByteBuffer bb) {
40 return impl.digest(bb);
43 // END: day.end.bridges.Digest