2 package org.apidesign.api.security;
4 import java.nio.ByteBuffer;
5 import org.apidesign.impl.security.friendapi.DigestImplementation;
6 import org.apidesign.impl.security.friendapi.DigestProvider;
7 import java.util.ServiceLoader;
9 /** MessageDigest extends MessageDigestSpi, that means the javadoc
11 * @author Jaroslav Tulach
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 (DigestProvider dp : ServiceLoader.load(DigestProvider.class)) {
26 DigestImplementation impl = dp.create(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) {
44 // END: day.end.bridges.Digest