jtulach@47
|
1 |
/*
|
jtulach@47
|
2 |
* To change this template, choose Tools | Templates
|
jtulach@47
|
3 |
* and open the template in the editor.
|
jtulach@47
|
4 |
*/
|
jtulach@47
|
5 |
|
jtulach@47
|
6 |
package org.apidesign.api.security;
|
jtulach@47
|
7 |
|
jtulach@47
|
8 |
import java.nio.ByteBuffer;
|
jtulach@47
|
9 |
import org.apidesign.spi.security.Digestor;
|
jtulach@47
|
10 |
|
jtulach@47
|
11 |
/**
|
jtulach@47
|
12 |
*
|
jtulach@47
|
13 |
* @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
|
jtulach@47
|
14 |
*/
|
jtulach@301
|
15 |
// BEGIN: day.end.bridges.DigestImpl
|
jtulach@301
|
16 |
final class DigestImpl<Data> {
|
jtulach@47
|
17 |
private static final DigestorAccessorImpl ACCESSOR = new DigestorAccessorImpl();
|
jtulach@47
|
18 |
|
jtulach@47
|
19 |
private final Digestor<Data> digestor;
|
jtulach@47
|
20 |
private final String algorithm;
|
jtulach@47
|
21 |
private Data data;
|
jtulach@47
|
22 |
|
jtulach@301
|
23 |
private DigestImpl(Digestor<Data> digestor, String algorithm, Data d) {
|
jtulach@47
|
24 |
this.digestor = digestor;
|
jtulach@47
|
25 |
this.algorithm = algorithm;
|
jtulach@47
|
26 |
this.data = d;
|
jtulach@47
|
27 |
}
|
jtulach@47
|
28 |
|
jtulach@301
|
29 |
static <Data> DigestImpl create(Digestor<Data> digestor, String algorithm) {
|
jtulach@301
|
30 |
// indirectly calls digestor.create(algorithm)
|
jtulach@47
|
31 |
Data d = ACCESSOR.create(digestor, algorithm);
|
jtulach@47
|
32 |
if (d == null) {
|
jtulach@47
|
33 |
return null;
|
jtulach@47
|
34 |
} else {
|
jtulach@301
|
35 |
return new DigestImpl(digestor, algorithm, d);
|
jtulach@47
|
36 |
}
|
jtulach@47
|
37 |
}
|
jtulach@47
|
38 |
|
jtulach@47
|
39 |
byte[] digest(ByteBuffer bb) {
|
jtulach@301
|
40 |
// indirectly calls digestor.update(data, bb)
|
jtulach@47
|
41 |
ACCESSOR.update(digestor, data, bb);
|
jtulach@301
|
42 |
// indirectly calls digestor.digest(data)
|
jtulach@47
|
43 |
return ACCESSOR.digest(digestor, data);
|
jtulach@47
|
44 |
}
|
jtulach@47
|
45 |
}
|
jtulach@301
|
46 |
// END: day.end.bridges.DigestImpl |