samples/messagedigest/src-new-api/org/apidesign/api/security/DigestImpl.java
changeset 301 dbe255defdbb
parent 47 f464a16d553a
child 302 fb84830aacc2
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/samples/messagedigest/src-new-api/org/apidesign/api/security/DigestImpl.java	Thu Dec 25 19:25:59 2008 +0100
     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.api.security;
    1.10 +
    1.11 +import java.nio.ByteBuffer;
    1.12 +import org.apidesign.spi.security.Digestor;
    1.13 +
    1.14 +/**
    1.15 + *
    1.16 + * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    1.17 + */
    1.18 +// BEGIN: day.end.bridges.DigestImpl
    1.19 +final class DigestImpl<Data> {
    1.20 +    private static final DigestorAccessorImpl ACCESSOR = new DigestorAccessorImpl();
    1.21 +    
    1.22 +    private final Digestor<Data> digestor;
    1.23 +    private final String algorithm;
    1.24 +    private Data data;
    1.25 +    
    1.26 +    private DigestImpl(Digestor<Data> digestor, String algorithm, Data d) {
    1.27 +        this.digestor = digestor;
    1.28 +        this.algorithm = algorithm;
    1.29 +        this.data = d;
    1.30 +    }
    1.31 +    
    1.32 +    static <Data> DigestImpl create(Digestor<Data> digestor, String algorithm) {
    1.33 +        // indirectly calls digestor.create(algorithm)
    1.34 +        Data d = ACCESSOR.create(digestor, algorithm);
    1.35 +        if (d == null) {
    1.36 +            return null;
    1.37 +        } else {
    1.38 +            return new DigestImpl(digestor, algorithm, d);
    1.39 +        }
    1.40 +    }
    1.41 +
    1.42 +    byte[] digest(ByteBuffer bb) {
    1.43 +        // indirectly calls digestor.update(data, bb)
    1.44 +        ACCESSOR.update(digestor, data, bb);
    1.45 +        // indirectly calls digestor.digest(data)
    1.46 +        return ACCESSOR.digest(digestor, data);
    1.47 +    }
    1.48 +}
    1.49 +// END: day.end.bridges.DigestImpl
    1.50 \ No newline at end of file