Initial commit

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
dinlo
2026-05-31 18:44:04 +08:00
commit 436a9631fc
8616 changed files with 1389957 additions and 0 deletions
+7
View File
@@ -0,0 +1,7 @@
import DERObject from './DERObject.js';
import ObjectIdentifier from './ObjectIdentifier.js';
export default class AlgorithmIdentifier implements DERObject {
algorithm: ObjectIdentifier;
constructor(algorithm: ObjectIdentifier);
toDER(): number[];
}
+16
View File
@@ -0,0 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var derUtil_js_1 = require("./derUtil.js");
var AlgorithmIdentifier = /** @class */ (function () {
function AlgorithmIdentifier(algorithm) {
this.algorithm = algorithm;
}
AlgorithmIdentifier.prototype.toDER = function () {
var r = this.algorithm.toDER();
return derUtil_js_1.makeDERSequence(r.concat(
// parameters is not used now
[0x05, 0x00]));
};
return AlgorithmIdentifier;
}());
exports.default = AlgorithmIdentifier;
+8
View File
@@ -0,0 +1,8 @@
import DERObject from './DERObject.js';
import ObjectIdentifier from './ObjectIdentifier.js';
export default class Attribute implements DERObject {
attrType: ObjectIdentifier;
attrValues: DERObject[];
constructor(attrType: ObjectIdentifier, attrValues: DERObject[]);
toDER(): number[];
}
+14
View File
@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var derUtil_js_1 = require("./derUtil.js");
var Attribute = /** @class */ (function () {
function Attribute(attrType, attrValues) {
this.attrType = attrType;
this.attrValues = attrValues;
}
Attribute.prototype.toDER = function () {
return derUtil_js_1.makeDERSequence(this.attrType.toDER().concat(derUtil_js_1.arrayToDERSet(this.attrValues)));
};
return Attribute;
}());
exports.default = Attribute;
+4
View File
@@ -0,0 +1,4 @@
import ContentInfo from './ContentInfo.js';
import SignedData from './SignedData.js';
export default class CertificateDataRoot extends ContentInfo<SignedData> {
}
+26
View File
@@ -0,0 +1,26 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var ContentInfo_js_1 = require("./ContentInfo.js");
var CertificateDataRoot = /** @class */ (function (_super) {
__extends(CertificateDataRoot, _super);
function CertificateDataRoot() {
return _super !== null && _super.apply(this, arguments) || this;
}
return CertificateDataRoot;
}(ContentInfo_js_1.default));
exports.default = CertificateDataRoot;
+8
View File
@@ -0,0 +1,8 @@
import DERObject from './DERObject.js';
import ObjectIdentifier from './ObjectIdentifier.js';
export default class ContentInfo<TContent extends DERObject = DERObject> implements DERObject {
contentType: ObjectIdentifier;
content: TContent;
constructor(contentType: ObjectIdentifier, content: TContent);
toDER(): number[];
}
+17
View File
@@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var derUtil_js_1 = require("./derUtil.js");
// abstract
var ContentInfo = /** @class */ (function () {
function ContentInfo(contentType, content) {
this.contentType = contentType;
this.content = content;
}
ContentInfo.prototype.toDER = function () {
return derUtil_js_1.makeDERSequence(this.contentType
.toDER()
.concat(derUtil_js_1.makeDERTaggedData(0, this.content.toDER())));
};
return ContentInfo;
}());
exports.default = ContentInfo;
+8
View File
@@ -0,0 +1,8 @@
export default interface DERObject {
toDER: () => number[];
}
export declare class RawDERObject implements DERObject {
data: number[] | Uint8Array;
constructor(data: number[] | Uint8Array);
toDER(): number[];
}
+13
View File
@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RawDERObject = void 0;
var RawDERObject = /** @class */ (function () {
function RawDERObject(data) {
this.data = data;
}
RawDERObject.prototype.toDER = function () {
return [].slice.call(this.data);
};
return RawDERObject;
}());
exports.RawDERObject = RawDERObject;
+8
View File
@@ -0,0 +1,8 @@
import AlgorithmIdentifier from './AlgorithmIdentifier.js';
import DERObject from './DERObject.js';
export default class DigestInfo implements DERObject {
digestAlgorithm: AlgorithmIdentifier;
digest: ArrayBuffer | ArrayBufferView;
constructor(digestAlgorithm: AlgorithmIdentifier, digest: ArrayBuffer | ArrayBufferView);
toDER(): number[];
}
+25
View File
@@ -0,0 +1,25 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var derUtil_js_1 = require("./derUtil.js");
var DigestInfo = /** @class */ (function () {
function DigestInfo(digestAlgorithm, digest) {
this.digestAlgorithm = digestAlgorithm;
this.digest = digest;
}
DigestInfo.prototype.toDER = function () {
var digest = this.digest;
var digestArray;
if ('buffer' in digest) {
digestArray = new Uint8Array(digest.buffer, digest.byteOffset, digest.byteLength);
}
else {
digestArray = new Uint8Array(digest);
}
var derData = this.digestAlgorithm
.toDER()
.concat(derUtil_js_1.makeDEROctetString(digestArray));
return derUtil_js_1.makeDERSequence(derData);
};
return DigestInfo;
}());
exports.default = DigestInfo;
+7
View File
@@ -0,0 +1,7 @@
import DERObject from './DERObject.js';
export default class IssuerAndSerialNumber implements DERObject {
issuer: DERObject;
serialNumber: DERObject;
constructor(issuer: DERObject, serialNumber: DERObject);
toDER(): number[];
}
+14
View File
@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var derUtil_js_1 = require("./derUtil.js");
var IssuerAndSerialNumber = /** @class */ (function () {
function IssuerAndSerialNumber(issuer, serialNumber) {
this.issuer = issuer;
this.serialNumber = serialNumber;
}
IssuerAndSerialNumber.prototype.toDER = function () {
return derUtil_js_1.makeDERSequence(this.issuer.toDER().concat(this.serialNumber.toDER()));
};
return IssuerAndSerialNumber;
}());
exports.default = IssuerAndSerialNumber;
+23
View File
@@ -0,0 +1,23 @@
import ObjectIdentifier from './ObjectIdentifier.js';
export declare const OID_SHA1_NO_SIGN: ObjectIdentifier;
export declare const OID_SHA256_NO_SIGN: ObjectIdentifier;
export declare const OID_SHA384_NO_SIGN: ObjectIdentifier;
export declare const OID_SHA512_NO_SIGN: ObjectIdentifier;
export declare const OID_SHA224_NO_SIGN: ObjectIdentifier;
export declare const OID_SHA512_224_NO_SIGN: ObjectIdentifier;
export declare const OID_SHA512_256_NO_SIGN: ObjectIdentifier;
export declare const OID_SHA3_224_NO_SIGN: ObjectIdentifier;
export declare const OID_SHA3_256_NO_SIGN: ObjectIdentifier;
export declare const OID_SHA3_384_NO_SIGN: ObjectIdentifier;
export declare const OID_SHA3_512_NO_SIGN: ObjectIdentifier;
export declare const OID_SHAKE128_NO_SIGN: ObjectIdentifier;
export declare const OID_SHAKE256_NO_SIGN: ObjectIdentifier;
export declare const OID_RSA: ObjectIdentifier;
export declare const OID_DSA: ObjectIdentifier;
export declare const OID_SIGNED_DATA: ObjectIdentifier;
export declare const OID_CONTENT_TYPE: ObjectIdentifier;
export declare const OID_MESSAGE_DIGEST: ObjectIdentifier;
export declare const OID_SPC_STATEMENT_TYPE_OBJID: ObjectIdentifier;
export declare const OID_SPC_SP_OPUS_INFO_OBJID: ObjectIdentifier;
export declare const OID_SPC_INDIVIDUAL_SP_KEY_PURPOSE_OBJID: ObjectIdentifier;
export declare const OID_RFC3161_COUNTER_SIGNATURE: ObjectIdentifier;
+70
View File
@@ -0,0 +1,70 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OID_RFC3161_COUNTER_SIGNATURE = exports.OID_SPC_INDIVIDUAL_SP_KEY_PURPOSE_OBJID = exports.OID_SPC_SP_OPUS_INFO_OBJID = exports.OID_SPC_STATEMENT_TYPE_OBJID = exports.OID_MESSAGE_DIGEST = exports.OID_CONTENT_TYPE = exports.OID_SIGNED_DATA = exports.OID_DSA = exports.OID_RSA = exports.OID_SHAKE256_NO_SIGN = exports.OID_SHAKE128_NO_SIGN = exports.OID_SHA3_512_NO_SIGN = exports.OID_SHA3_384_NO_SIGN = exports.OID_SHA3_256_NO_SIGN = exports.OID_SHA3_224_NO_SIGN = exports.OID_SHA512_256_NO_SIGN = exports.OID_SHA512_224_NO_SIGN = exports.OID_SHA224_NO_SIGN = exports.OID_SHA512_NO_SIGN = exports.OID_SHA384_NO_SIGN = exports.OID_SHA256_NO_SIGN = exports.OID_SHA1_NO_SIGN = void 0;
var ObjectIdentifier_js_1 = require("./ObjectIdentifier.js");
// 1.3.14.3.2.26
// prettier-ignore
exports.OID_SHA1_NO_SIGN = new ObjectIdentifier_js_1.default([1, 3, 14, 3, 2, 26]);
// 2.16.840.1.101.3.4.2.1
// prettier-ignore
exports.OID_SHA256_NO_SIGN = new ObjectIdentifier_js_1.default([2, 16, 840, 1, 101, 3, 4, 2, 1]);
// 2.16.840.1.101.3.4.2.2
// prettier-ignore
exports.OID_SHA384_NO_SIGN = new ObjectIdentifier_js_1.default([2, 16, 840, 1, 101, 3, 4, 2, 2]);
// 2.16.840.1.101.3.4.2.3
// prettier-ignore
exports.OID_SHA512_NO_SIGN = new ObjectIdentifier_js_1.default([2, 16, 840, 1, 101, 3, 4, 2, 3]);
// 2.16.840.1.101.3.4.2.4
// prettier-ignore
exports.OID_SHA224_NO_SIGN = new ObjectIdentifier_js_1.default([2, 16, 840, 1, 101, 3, 4, 2, 4]);
// 2.16.840.1.101.3.4.2.5
// prettier-ignore
exports.OID_SHA512_224_NO_SIGN = new ObjectIdentifier_js_1.default([2, 16, 840, 1, 101, 3, 4, 2, 5]);
// 2.16.840.1.101.3.4.2.6
// prettier-ignore
exports.OID_SHA512_256_NO_SIGN = new ObjectIdentifier_js_1.default([2, 16, 840, 1, 101, 3, 4, 2, 6]);
// 2.16.840.1.101.3.4.2.7
// prettier-ignore
exports.OID_SHA3_224_NO_SIGN = new ObjectIdentifier_js_1.default([2, 16, 840, 1, 101, 3, 4, 2, 7]);
// 2.16.840.1.101.3.4.2.8
// prettier-ignore
exports.OID_SHA3_256_NO_SIGN = new ObjectIdentifier_js_1.default([2, 16, 840, 1, 101, 3, 4, 2, 8]);
// 2.16.840.1.101.3.4.2.9
// prettier-ignore
exports.OID_SHA3_384_NO_SIGN = new ObjectIdentifier_js_1.default([2, 16, 840, 1, 101, 3, 4, 2, 9]);
// 2.16.840.1.101.3.4.2.10
// prettier-ignore
exports.OID_SHA3_512_NO_SIGN = new ObjectIdentifier_js_1.default([2, 16, 840, 1, 101, 3, 4, 2, 10]);
// 2.16.840.1.101.3.4.2.11
// prettier-ignore
exports.OID_SHAKE128_NO_SIGN = new ObjectIdentifier_js_1.default([2, 16, 840, 1, 101, 3, 4, 2, 11]);
// 2.16.840.1.101.3.4.2.12
// prettier-ignore
exports.OID_SHAKE256_NO_SIGN = new ObjectIdentifier_js_1.default([2, 16, 840, 1, 101, 3, 4, 2, 12]);
// 1.2.840.113549.1.1.1
// prettier-ignore
exports.OID_RSA = new ObjectIdentifier_js_1.default([1, 2, 840, 113549, 1, 1, 1]);
// 1.2.840.10040.4.1
// prettier-ignore
exports.OID_DSA = new ObjectIdentifier_js_1.default([1, 2, 840, 10040, 4, 1]);
// 1.2.840.113549.1.7.2
// prettier-ignore
exports.OID_SIGNED_DATA = new ObjectIdentifier_js_1.default([1, 2, 840, 113549, 1, 7, 2]);
// 1.2.840.113549.1.9.3
// prettier-ignore
exports.OID_CONTENT_TYPE = new ObjectIdentifier_js_1.default([1, 2, 840, 113549, 1, 9, 3]);
// 1.2.840.113549.1.9.4
// prettier-ignore
exports.OID_MESSAGE_DIGEST = new ObjectIdentifier_js_1.default([1, 2, 840, 113549, 1, 9, 4]);
// 1.3.6.1.4.1.311.2.1.11
// prettier-ignore
exports.OID_SPC_STATEMENT_TYPE_OBJID = new ObjectIdentifier_js_1.default([1, 3, 6, 1, 4, 1, 311, 2, 1, 11]);
// 1.3.6.1.4.1.311.2.1.12
// prettier-ignore
exports.OID_SPC_SP_OPUS_INFO_OBJID = new ObjectIdentifier_js_1.default([1, 3, 6, 1, 4, 1, 311, 2, 1, 12]);
// 1.3.6.1.4.1.311.2.1.21
// prettier-ignore
exports.OID_SPC_INDIVIDUAL_SP_KEY_PURPOSE_OBJID = new ObjectIdentifier_js_1.default([1, 3, 6, 1, 4, 1, 311, 2, 1, 21]);
// 1.3.6.1.4.1.311.3.3.1
// prettier-ignore
exports.OID_RFC3161_COUNTER_SIGNATURE = new ObjectIdentifier_js_1.default([1, 3, 6, 1, 4, 1, 311, 3, 3, 1]);
+6
View File
@@ -0,0 +1,6 @@
import DERObject from './DERObject.js';
export default class ObjectIdentifier implements DERObject {
value: number[];
constructor(value: number[] | string);
toDER(): number[];
}
+43
View File
@@ -0,0 +1,43 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var derUtil_js_1 = require("./derUtil.js");
var ObjectIdentifier = /** @class */ (function () {
function ObjectIdentifier(value) {
if (typeof value === 'string') {
this.value = value.split(/\./g).map(function (s) { return Number(s); });
}
else {
this.value = value;
}
}
ObjectIdentifier.prototype.toDER = function () {
var id = this.value;
var r = [];
if (id.length < 2) {
throw new Error("Unexpected 'value' field");
}
// first byte will be (x * 40 + y) for 'x.y.****'
r.push(id[0] * 40 + id[1]);
for (var i = 2; i < id.length; ++i) {
// store as variable-length value
var val = id[i];
var isFirst = true;
var insertPos = r.length;
while (true) {
var v = val & 0x7f;
if (!isFirst) {
v += 0x80;
}
r.splice(insertPos, 0, v);
if (val < 0x80) {
break;
}
isFirst = false;
val = Math.floor(val / 0x80);
}
}
return [0x06].concat(derUtil_js_1.makeDERLength(r.length)).concat(r);
};
return ObjectIdentifier;
}());
exports.default = ObjectIdentifier;
+13
View File
@@ -0,0 +1,13 @@
import DigestAlgorithmIdentifier from './AlgorithmIdentifier.js';
import ContentInfo from './ContentInfo.js';
import DERObject from './DERObject.js';
export default class SignedData implements DERObject {
version: number;
digestAlgorithms: DigestAlgorithmIdentifier[];
contentInfo: ContentInfo;
signerInfos: DERObject[];
certificates?: DERObject[] | undefined;
crls?: DERObject[] | undefined;
constructor(version: number, digestAlgorithms: DigestAlgorithmIdentifier[], contentInfo: ContentInfo, signerInfos: DERObject[], certificates?: DERObject[] | undefined, crls?: DERObject[] | undefined);
toDER(): number[];
}
+31
View File
@@ -0,0 +1,31 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var derUtil_js_1 = require("./derUtil.js");
var SignedData = /** @class */ (function () {
function SignedData(version, digestAlgorithms, contentInfo, signerInfos, certificates, crls) {
this.version = version;
this.digestAlgorithms = digestAlgorithms;
this.contentInfo = contentInfo;
this.signerInfos = signerInfos;
this.certificates = certificates;
this.crls = crls;
}
SignedData.prototype.toDER = function () {
var r = [0x02, 0x01, this.version & 0xff]
.concat(derUtil_js_1.arrayToDERSet(this.digestAlgorithms))
.concat(this.contentInfo.toDER());
if (this.certificates && this.certificates.length > 0) {
var allCertsDER = derUtil_js_1.arrayToDERSet(this.certificates);
// IMPLICIT SET
allCertsDER[0] = 0xa0;
r = r.concat(allCertsDER);
}
if (this.crls) {
r = r.concat(derUtil_js_1.makeDERTaggedData(1, derUtil_js_1.arrayToDERSet(this.crls)));
}
r = r.concat(derUtil_js_1.arrayToDERSet(this.signerInfos));
return derUtil_js_1.makeDERSequence(r);
};
return SignedData;
}());
exports.default = SignedData;
+15
View File
@@ -0,0 +1,15 @@
import DERObject from './DERObject.js';
import IssuerAndSerialNumber from './IssuerAndSerialNumber.js';
import AlgorithmIdentifier from './AlgorithmIdentifier.js';
import Attribute from './Attribute.js';
export default class SignerInfo implements DERObject {
version: number;
issuerAndSerialNumber: IssuerAndSerialNumber;
digestAlgorithm: AlgorithmIdentifier;
digestEncryptionAlgorithm: AlgorithmIdentifier;
encryptedDigest: Uint8Array;
authenticatedAttributes?: Attribute[] | undefined;
unauthenticatedAttributes?: Attribute[] | undefined;
constructor(version: number, issuerAndSerialNumber: IssuerAndSerialNumber, digestAlgorithm: AlgorithmIdentifier, digestEncryptionAlgorithm: AlgorithmIdentifier, encryptedDigest: Uint8Array, authenticatedAttributes?: Attribute[] | undefined, unauthenticatedAttributes?: Attribute[] | undefined);
toDER(): number[];
}
+39
View File
@@ -0,0 +1,39 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var derUtil_js_1 = require("./derUtil.js");
var SignerInfo = /** @class */ (function () {
function SignerInfo(version, issuerAndSerialNumber, digestAlgorithm, digestEncryptionAlgorithm, encryptedDigest, authenticatedAttributes, unauthenticatedAttributes) {
this.version = version;
this.issuerAndSerialNumber = issuerAndSerialNumber;
this.digestAlgorithm = digestAlgorithm;
this.digestEncryptionAlgorithm = digestEncryptionAlgorithm;
this.encryptedDigest = encryptedDigest;
this.authenticatedAttributes = authenticatedAttributes;
this.unauthenticatedAttributes = unauthenticatedAttributes;
}
SignerInfo.prototype.toDER = function () {
var r = [0x02, 0x01, this.version & 0xff]
.concat(this.issuerAndSerialNumber.toDER())
.concat(this.digestAlgorithm.toDER());
if (this.authenticatedAttributes &&
this.authenticatedAttributes.length > 0) {
var a = derUtil_js_1.arrayToDERSet(this.authenticatedAttributes);
// [0] IMPLICIT
a[0] = 0xa0;
r = r.concat(a);
}
r = r
.concat(this.digestEncryptionAlgorithm.toDER())
.concat(derUtil_js_1.makeDEROctetString(this.encryptedDigest));
if (this.unauthenticatedAttributes &&
this.unauthenticatedAttributes.length > 0) {
var u = derUtil_js_1.arrayToDERSet(this.unauthenticatedAttributes);
// [1] IMPLICIT
u[0] = 0xa1;
r = r.concat(u);
}
return derUtil_js_1.makeDERSequence(r);
};
return SignerInfo;
}());
exports.default = SignerInfo;
+21
View File
@@ -0,0 +1,21 @@
import ContentInfo from './ContentInfo.js';
import DigestInfo from './DigestInfo.js';
import ObjectIdentifier from './ObjectIdentifier.js';
import DERObject from './DERObject.js';
export declare const SPC_INDIRECT_DATA_OBJID: ObjectIdentifier;
export declare class SpcAttributeTypeAndOptionalValue<TValue extends DERObject = DERObject> {
type: ObjectIdentifier;
value: TValue;
constructor(type: ObjectIdentifier, value: TValue);
toDER(): number[];
}
export default class SpcIndirectDataContent implements DERObject {
data: SpcAttributeTypeAndOptionalValue;
messageDigest: DigestInfo;
constructor(data: SpcAttributeTypeAndOptionalValue, messageDigest: DigestInfo);
toDER(): number[];
toDERWithoutHeader(): number[];
}
export declare class SpcIndirectDataContentInfo extends ContentInfo<SpcIndirectDataContent> {
constructor(content: SpcIndirectDataContent);
}
+57
View File
@@ -0,0 +1,57 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.SpcIndirectDataContentInfo = exports.SpcAttributeTypeAndOptionalValue = exports.SPC_INDIRECT_DATA_OBJID = void 0;
var ContentInfo_js_1 = require("./ContentInfo.js");
var ObjectIdentifier_js_1 = require("./ObjectIdentifier.js");
var derUtil_js_1 = require("./derUtil.js");
// prettier-ignore
exports.SPC_INDIRECT_DATA_OBJID = new ObjectIdentifier_js_1.default([1, 3, 6, 1, 4, 1, 311, 2, 1, 4]);
var SpcAttributeTypeAndOptionalValue = /** @class */ (function () {
function SpcAttributeTypeAndOptionalValue(type, value) {
this.type = type;
this.value = value;
}
SpcAttributeTypeAndOptionalValue.prototype.toDER = function () {
return derUtil_js_1.makeDERSequence(this.type.toDER().concat(this.value.toDER()));
};
return SpcAttributeTypeAndOptionalValue;
}());
exports.SpcAttributeTypeAndOptionalValue = SpcAttributeTypeAndOptionalValue;
var SpcIndirectDataContent = /** @class */ (function () {
function SpcIndirectDataContent(data, messageDigest) {
this.data = data;
this.messageDigest = messageDigest;
}
SpcIndirectDataContent.prototype.toDER = function () {
return derUtil_js_1.makeDERSequence(this.toDERWithoutHeader());
};
// this is used for calculating 'messageDigest'
SpcIndirectDataContent.prototype.toDERWithoutHeader = function () {
return this.data.toDER().concat(this.messageDigest.toDER());
};
return SpcIndirectDataContent;
}());
exports.default = SpcIndirectDataContent;
var SpcIndirectDataContentInfo = /** @class */ (function (_super) {
__extends(SpcIndirectDataContentInfo, _super);
function SpcIndirectDataContentInfo(content) {
return _super.call(this, exports.SPC_INDIRECT_DATA_OBJID, content) || this;
}
return SpcIndirectDataContentInfo;
}(ContentInfo_js_1.default));
exports.SpcIndirectDataContentInfo = SpcIndirectDataContentInfo;
+16
View File
@@ -0,0 +1,16 @@
import DERObject from './DERObject.js';
/**
* Abstract data SpcLink. Must use either `SpcLinkUrl` or `SpcLinkFile` instead.
*/
export default abstract class SpcLink implements DERObject {
private readonly tag;
value: DERObject;
constructor(tag: number, value: DERObject);
toDER(): number[];
}
export declare class SpcLinkUrl extends SpcLink {
constructor(url: string);
}
export declare class SpcLinkFile extends SpcLink {
constructor(file: string);
}
+65
View File
@@ -0,0 +1,65 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.SpcLinkFile = exports.SpcLinkUrl = void 0;
var DERObject_js_1 = require("./DERObject.js");
var derUtil_js_1 = require("./derUtil.js");
/**
* Abstract data SpcLink. Must use either `SpcLinkUrl` or `SpcLinkFile` instead.
*/
var SpcLink = /** @class */ (function () {
function SpcLink(tag, value) {
this.tag = tag;
this.value = value;
}
SpcLink.prototype.toDER = function () {
var v = this.value.toDER();
if (this.tag === 2) {
// EXPLICIT
return derUtil_js_1.makeDERTaggedData(this.tag, v);
}
else {
// IMPLICIT
v[0] = 0x80 + this.tag;
return v;
}
};
return SpcLink;
}());
exports.default = SpcLink;
var SpcLinkUrl = /** @class */ (function (_super) {
__extends(SpcLinkUrl, _super);
function SpcLinkUrl(url) {
return _super.call(this, 0, new DERObject_js_1.RawDERObject(derUtil_js_1.makeDERIA5String(url))) || this;
}
return SpcLinkUrl;
}(SpcLink));
exports.SpcLinkUrl = SpcLinkUrl;
// moniker is not supported now (currently unused)
var SpcLinkFile = /** @class */ (function (_super) {
__extends(SpcLinkFile, _super);
function SpcLinkFile(file) {
var _this = this;
var v = derUtil_js_1.makeDERBMPString(file);
// [0] IMPLICIT BMPSTRING
v[0] = 0x80;
_this = _super.call(this, 2, new DERObject_js_1.RawDERObject(v)) || this;
return _this;
}
return SpcLinkFile;
}(SpcLink));
exports.SpcLinkFile = SpcLinkFile;
+19
View File
@@ -0,0 +1,19 @@
import DERObject from './DERObject.js';
import ObjectIdentifier from './ObjectIdentifier.js';
import { SpcAttributeTypeAndOptionalValue } from './SpcIndirectDataContent.js';
import SpcLink from './SpcLink.js';
export declare const SPC_PE_IMAGE_DATA_OBJID: ObjectIdentifier;
export declare const enum SpcPeImageFlags {
IncludeResources = 0,
IncludeDebugInfo = 1,
IncludeImportAddressTable = 2
}
export default class SpcPeImageData implements DERObject {
flags: SpcPeImageFlags;
file: SpcLink;
constructor(flags: SpcPeImageFlags, file: SpcLink);
toDER(): number[];
}
export declare class SpcPeImageAttributeTypeAndOptionalValue extends SpcAttributeTypeAndOptionalValue<SpcPeImageData> {
constructor(value: SpcPeImageData);
}
+44
View File
@@ -0,0 +1,44 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.SpcPeImageAttributeTypeAndOptionalValue = exports.SPC_PE_IMAGE_DATA_OBJID = void 0;
var ObjectIdentifier_js_1 = require("./ObjectIdentifier.js");
var SpcIndirectDataContent_js_1 = require("./SpcIndirectDataContent.js");
var derUtil_js_1 = require("./derUtil.js");
// prettier-ignore
exports.SPC_PE_IMAGE_DATA_OBJID = new ObjectIdentifier_js_1.default([1, 3, 6, 1, 4, 1, 311, 2, 1, 15]);
var SpcPeImageData = /** @class */ (function () {
function SpcPeImageData(flags, file) {
this.flags = flags;
this.file = file;
}
SpcPeImageData.prototype.toDER = function () {
return derUtil_js_1.makeDERSequence([0x03, 0x01, this.flags & 0xff].concat(
// undocumented -- SpcLink must be tagged
derUtil_js_1.makeDERTaggedData(0, this.file.toDER())));
};
return SpcPeImageData;
}());
exports.default = SpcPeImageData;
var SpcPeImageAttributeTypeAndOptionalValue = /** @class */ (function (_super) {
__extends(SpcPeImageAttributeTypeAndOptionalValue, _super);
function SpcPeImageAttributeTypeAndOptionalValue(value) {
return _super.call(this, exports.SPC_PE_IMAGE_DATA_OBJID, value) || this;
}
return SpcPeImageAttributeTypeAndOptionalValue;
}(SpcIndirectDataContent_js_1.SpcAttributeTypeAndOptionalValue));
exports.SpcPeImageAttributeTypeAndOptionalValue = SpcPeImageAttributeTypeAndOptionalValue;
+8
View File
@@ -0,0 +1,8 @@
import DERObject from './DERObject.js';
export declare function makeDERLength(length: number): number[];
export declare function makeDERIA5String(text: string): number[];
export declare function makeDERBMPString(text: string): number[];
export declare function makeDEROctetString(bin: number[] | Uint8Array): number[];
export declare function makeDERTaggedData(tag: number, body: number[]): number[];
export declare function makeDERSequence(body: number[]): number[];
export declare function arrayToDERSet(items: Array<DERObject | number[]>): number[];
+66
View File
@@ -0,0 +1,66 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.arrayToDERSet = exports.makeDERSequence = exports.makeDERTaggedData = exports.makeDEROctetString = exports.makeDERBMPString = exports.makeDERIA5String = exports.makeDERLength = void 0;
function makeDERLength(length) {
if (length < 0x80) {
return [length];
}
var r = [];
while (true) {
r.push(length & 0xff);
if (length < 0x100) {
break;
}
length >>= 8;
}
r.push(0x80 + r.length);
return r.reverse();
}
exports.makeDERLength = makeDERLength;
function makeDERIA5String(text) {
// convert to char-code array and filter to [0-127]
var r = [].map
.call(text, function (c) { return c.charCodeAt(0); })
.filter(function (n) { return n < 128; });
return [0x16].concat(makeDERLength(r.length)).concat(r);
}
exports.makeDERIA5String = makeDERIA5String;
function makeDERBMPString(text) {
// convert to char-code array
// NOTE: In ECMAScript `charCodeAt` returns surrogate pair for >=0x10000 codes,
// and surrogate pair is valid for BMPString data
var r = [].map.call(text, function (c) { return c.charCodeAt(0); });
var ua = new Uint8Array(r.length * 2);
var dv = new DataView(ua.buffer);
// store codes as big-endian
r.forEach(function (v, i) {
dv.setUint16(i * 2, v, false);
});
return [0x1e].concat(makeDERLength(ua.length)).concat(
// convert Uint8Array to number[] (not using spread operator)
[].slice.call(ua));
}
exports.makeDERBMPString = makeDERBMPString;
function makeDEROctetString(bin) {
if (!(bin instanceof Array)) {
// convert Uint8Array to number[] (not using spread operator)
bin = [].slice.call(bin);
}
return [0x04].concat(makeDERLength(bin.length)).concat(bin);
}
exports.makeDEROctetString = makeDEROctetString;
function makeDERTaggedData(tag, body) {
return [0xa0 + tag].concat(makeDERLength(body.length)).concat(body);
}
exports.makeDERTaggedData = makeDERTaggedData;
function makeDERSequence(body) {
return [0x30].concat(makeDERLength(body.length)).concat(body);
}
exports.makeDERSequence = makeDERSequence;
function arrayToDERSet(items) {
var r = items.reduce(function (prev, item) {
return prev.concat(item instanceof Array ? item : item.toDER());
}, []);
return [0x31].concat(makeDERLength(r.length)).concat(r);
}
exports.arrayToDERSet = arrayToDERSet;