File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed
basex-core/src/main/java/org/basex/query/func/hash Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change 2
2
3
3
import static org .basex .query .QueryError .*;
4
4
5
+ import java .io .*;
5
6
import java .security .*;
6
7
8
+ import org .basex .io .*;
9
+ import org .basex .io .in .*;
7
10
import org .basex .query .*;
8
11
import org .basex .query .func .*;
9
12
import org .basex .query .value .item .*;
@@ -23,8 +26,23 @@ abstract class HashFn extends StandardFunc {
23
26
* @throws QueryException exception
24
27
*/
25
28
final B64 hash (final String algo , final QueryContext qc ) throws QueryException {
29
+ final Item item = exprs [0 ].atomItem (qc , info );
26
30
try {
27
- return new B64 (MessageDigest .getInstance (algo ).digest (toBinary (exprs [0 ], qc )));
31
+ final MessageDigest md = MessageDigest .getInstance (algo );
32
+ if (item instanceof B64Stream ) {
33
+ try (final BufferInput bi = item .input (info )) {
34
+ final byte [] tmp = new byte [IO .BLOCKSIZE ];
35
+ do {
36
+ final int n = bi .read (tmp );
37
+ if (n == -1 ) return new B64 (md .digest ());
38
+ md .update (tmp , 0 , n );
39
+ } while (true );
40
+ } catch (final IOException ex ) {
41
+ throw FILE_IO_ERROR_X .get (info , ex );
42
+ }
43
+ }
44
+ // non-streaming item, string
45
+ return new B64 (md .digest (toBytes (item )));
28
46
} catch (final NoSuchAlgorithmException ex ) {
29
47
throw HASH_ALG_X .get (info , algo );
30
48
}
You can’t perform that action at this time.
0 commit comments