Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update generator use @videojs/vhs-utils #68

Merged
merged 4 commits into from
Aug 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7,019 changes: 3,137 additions & 3,882 deletions package-lock.json

Large diffs are not rendered by default.

56 changes: 22 additions & 34 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,22 @@
"bcasey"
],
"scripts": {
"prebuild": "npm run clean",
"build": "npm-run-all -p build:*",
"build-test": "cross-env-shell TEST_BUNDLE_ONLY=1 'npm run build'",
"build-prod": "cross-env-shell NO_TEST_BUNDLE=1 'npm run build'",
"build": "npm-run-all -s clean -p build:*",
"build:js": "rollup -c scripts/rollup.config.js",
"clean": "shx rm -rf ./dist ./test/dist",
"postclean": "shx mkdir -p ./dist ./test/dist",
"docs": "npm-run-all docs:*",
"docs:api": "jsdoc src -g plugins/markdown -r -d docs/api",
"docs:toc": "doctoc README.md",
"clean": "shx rm -rf ./dist ./test/dist && shx mkdir -p ./dist ./test/dist",
"lint": "vjsstandard",
"server": "karma start scripts/karma.conf.js --singleRun=false --auto-watch",
"prepublishOnly": "npm-run-all build-prod && vjsverify --verbose",
"start": "npm-run-all -p server watch",
"pretest": "npm-run-all lint build",
"test": "karma start scripts/karma.conf.js",
"server": "karma start scripts/karma.conf.js --singleRun=false --auto-watch",
"test": "npm-run-all lint build-test && karma start scripts/karma.conf.js",
"posttest": "shx cat test/dist/coverage/text.txt",
"update-changelog": "conventional-changelog -p videojs -i CHANGELOG.md -s",
"preversion": "npm test",
"version": "is-prerelease || npm run update-changelog && git add CHANGELOG.md",
"update-changelog": "conventional-changelog -p videojs -i CHANGELOG.md -s",
"watch": "npm-run-all -p watch:*",
"watch:js": "npm run build:js -- -w",
"prepublishOnly": "npm run build && vjsverify"
"watch:js": "npm run build:js -- -w"
},
"author": "Brightcove, Inc.",
"license": "Apache-2.0",
Expand All @@ -51,31 +47,23 @@
"test/"
],
"dependencies": {
"@babel/runtime": "^7.5.5",
"@videojs/vhs-utils": "^1.0.0",
"global": "^4.3.2",
"pkcs7": "^1.0.2"
"pkcs7": "^1.0.3"
},
"devDependencies": {
"conventional-changelog-cli": "^2.0.1",
"conventional-changelog-videojs": "^3.0.0",
"doctoc": "^1.3.1",
"husky": "^1.0.0-rc.13",
"jsdoc": "https://github.com/BrandonOCasey/jsdoc#feat/plugin-from-cli",
"karma": "^3.0.0",
"lint-staged": "^7.2.2",
"not-prerelease": "^1.0.1",
"npm-merge-driver-install": "^1.0.0",
"npm-run-all": "^4.1.3",
"pkg-ok": "^2.2.0",
"rollup": "^0.66.0",
"shx": "^0.3.2",
"sinon": "^6.1.5",
"videojs-generate-karma-config": "~5.0.1",
"videojs-generate-rollup-config": "~2.2.0",
"videojs-standard": "~7.1.0",
"videojs-generator-verify": "~1.0.4"
"rollup": "^1.19.4",
"@videojs/generator-helpers": "~1.2.0",
"karma": "^4.0.0",
"sinon": "^7.2.2",
"videojs-generate-karma-config": "~5.3.1",
"videojs-generator-verify": "~2.0.0",
"videojs-generate-rollup-config": "~5.0.1",
"videojs-standard": "^8.0.3"
},
"generator-videojs-plugin": {
"version": "7.3.2"
"version": "7.7.3"
},
"directories": {
"test": "test"
Expand Down Expand Up @@ -107,7 +95,7 @@
"git add"
],
"README.md": [
"npm run docs:toc",
"doctoc --notitle",
"git add"
]
}
Expand Down
7 changes: 6 additions & 1 deletion scripts/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ const generate = require('videojs-generate-rollup-config');
// see https://github.com/videojs/videojs-generate-rollup-config
// for options
const options = {
input: 'src/index.js'
input: 'src/index.js',
externals(defaults) {
defaults.module.push('pkcs7');
defaults.module.push('@videojs/vhs-utils');
return defaults;
}
};
const config = generate(options);

Expand Down
14 changes: 9 additions & 5 deletions src/async-stream.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @file async-stream.js
*/
import Stream from './stream';
import Stream from '@videojs/vhs-utils/dist/stream.js';

