1.1 --- a/samples/messagedigest/src/api/Digest.java Sat Jun 14 09:51:45 2008 +0200
1.2 +++ b/samples/messagedigest/src/api/Digest.java Sat Jun 14 09:51:46 2008 +0200
1.3 @@ -1,13 +1,19 @@
1.4
1.5 package api;
1.6
1.7 +import java.nio.ByteBuffer;
1.8 +import spi.DigestImplementation;
1.9 +
1.10 /** MessageDigest extends MessageDigestSpi, that means the javadoc
1.11 *
1.12 * @author Jaroslav Tulach
1.13 */
1.14 public final class Digest {
1.15 + private final DigestImplementation impl;
1.16 +
1.17 /** Factory method is better than constructor */
1.18 - private Digest() {
1.19 + private Digest(DigestImplementation impl) {
1.20 + this.impl = impl;
1.21 }
1.22
1.23 /** Factory method to create digest for an algorithm.
1.24 @@ -16,6 +22,13 @@
1.25 return null;
1.26 }
1.27
1.28 + //
1.29 + // these methods are kept the same as in original MessageDigest,
1.30 + // but for simplicity choose just some from the original API
1.31 + //
1.32
1.33 + public byte[] digest(ByteBuffer bb) {
1.34 + return null;
1.35 + }
1.36
1.37 }
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/samples/messagedigest/src/spi/DigestImplementation.java Sat Jun 14 09:51:46 2008 +0200
2.3 @@ -0,0 +1,23 @@
2.4 +/*
2.5 + * To change this template, choose Tools | Templates
2.6 + * and open the template in the editor.
2.7 + */
2.8 +
2.9 +package spi;
2.10 +
2.11 +import java.nio.ByteBuffer;
2.12 +
2.13 +/**
2.14 + *
2.15 + * @author Jaroslav Tulach
2.16 + */
2.17 +public abstract class DigestImplementation {
2.18 + final String name;
2.19 +
2.20 + protected DigestImplementation(String algorithm) {
2.21 + this.name = algorithm;
2.22 + }
2.23 +
2.24 + protected abstract void update(ByteBuffer bb);
2.25 + protected abstract byte[] digest();
2.26 +}