occulto/test/main.js

70 lines
2.5 KiB
JavaScript
Raw Normal View History

2019-03-30 20:50:04 +01:00
const { describe, it } = require('mocha')
const a = require('assert')
2019-03-31 16:00:24 +02:00
describe('Check imports', () => {
it('default', () => {
const Occulto = require('../').default
a.notStrictEqual(undefined, Occulto.RSA)
2019-04-08 20:07:11 +02:00
a.notStrictEqual(undefined, Occulto.Symmetric)
2019-03-31 16:00:24 +02:00
})
it('normal', () => {
2019-04-08 20:07:11 +02:00
const { RSA, Symmetric } = require('../')
2019-03-31 16:00:24 +02:00
a.notStrictEqual(undefined, RSA)
2019-04-08 20:07:11 +02:00
a.notStrictEqual(undefined, Symmetric)
2019-03-31 16:00:24 +02:00
})
})
2019-04-08 20:07:11 +02:00
const { RSA, Symmetric } = require('../')
2019-03-30 20:50:04 +01:00
describe('Asymmetric', () => {
describe('RSA', () => {
it('Encrypt and Decrypt small string', async () => {
const pair = await RSA.gen(2 ** 10)
const text = `some small string`
const e = RSA.encrypt(text, pair.pub)
const d = RSA.decrypt(e, pair.prv)
a.strictEqual(text, d)
})
})
})
describe('Symmetric', () => {
const keyLong = `yruyLaCAbcfJD9DKk3Ef6zuSFMPatwbg63ayPHVDSSxAePqtYxmd7N5BX2ShCgaG`
const keyShort = `simple`
const dataShort = `a sentence`
const dataLong = `Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.`
2019-04-08 20:07:11 +02:00
describe('Symmetric', () => {
2019-03-30 20:50:04 +01:00
describe('Default', () => {
it('Short', () => {
2019-04-08 20:07:11 +02:00
const e = Symmetric.encrypt(dataShort, keyShort)
const d = Symmetric.decrypt(e, keyShort)
2019-03-30 20:50:04 +01:00
a.strictEqual(dataShort, d)
})
it('Long', () => {
2019-04-08 20:07:11 +02:00
const e = Symmetric.encrypt(dataLong, keyLong)
const d = Symmetric.decrypt(e, keyLong)
2019-03-30 20:50:04 +01:00
a.strictEqual(dataLong, d)
})
})
2019-04-08 20:07:11 +02:00
describe('All Ciphers', () => {
for (const [key, value] of Object.entries(Symmetric.Ciphers)) {
if (!isNaN(key)) continue
it(key, () => {
const e = Symmetric.encrypt(dataShort, keyShort, value)
const d = Symmetric.decrypt(e, keyShort)
a.strictEqual(dataShort, d)
})
}
2019-03-30 20:50:04 +01:00
})
})
})