/**
* A wrapper around the Stream class to use setTimeout
Expand All @@ -26,8 +26,10 @@ export default class AsyncStream extends Stream {
processJob_() {
this.jobs.shift()();
if (this.jobs.length) {
this.timeout_ = setTimeout(this.processJob_.bind(this),
this.delay);
this.timeout_ = setTimeout(
this.processJob_.bind(this),
this.delay
);
} else {
this.timeout_ = null;
}
Expand All @@ -41,8 +43,10 @@ export default class AsyncStream extends Stream {
push(job) {
this.jobs.push(job);
if (!this.timeout_) {
this.timeout_ = setTimeout(this.processJob_.bind(this),
this.delay);
this.timeout_ = setTimeout(
this.processJob_.bind(this),
this.delay
);
}
}
}
Expand Down
24 changes: 16 additions & 8 deletions src/decrypter.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ const ntoh = function(word) {
*/
const decrypt = function(encrypted, key, initVector) {
// word-level access to the encrypted bytes
const encrypted32 = new Int32Array(encrypted.buffer,
const encrypted32 = new Int32Array(
encrypted.buffer,
encrypted.byteOffset,
encrypted.byteLength >> 2);
encrypted.byteLength >> 2
);

const decipher = new AES(Array.prototype.slice.call(key));

Expand Down Expand Up @@ -77,12 +79,14 @@ const decrypt = function(encrypted, key, initVector) {
encrypted3 = ntoh(encrypted32[wordIx + 3]);

// decrypt the block
decipher.decrypt(encrypted0,
decipher.decrypt(
encrypted0,
encrypted1,
encrypted2,
encrypted3,
decrypted32,
wordIx);
wordIx
);

// XOR with the IV, and restore network byte-order to obtain the
// plaintext
Expand Down Expand Up @@ -122,19 +126,23 @@ class Decrypter {
this.asyncStream_ = new AsyncStream();

// split up the encryption job and do the individual chunks asynchronously
this.asyncStream_.push(this.decryptChunk_(encrypted32.subarray(i, i + step),
this.asyncStream_.push(this.decryptChunk_(
encrypted32.subarray(i, i + step),
key,
initVector,
decrypted));
decrypted
));
for (i = step; i < encrypted32.length; i += step) {
initVector = new Uint32Array([ntoh(encrypted32[i - 4]),
ntoh(encrypted32[i - 3]),
ntoh(encrypted32[i - 2]),
ntoh(encrypted32[i - 1])]);
this.asyncStream_.push(this.decryptChunk_(encrypted32.subarray(i, i + step),
this.asyncStream_.push(this.decryptChunk_(
encrypted32.subarray(i, i + step),
key,
initVector,
decrypted));
decrypted
));
}
// invoke the done() callback when everything is finished
this.asyncStream_.push(function() {
Expand Down
99 changes: 0 additions & 99 deletions src/stream.js

This file was deleted.

39 changes: 26 additions & 13 deletions test/decrypter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ QUnit.test('decrypts a single AES-128 with PKCS7 block', function(assert) {
0x82, 0xa8, 0xf0, 0x67
]);

assert.deepEqual('howdy folks',
assert.deepEqual(
'howdy folks',
stringFromBytes(unpad(decrypt(encrypted, key, initVector))),
'decrypted with a byte array key'
);
Expand All @@ -48,9 +49,11 @@ QUnit.test('decrypts multiple AES-128 blocks with CBC', function(assert) {
0xe9, 0x4e, 0x29, 0xb3
]);

assert.deepEqual('0123456789abcdef01234',
assert.deepEqual(
'0123456789abcdef01234',
stringFromBytes(unpad(decrypt(encrypted, key, initVector))),
'decrypted multiple blocks');
'decrypted multiple blocks'
);
});

QUnit.test(
Expand All @@ -66,7 +69,8 @@ QUnit.test(
0x82, 0xa8, 0xf0, 0x67
]);

assert.deepEqual('howdy folks',
assert.deepEqual(
'howdy folks',
stringFromBytes(unpad(decrypt(pkcs7Block, key, initVector))),
'decrypted with a byte array key'
);
Expand All @@ -84,11 +88,14 @@ QUnit.test(
0xe9, 0x4e, 0x29, 0xb3
]);

assert.deepEqual('0123456789abcdef01234',
assert.deepEqual(
'0123456789abcdef01234',
stringFromBytes(unpad(decrypt(cbcBlocks, key, initVector))),
'decrypted multiple blocks');
'decrypted multiple blocks'
);

});
}
);

QUnit.module('Incremental Processing', {
beforeEach() {
Expand Down Expand Up @@ -148,34 +155,40 @@ QUnit.test('asynchronously decrypts a 4-word block', function(assert) {
0x4f, 0xae, 0x01, 0x1c,
0x82, 0xa8, 0xf0, 0x67]);
let decrypted;
const decrypter = new Decrypter(encrypted,
const decrypter = new Decrypter(
encrypted,
key,
initVector,
function(error, result) {
if (error) {
throw new Error(error);
}
decrypted = result;
});
}
);

assert.ok(!decrypted, 'asynchronously decrypts');
this.clock.tick(decrypter.asyncStream_.delay * 2);

assert.ok(decrypted, 'completed decryption');
assert.deepEqual('howdy folks',
assert.deepEqual(
'howdy folks',
stringFromBytes(decrypted),
'decrypts and unpads the result');
'decrypts and unpads the result'
);
});

QUnit.test('breaks up input greater than the step value', function(assert) {
const encrypted = new Int32Array(Decrypter.STEP + 4);
let done = false;
const decrypter = new Decrypter(encrypted,
const decrypter = new Decrypter(
encrypted,
new Uint32Array(4),
new Uint32Array(4),
function() {
done = true;
});
}
);

this.clock.tick(decrypter.asyncStream_.delay * 2);
assert.ok(!done, 'not finished after two ticks');
Expand Down