1 module wrapper.sodium.crypto_verify_64;
2 
3 import wrapper.sodium.core; // assure sodium got initialized
4 
5 public
6 import  deimos.sodium.crypto_verify_64 : crypto_verify_64_BYTES,
7                                          crypto_verify_64_bytes;
8 //                                       crypto_verify_64;
9 
10 // overloading a functions between module deimos.sodium.crypto_verify_64 and this module
11 
12 alias crypto_verify_64 = deimos.sodium.crypto_verify_64.crypto_verify_64;
13 
14 /** Secrets are always compared in constant time using sodium_memcmp() or crypto_verify_(16|32|64)()
15  * @returns true, if the content of array `x` matches the content of array `y`.
16  * Otherwise, it returns false.
17  */
18 pragma(inline, true)
19 bool crypto_verify_64(const ubyte[crypto_verify_64_BYTES] x, const ubyte[crypto_verify_64_BYTES] y) @nogc nothrow pure @trusted
20 {
21   return crypto_verify_64(x.ptr, y.ptr) == 0; // __attribute__ ((warn_unused_result)) __attribute__ ((nonnull));
22 }
23 
24 
25 pure @system
26 unittest
27 {
28   import std.stdio : writeln;
29   import std.range : iota, array;
30   debug  writeln("unittest block 1 from sodium.crypto_verify_64.d");
31 
32 //crypto_verify_64
33   ubyte[] buf1 = array(iota(ubyte(1), cast(ubyte)(1+crypto_verify_64_BYTES)));
34   ubyte[] buf2 = buf1.dup;
35   assert(crypto_verify_64(buf1.ptr, buf2.ptr) ==  0);
36   buf2[$-1] = 65;
37   assert(crypto_verify_64(buf1.ptr, buf2.ptr) == -1);
38 }
39 
40 @nogc nothrow pure @safe
41 unittest
42 {
43   import std.range : iota, enumerate; //, array;
44 //crypto_verify_64
45   assert(crypto_verify_64_bytes() == crypto_verify_64_BYTES);
46 
47 //crypto_verify_64 overload
48   ubyte[crypto_verify_64_BYTES] buf1 = void; // = array(iota(ubyte(1), cast(ubyte)(1+crypto_verify_64_BYTES)))[];
49 version(GNU) // 	GDC (GNU D Compiler) is the compiler ; there, enumerate is not @nogc
50 {
51   size_t idx;
52   foreach (e; iota(ubyte(1), cast(ubyte)(1+crypto_verify_64_BYTES)))
53     buf1[idx++] = e;
54 }
55 else {
56   foreach (i, e; iota(ubyte(1), cast(ubyte)(1+crypto_verify_64_BYTES)).enumerate)
57     buf1[i] = e;
58 }
59   ubyte[crypto_verify_64_BYTES] buf2 = buf1;
60   assert( crypto_verify_64(buf1, buf2));
61   buf2[$-1] = 65;
62   assert(!crypto_verify_64(buf1, buf2));
63 }
64