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 DigestImpl<?> impl;
17 /** Factory method is better than constructor */
18 private Digest(DigestImpl<?> 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 DigestImpl<?> impl = DigestImpl.create(
30 return new Digest(impl);
33 throw new IllegalArgumentException(algorithm);
37 // these methods are kept the same as in original MessageDigest,
38 // but for simplicity choose just some from the original API
41 public byte[] digest(ByteBuffer bb) {
42 return impl.digest(bb);
45 // END: day.end.bridges.Digest