samples/messagedigest/src-bridge/org/apidesign/impl/security/extension/BridgeToOldAlgorithmsProvider.java
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/samples/messagedigest/src-bridge/org/apidesign/impl/security/extension/BridgeToOldAlgorithmsProvider.java Sat Jun 14 09:52:23 2008 +0200
1.3 @@ -0,0 +1,46 @@
1.4 +/*
1.5 + * To change this template, choose Tools | Templates
1.6 + * and open the template in the editor.
1.7 + */
1.8 +
1.9 +package org.apidesign.impl.security.extension;
1.10 +
1.11 +import org.apidesign.impl.security.friendapi.DigestImplementation;
1.12 +import org.apidesign.impl.security.friendapi.DigestProvider;
1.13 +import java.nio.ByteBuffer;
1.14 +import java.security.MessageDigest;
1.15 +import java.security.NoSuchAlgorithmException;
1.16 +import java.util.logging.Level;
1.17 +import java.util.logging.Logger;
1.18 +
1.19 +/**
1.20 + *
1.21 + * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
1.22 + */
1.23 +public class BridgeToOldAlgorithmsProvider implements DigestProvider {
1.24 +
1.25 + public DigestImplementation create(String algorithm) {
1.26 + try {
1.27 + final MessageDigest md = MessageDigest.getInstance(algorithm);
1.28 + return new DigestImplementation(algorithm) {
1.29 +
1.30 + @Override
1.31 + public void update(ByteBuffer bb) {
1.32 + md.update(bb);
1.33 + }
1.34 +
1.35 + @Override
1.36 + public byte[] digest() {
1.37 + return md.digest();
1.38 + }
1.39 + };
1.40 + } catch (NoSuchAlgorithmException ex) {
1.41 + Logger.getLogger(BridgeToOldAlgorithmsProvider.class.getName()).log(Level.INFO, null, ex);
1.42 + return null;
1.43 + }
1.44 + }
1.45 +
1.46 + static {
1.47 + new BridgeToOld();
1.48 + }
1.49 +}