aboutsummaryrefslogblamecommitdiffstats
path: root/library/sodium-plus/test/util-test.js
blob: f1358686865d6f982d449a2fbf98b73c8e28ea3f (plain) (tree)





























                                                                                        
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');
    });
});