-
Notifications
You must be signed in to change notification settings - Fork 1
/
encrypt.spec.js
58 lines (50 loc) · 1.46 KB
/
encrypt.spec.js
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* eslint-env mocha */
'use strict'
const chai = require('chai')
chai.use(require('dirty-chai'))
const expect = chai.expect
const isNode = require('detect-node')
const values = require('pull-stream/sources/values')
const bufferStream = require('pull-buffer-stream')
const multihash = require('multihashes')
const randomBytes = require('./helpers/random-bytes')
const util = require('util')
const {
collectLeafCids,
createMfs,
cidAtPath,
createShardedDirectory,
createTwoShards,
createShard
} = require('./helpers')
const CID = require('cids')
const crypto = require('crypto')
const {
encrypt,
decrypt,
generateRandomIV,
generateRandomKey
} = require('../src/core/utils/crypto/symmetric')
let fs, tempWrite
if (isNode) {
fs = require('fs')
tempWrite = require('temp-write')
}
describe('encrypt', () => {
let mfs;
let smallFile = Buffer.from("small message from vasa")
let largeFile = randomBytes(490668)
before(async () => {
mfs = await createMfs()
})
it('encrypts the content passed and writes it to a file', async () => {
const filePath = `/small-file-${Math.random()}.txt`
await mfs.write(filePath, smallFile, {
create: true,
crypto: {"algorithm": "aes-256-cbc", "key": generateRandomKey(), "iv": generateRandomIV()}
})
const stats = await mfs.stat(filePath)
//console.log("STATS: ",stats)
//expect(stats.size).to.equal(smallFile.length)
})
})