aboutsummaryrefslogtreecommitdiffstats
path: root/library/sodium-plus/test/util-test.js
blob: f1358686865d6f982d449a2fbf98b73c8e28ea3f (plain) (blame)
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
const { describe, it } = require('mocha');
const { expect } = require('chai');
const { SodiumPlus } = require('../index');
const Util = require('../lib/util');
const VERBOSE = false;
const expectError = require('./async-helper');

let sodium;

(async () => {
    if (!sodium) sodium = await SodiumPlus.auto();
    if (VERBOSE) {
        console.log({
            'libsodium-wrappers': sodium.isLibsodiumWrappers(),
            'sodium-native': sodium.isSodiumNative()
        });
    }
})();

describe('Util', async () => {
    it('toBuffer()', async () => {
        if (!sodium) sodium = await SodiumPlus.auto();

        expect(null).to.be.equal(await Util.toBuffer(null));

        let promised = await Util.toBuffer(sodium.crypto_secretbox_keygen());
        expect(32).to.be.equal(promised.getBuffer().length);
        await expectError(Util.toBuffer(12), 'Invalid type; string or buffer expected');
    });
});