Merge pull request #642 from mmso/feat/bzip2
Fix #607 - Add support for bzip2 de/compression
This commit is contained in:
commit
fa2672fcc1
|
@ -213,6 +213,12 @@ module.exports = function(grunt) {
|
||||||
cwd: 'node_modules/zlibjs/bin/',
|
cwd: 'node_modules/zlibjs/bin/',
|
||||||
src: ['rawdeflate.min.js','rawinflate.min.js','zlib.min.js'],
|
src: ['rawdeflate.min.js','rawinflate.min.js','zlib.min.js'],
|
||||||
dest: 'src/compression/'
|
dest: 'src/compression/'
|
||||||
|
},
|
||||||
|
bzip2: {
|
||||||
|
expand: true,
|
||||||
|
cwd: 'node_modules/compressjs/bin/',
|
||||||
|
src: ['bzip2.build.js'],
|
||||||
|
dest: 'src/compression/'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
clean: ['dist/'],
|
clean: ['dist/'],
|
||||||
|
@ -310,7 +316,7 @@ module.exports = function(grunt) {
|
||||||
// Build tasks
|
// Build tasks
|
||||||
grunt.registerTask('version', ['replace:openpgp', 'replace:openpgp_debug']);
|
grunt.registerTask('version', ['replace:openpgp', 'replace:openpgp_debug']);
|
||||||
grunt.registerTask('replace_min', ['replace:openpgp_min', 'replace:worker_min']);
|
grunt.registerTask('replace_min', ['replace:openpgp_min', 'replace:worker_min']);
|
||||||
grunt.registerTask('default', ['clean', 'copy:zlib', 'browserify', 'version', 'uglify', 'replace_min']);
|
grunt.registerTask('default', ['clean', 'copy:zlib', 'copy:bzip2', 'browserify', 'version', 'uglify', 'replace_min']);
|
||||||
grunt.registerTask('documentation', ['jsdoc']);
|
grunt.registerTask('documentation', ['jsdoc']);
|
||||||
// Test/Dev tasks
|
// Test/Dev tasks
|
||||||
grunt.registerTask('test', ['eslint', 'mochaTest']);
|
grunt.registerTask('test', ['eslint', 'mochaTest']);
|
||||||
|
|
|
@ -19,6 +19,7 @@ OpenPGP.js [
|
- [Set up](#set-up)
|
||||||
- [Encrypt and decrypt *Uint8Array* data with a password](#encrypt-and-decrypt-uint8array-data-with-a-password)
|
- [Encrypt and decrypt *Uint8Array* data with a password](#encrypt-and-decrypt-uint8array-data-with-a-password)
|
||||||
- [Encrypt and decrypt *String* data with PGP keys](#encrypt-and-decrypt-string-data-with-pgp-keys)
|
- [Encrypt and decrypt *String* data with PGP keys](#encrypt-and-decrypt-string-data-with-pgp-keys)
|
||||||
|
- [Encrypt with compression](#encrypt-with-compression)
|
||||||
- [Generate new key pair](#generate-new-key-pair)
|
- [Generate new key pair](#generate-new-key-pair)
|
||||||
- [Lookup public key on HKP server](#lookup-public-key-on-hkp-server)
|
- [Lookup public key on HKP server](#lookup-public-key-on-hkp-server)
|
||||||
- [Upload public key to HKP server](#upload-public-key-to-hkp-server)
|
- [Upload public key to HKP server](#upload-public-key-to-hkp-server)
|
||||||
|
@ -180,7 +181,10 @@ Or, override the config to enable compression:
|
||||||
openpgp.config.compression = openpgp.enums.compression.zip
|
openpgp.config.compression = openpgp.enums.compression.zip
|
||||||
```
|
```
|
||||||
|
|
||||||
Where `compression` can take the value of `openpgp.enums.compression.zlib` or `openpgp.enums.compression.zip`.
|
Where the value can be any of:
|
||||||
|
* `openpgp.enums.compression.zip`
|
||||||
|
* `openpgp.enums.compression.zlib`
|
||||||
|
* `openpgp.enums.compression.bzip2`
|
||||||
|
|
||||||
|
|
||||||
#### Generate new key pair
|
#### Generate new key pair
|
||||||
|
|
|
@ -83,7 +83,8 @@
|
||||||
"jwk-to-pem": "^1.2.6",
|
"jwk-to-pem": "^1.2.6",
|
||||||
"node-fetch": "^1.7.3",
|
"node-fetch": "^1.7.3",
|
||||||
"node-localstorage": "~1.3.0",
|
"node-localstorage": "~1.3.0",
|
||||||
"rusha": "^0.8.12"
|
"rusha": "^0.8.12",
|
||||||
|
"compressjs": "github:openpgpjs/compressjs.git"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
* @requires compression/zlib
|
* @requires compression/zlib
|
||||||
* @requires compression/rawinflate
|
* @requires compression/rawinflate
|
||||||
* @requires compression/rawdeflate
|
* @requires compression/rawdeflate
|
||||||
|
* @requires compression/bzip2
|
||||||
* @requires enums
|
* @requires enums
|
||||||
* @requires util
|
* @requires util
|
||||||
* @module packet/compressed
|
* @module packet/compressed
|
||||||
|
@ -34,6 +35,7 @@ import util from '../util.js';
|
||||||
import Zlib from '../compression/zlib.min.js';
|
import Zlib from '../compression/zlib.min.js';
|
||||||
import RawInflate from '../compression/rawinflate.min.js';
|
import RawInflate from '../compression/rawinflate.min.js';
|
||||||
import RawDeflate from '../compression/rawdeflate.min.js';
|
import RawDeflate from '../compression/rawdeflate.min.js';
|
||||||
|
import Bzip2 from '../compression/bzip2.build.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
|
@ -114,8 +116,8 @@ Compressed.prototype.decompress = function () {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'bzip2':
|
case 'bzip2':
|
||||||
// TODO: need to implement this
|
decompressed = Bzip2.decompressFile(this.compressed);
|
||||||
throw new Error('Compression algorithm BZip2 [BZ2] is not implemented.');
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new Error("Compression algorithm unknown :" + this.algorithm);
|
throw new Error("Compression algorithm unknown :" + this.algorithm);
|
||||||
|
@ -150,9 +152,8 @@ Compressed.prototype.compress = function () {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'bzip2':
|
case 'bzip2':
|
||||||
// - BZip2 [BZ2]
|
this.compressed = Bzip2.compressFile(uncompressed);
|
||||||
// TODO: need to implement this
|
break;
|
||||||
throw new Error("Compression algorithm BZip2 [BZ2] is not implemented.");
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new Error("Compression algorithm unknown :" + this.type);
|
throw new Error("Compression algorithm unknown :" + this.type);
|
||||||
|
|
60
test/general/decompression.js
Normal file
60
test/general/decompression.js
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : require('../../dist/openpgp');
|
||||||
|
|
||||||
|
const chai = require('chai');
|
||||||
|
chai.use(require('chai-as-promised'));
|
||||||
|
|
||||||
|
const expect = chai.expect;
|
||||||
|
|
||||||
|
const password = 'I am a password';
|
||||||
|
|
||||||
|
const tests = {
|
||||||
|
zip: {
|
||||||
|
input: `-----BEGIN PGP MESSAGE-----
|
||||||
|
|
||||||
|
jA0ECQMC5rhAA7l3jOzk0kwBTMc07y+1NME5RCUQ2EOlSofbh1KARLC5B1NMeBlq
|
||||||
|
jS917VBeCW3R21xG+0ZJ6Z5iWwdQD7XBtg19doWOqExSmXBWWW/6vSaD81ox
|
||||||
|
=Gw9+
|
||||||
|
-----END PGP MESSAGE-----`,
|
||||||
|
output: 'Hello world! With zip.'
|
||||||
|
},
|
||||||
|
zlib: {
|
||||||
|
input: `-----BEGIN PGP MESSAGE-----
|
||||||
|
|
||||||
|
jA0ECQMC8Qfig2+Tygnk0lMB++5JoyZUcpUy5EJqcxBuy93tXw+BSk7OhFhda1Uo
|
||||||
|
JuQlKv27HlyUaA55tMJsFYPypGBLEXW3k0xi3Cs87RrLqmVGTZSqNhHOVNE28lVe
|
||||||
|
W40mpQ==
|
||||||
|
=z0we
|
||||||
|
-----END PGP MESSAGE-----`,
|
||||||
|
output: 'Hello world! With zlib.'
|
||||||
|
},
|
||||||
|
bzip2: {
|
||||||
|
input: `-----BEGIN PGP MESSAGE-----
|
||||||
|
|
||||||
|
jA0ECQMC97w+wp7u9/Xk0oABBfapJBuuxGBiHDfNmVgsRzbjLDBWTJ3LD4UtxEku
|
||||||
|
qu6hwp5JXB0TgI/XQ3tKobSqHv1wSJ9SVxtWZq6WvWulu+j9GtzIVC3mbDA/qRA3
|
||||||
|
41sUEMdAFC6I7BYLYGEiUAVNpjbvGOmJWptDyawjRgEuZeTzKyTI/UcMc/rLy9Pz
|
||||||
|
Xg==
|
||||||
|
=6ek1
|
||||||
|
-----END PGP MESSAGE-----`,
|
||||||
|
output: 'Hello world! With bzip2.'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('Decrypt and decompress message tests', function () {
|
||||||
|
|
||||||
|
function runTest(key, test) {
|
||||||
|
it(`Decrypts message compressed with ${key}`, function () {
|
||||||
|
const message = openpgp.message.readArmored(test.input);
|
||||||
|
const options = {
|
||||||
|
passwords: password,
|
||||||
|
message
|
||||||
|
};
|
||||||
|
return openpgp.decrypt(options).then(function (encrypted) {
|
||||||
|
expect(encrypted.data).to.equal(test.output + '\n');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Object.keys(tests).forEach(key => runTest(key, tests[key]));
|
||||||
|
|
||||||
|
});
|
|
@ -10,5 +10,6 @@ describe('General', function () {
|
||||||
require('./oid.js');
|
require('./oid.js');
|
||||||
require('./ecc_nist.js');
|
require('./ecc_nist.js');
|
||||||
require('./x25519.js');
|
require('./x25519.js');
|
||||||
|
require('./decompression.js');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -183,12 +183,6 @@ function withCompression(tests) {
|
||||||
const compressionName = openpgp.enums.read(openpgp.enums.compression, compression);
|
const compressionName = openpgp.enums.read(openpgp.enums.compression, compression);
|
||||||
const group = `compression - ${compressionName}`;
|
const group = `compression - ${compressionName}`;
|
||||||
|
|
||||||
// Compression bzip2 [BZ2] is yet to be implemented.
|
|
||||||
if (compression === openpgp.enums.compression.bzip2) {
|
|
||||||
describe.skip(`${group} (not implemented --> skipping tests)`, tests);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
describe(group, function() {
|
describe(group, function() {
|
||||||
let compressSpy;
|
let compressSpy;
|
||||||
let decompressSpy;
|
let decompressSpy;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user