forked from eXist-db/expath-crypto-module
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhashBinaryWithSha1.xq
44 lines (40 loc) · 1.54 KB
/
hashBinaryWithSha1.xq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
(:
: eXist-db EXPath Cryptographic library
: eXist-db wrapper for EXPath Cryptographic Java library
: Copyright (C) 2016 Claudius Teodorescu
:
: This library is free software; you can redistribute it and/or
: modify it under the terms of the GNU Lesser General Public License
: as published by the Free Software Foundation; either version 2.1
: of the License, or (at your option) any later version.
:
: This library is distributed in the hope that it will be useful,
: but WITHOUT ANY WARRANTY; without even the implied warranty of
: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
: GNU Lesser General Public License for more details.
:
: You should have received a copy of the GNU Lesser General Public License
: along with this library; if not, write to the Free Software Foundation,
: Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
:)
xquery version "3.0";
import module "http://expath.org/ns/crypto";
let $input := util:binary-doc(concat('xmldb:', resolve-uri('../resources/keystore.ks', concat(substring-after(system:get-module-load-path(), 'xmldb:'), '/'))))
let $expected-result :=
<expected-result>GyscHvnJKxInsBLgSg/FRAmQXYU=</expected-result>
let $actual-result :=
<actual-result>
{crypto:hash($input, "SHA-1", "base64")}
</actual-result>
let $condition := normalize-space($expected-result/text()) = normalize-space($actual-result/text())
return
<result>
{
(
if ($condition)
then <result-token>passed</result-token>
else <result-token>failed</result-token>
, $actual-result
)
}
</result>