define(["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var _PdfNativeAccumulatorSink = (function () {
function _PdfNativeAccumulatorSink() {
this._events = [];
}
_PdfNativeAccumulatorSink.prototype._add = function (event) {
this._events.push(event);
this._result = event.bytes;
};
_PdfNativeAccumulatorSink.prototype._setResult = function (result) {
this._result = result;
this._events = [{ bytes: result }];
};
_PdfNativeAccumulatorSink.prototype._getResult = function () {
if (this._events.length > 0) {
return this._events[this._events.length - 1].bytes;
}
return this._result;
};
return _PdfNativeAccumulatorSink;
}());
exports._PdfNativeAccumulatorSink = _PdfNativeAccumulatorSink;
var _PdfNativeHashInput = (function () {
function _PdfNativeHashInput(hasher, outputSink) {
this._buffer = [];
this._closed = false;
this._hasher = hasher;
this._outputSink = outputSink;
}
_PdfNativeHashInput.prototype._add = function (data) {
if (this._closed) {
throw new Error('Cannot add data to closed hash input');
}
for (var i = 0; i < data.length; i++) {
this._buffer.push(data[i]);
}
};
_PdfNativeHashInput.prototype._close = function () {
if (this._closed) {
return;
}
this._closed = true;
if (this._buffer.length > 0) {
var inputData = new Uint8Array(this._buffer);
var result = this._hasher._hash(inputData, 0, inputData.length);
this._outputSink._add({ bytes: result });
}
};
return _PdfNativeHashInput;
}());
exports._PdfNativeHashInput = _PdfNativeHashInput;
var _PdfNativeAlgorithmIdentifier = (function () {
function _PdfNativeAlgorithmIdentifier(oid) {
this._oid = oid;
}
_PdfNativeAlgorithmIdentifier.prototype._getEncoded = function () {
var oidBytes = this._encodeObjectIdentifier(this._oid);
var nullBytes = new Uint8Array([0x05, 0x00]);
var contentLength = oidBytes.length + nullBytes.length;
var result = [];
result.push(0x30);
result.push(contentLength);
result.push.apply(result, Array.from(oidBytes));
result.push.apply(result, Array.from(nullBytes));
return new Uint8Array(result);
};
_PdfNativeAlgorithmIdentifier.prototype._encodeObjectIdentifier = function (oidString) {
var parts = oidString.split('.').map(Number);
var bytes = [];
bytes.push(parts[0] * 40 + parts[1]);
for (var i = 2; i < parts.length; i++) {
var value = parts[i];
if (value < 128) {
bytes.push(value);
}
else {
var temp = [];
while (value > 0) {
temp.unshift(value & 0x7F);
value = Math.floor(value / 128);
}
for (var j = 0; j < temp.length - 1; j++) {
temp[j] |= 0x80;
}
bytes.push.apply(bytes, temp);
}
}
var result = [];
result.push(0x06);
result.push(bytes.length);
result.push.apply(result, bytes);
return new Uint8Array(result);
};
return _PdfNativeAlgorithmIdentifier;
}());
exports._PdfNativeAlgorithmIdentifier = _PdfNativeAlgorithmIdentifier;
});
|