1.1 --- a/samples/messagedigest/nbproject/project.xml Sat Jun 14 09:52:23 2008 +0200
1.2 +++ b/samples/messagedigest/nbproject/project.xml Sat Jun 14 09:52:23 2008 +0200
1.3 @@ -97,7 +97,7 @@
1.4 </compilation-unit>
1.5 <compilation-unit>
1.6 <package-root>src-test</package-root>
1.7 - <classpath mode="compile">src-api1.0:../libs/dist/junit-4.4.jar</classpath>
1.8 + <classpath mode="compile">src-new-api:src-new-spi:../libs/dist/junit-4.4.jar</classpath>
1.9 <source-level>1.5</source-level>
1.10 </compilation-unit>
1.11 </java-data>
2.1 --- a/samples/messagedigest/src-bridge/META-INF/services/org.apidesign.impl.security.friendapi.DigestProvider Sat Jun 14 09:52:23 2008 +0200
2.2 +++ b/samples/messagedigest/src-bridge/META-INF/services/org.apidesign.impl.security.friendapi.DigestProvider Sat Jun 14 09:52:23 2008 +0200
2.3 @@ -1,3 +1,4 @@
2.4 -# this shall be in a separate module that provides the "bridge"
2.5 -org.apidesign.impl.security.extension.BridgeToOldAlgorithmsProvider
2.6 -
2.7 +# BEGIN: day.end.bridges.FriendMetaInf
2.8 +# registration in bridge's META-INF/services/friendapi.DigestProvider
2.9 +org.apidesign.impl.security.extension.BridgeToNew
2.10 +# END: day.end.bridges.FriendMetaInf
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/samples/messagedigest/src-bridge/org/apidesign/impl/security/extension/BridgeToNew.java Sat Jun 14 09:52:23 2008 +0200
3.3 @@ -0,0 +1,44 @@
3.4 +/*
3.5 + * To change this template, choose Tools | Templates
3.6 + * and open the template in the editor.
3.7 + */
3.8 +
3.9 +package org.apidesign.impl.security.extension;
3.10 +
3.11 +import org.apidesign.impl.security.friendapi.DigestImplementation;
3.12 +import org.apidesign.impl.security.friendapi.DigestProvider;
3.13 +import java.nio.ByteBuffer;
3.14 +import java.security.MessageDigest;
3.15 +import java.security.NoSuchAlgorithmException;
3.16 +import java.util.logging.Level;
3.17 +import java.util.logging.Logger;
3.18 +
3.19 +/**
3.20 + *
3.21 + * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
3.22 + */
3.23 +// BEGIN: day.end.bridges.BridgeToNew
3.24 +public class BridgeToNew implements DigestProvider {
3.25 +
3.26 + public DigestImplementation create(String algorithm) {
3.27 + try {
3.28 + final MessageDigest md = MessageDigest.getInstance(algorithm);
3.29 + return new DigestImplementation(algorithm) {
3.30 +
3.31 + @Override
3.32 + public void update(ByteBuffer bb) {
3.33 + md.update(bb);
3.34 + }
3.35 +
3.36 + @Override
3.37 + public byte[] digest() {
3.38 + return md.digest();
3.39 + }
3.40 + };
3.41 + } catch (NoSuchAlgorithmException ex) {
3.42 + Logger.getLogger(BridgeToNew.class.getName()).log(Level.INFO, null, ex);
3.43 + return null;
3.44 + }
3.45 + }
3.46 +}
3.47 +// END: day.end.bridges.BridgeToNew
4.1 --- a/samples/messagedigest/src-bridge/org/apidesign/impl/security/extension/BridgeToOld.java Sat Jun 14 09:52:23 2008 +0200
4.2 +++ b/samples/messagedigest/src-bridge/org/apidesign/impl/security/extension/BridgeToOld.java Sat Jun 14 09:52:23 2008 +0200
4.3 @@ -19,6 +19,7 @@
4.4 *
4.5 * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
4.6 */
4.7 +// BEGIN: day.end.bridges.BridgeToOld
4.8 public class BridgeToOld extends Provider {
4.9
4.10 public BridgeToOld() {
4.11 @@ -80,3 +81,4 @@
4.12 }
4.13
4.14 }
4.15 +// END: day.end.bridges.BridgeToOld
5.1 --- a/samples/messagedigest/src-test/test/CountingDigestor.java Sat Jun 14 09:52:23 2008 +0200
5.2 +++ b/samples/messagedigest/src-test/test/CountingDigestor.java Sat Jun 14 09:52:23 2008 +0200
5.3 @@ -10,10 +10,10 @@
5.4
5.5 /**
5.6 *
5.7 - * @author jarda
5.8 + * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5.9 */
5.10 +// BEGIN: day.end.bridges.CountingDigestor
5.11 public final class CountingDigestor extends Digestor<int[]> {
5.12 -
5.13 @Override
5.14 protected byte[] digest(int[] data) {
5.15 int i = data[0];
5.16 @@ -31,5 +31,5 @@
5.17 data[0] += input.remaining();
5.18 input.position(input.position() + input.remaining());
5.19 }
5.20 -
5.21 }
5.22 +// END: day.end.bridges.CountingDigestor
5.23 \ No newline at end of file
6.1 --- a/samples/messagedigest/src-test/test/OldAPIToNewAPITest.java Sat Jun 14 09:52:23 2008 +0200
6.2 +++ b/samples/messagedigest/src-test/test/OldAPIToNewAPITest.java Sat Jun 14 09:52:23 2008 +0200
6.3 @@ -43,6 +43,7 @@
6.4
6.5 @Test
6.6 public void generateHashUsingMessageDigest() throws Exception {
6.7 + // BEGIN: day.end.bridges.BridgeToOldRegister
6.8 // The java.security.Providers cannot be registered in META-INF/services
6.9 // that is why one needs to either configure various properties or
6.10 // make some dummy call that will initialize our bridge class.
6.11 @@ -51,6 +52,7 @@
6.12 //
6.13 // This is the call:
6.14 Digest initialize = Digest.getInstance("MD5");
6.15 + // END: day.end.bridges.BridgeToOldRegister
6.16
6.17 MessageDigest md = MessageDigest.getInstance("cnt");
6.18 byte[] res = md.digest(arr);