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[];
}
+14
View File
@@ -0,0 +1,14 @@
import { makeDERSequence } from './derUtil.js';
var AlgorithmIdentifier = /** @class */ (function () {
function AlgorithmIdentifier(algorithm) {
this.algorithm = algorithm;
}
AlgorithmIdentifier.prototype.toDER = function () {
var r = this.algorithm.toDER();
return makeDERSequence(r.concat(
// parameters is not used now
[0x05, 0x00]));
};
return AlgorithmIdentifier;
}());
export 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[];
}
+12
View File
@@ -0,0 +1,12 @@
import { makeDERSequence, arrayToDERSet } from './derUtil.js';
var Attribute = /** @class */ (function () {
function Attribute(attrType, attrValues) {
this.attrType = attrType;
this.attrValues = attrValues;
}
Attribute.prototype.toDER = function () {
return makeDERSequence(this.attrType.toDER().concat(arrayToDERSet(this.attrValues)));
};
return Attribute;
}());
export 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> {
}
+24
View File
@@ -0,0 +1,24 @@
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 __());
};
})();
import ContentInfo from './ContentInfo.js';
var CertificateDataRoot = /** @class */ (function (_super) {
__extends(CertificateDataRoot, _super);
function CertificateDataRoot() {
return _super !== null && _super.apply(this, arguments) || this;
}
return CertificateDataRoot;
}(ContentInfo));
export 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[];
}
+15
View File
@@ -0,0 +1,15 @@
import { makeDERSequence, makeDERTaggedData } from './derUtil.js';
// abstract
var ContentInfo = /** @class */ (function () {
function ContentInfo(contentType, content) {
this.contentType = contentType;
this.content = content;
}
ContentInfo.prototype.toDER = function () {
return makeDERSequence(this.contentType
.toDER()
.concat(makeDERTaggedData(0, this.content.toDER())));
};
return ContentInfo;
}());
export 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[];
}
+10
View File
@@ -0,0 +1,10 @@
var RawDERObject = /** @class */ (function () {
function RawDERObject(data) {
this.data = data;
}
RawDERObject.prototype.toDER = function () {
return [].slice.call(this.data);
};
return RawDERObject;
}());
export { 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[];
}
+23
View File
@@ -0,0 +1,23 @@
import { makeDERSequence, makeDEROctetString } from './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(makeDEROctetString(digestArray));
return makeDERSequence(derData);
};
return DigestInfo;
}());
export 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[];
}
+12
View File
@@ -0,0 +1,12 @@
import { makeDERSequence } from './derUtil.js';
var IssuerAndSerialNumber = /** @class */ (function () {
function IssuerAndSerialNumber(issuer, serialNumber) {
this.issuer = issuer;
this.serialNumber = serialNumber;
}
IssuerAndSerialNumber.prototype.toDER = function () {
return makeDERSequence(this.issuer.toDER().concat(this.serialNumber.toDER()));
};
return IssuerAndSerialNumber;
}());
export 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;
+67
View File
@@ -0,0 +1,67 @@
import ObjectIdentifier from './ObjectIdentifier.js';
// 1.3.14.3.2.26
// prettier-ignore
export var OID_SHA1_NO_SIGN = new ObjectIdentifier([1, 3, 14, 3, 2, 26]);
// 2.16.840.1.101.3.4.2.1
// prettier-ignore
export var OID_SHA256_NO_SIGN = new ObjectIdentifier([2, 16, 840, 1, 101, 3, 4, 2, 1]);
// 2.16.840.1.101.3.4.2.2
// prettier-ignore
export var OID_SHA384_NO_SIGN = new ObjectIdentifier([2, 16, 840, 1, 101, 3, 4, 2, 2]);
// 2.16.840.1.101.3.4.2.3
// prettier-ignore
export var OID_SHA512_NO_SIGN = new ObjectIdentifier([2, 16, 840, 1, 101, 3, 4, 2, 3]);
// 2.16.840.1.101.3.4.2.4
// prettier-ignore
export var OID_SHA224_NO_SIGN = new ObjectIdentifier([2, 16, 840, 1, 101, 3, 4, 2, 4]);
// 2.16.840.1.101.3.4.2.5
// prettier-ignore
export var OID_SHA512_224_NO_SIGN = new ObjectIdentifier([2, 16, 840, 1, 101, 3, 4, 2, 5]);
// 2.16.840.1.101.3.4.2.6
// prettier-ignore
export var OID_SHA512_256_NO_SIGN = new ObjectIdentifier([2, 16, 840, 1, 101, 3, 4, 2, 6]);
// 2.16.840.1.101.3.4.2.7
// prettier-ignore
export var OID_SHA3_224_NO_SIGN = new ObjectIdentifier([2, 16, 840, 1, 101, 3, 4, 2, 7]);
// 2.16.840.1.101.3.4.2.8
// prettier-ignore
export var OID_SHA3_256_NO_SIGN = new ObjectIdentifier([2, 16, 840, 1, 101, 3, 4, 2, 8]);
// 2.16.840.1.101.3.4.2.9
// prettier-ignore
export var OID_SHA3_384_NO_SIGN = new ObjectIdentifier([2, 16, 840, 1, 101, 3, 4, 2, 9]);
// 2.16.840.1.101.3.4.2.10
// prettier-ignore
export var OID_SHA3_512_NO_SIGN = new ObjectIdentifier([2, 16, 840, 1, 101, 3, 4, 2, 10]);
// 2.16.840.1.101.3.4.2.11
// prettier-ignore
export var OID_SHAKE128_NO_SIGN = new ObjectIdentifier([2, 16, 840, 1, 101, 3, 4, 2, 11]);
// 2.16.840.1.101.3.4.2.12
// prettier-ignore
export var OID_SHAKE256_NO_SIGN = new ObjectIdentifier([2, 16, 840, 1, 101, 3, 4, 2, 12]);
// 1.2.840.113549.1.1.1
// prettier-ignore
export var OID_RSA = new ObjectIdentifier([1, 2, 840, 113549, 1, 1, 1]);
// 1.2.840.10040.4.1
// prettier-ignore
export var OID_DSA = new ObjectIdentifier([1, 2, 840, 10040, 4, 1]);
// 1.2.840.113549.1.7.2
// prettier-ignore
export var OID_SIGNED_DATA = new ObjectIdentifier([1, 2, 840, 113549, 1, 7, 2]);
// 1.2.840.113549.1.9.3
// prettier-ignore
export var OID_CONTENT_TYPE = new ObjectIdentifier([1, 2, 840, 113549, 1, 9, 3]);
// 1.2.840.113549.1.9.4
// prettier-ignore
export var OID_MESSAGE_DIGEST = new ObjectIdentifier([1, 2, 840, 113549, 1, 9, 4]);
// 1.3.6.1.4.1.311.2.1.11
// prettier-ignore
export var OID_SPC_STATEMENT_TYPE_OBJID = new ObjectIdentifier([1, 3, 6, 1, 4, 1, 311, 2, 1, 11]);
// 1.3.6.1.4.1.311.2.1.12
// prettier-ignore
export var OID_SPC_SP_OPUS_INFO_OBJID = new ObjectIdentifier([1, 3, 6, 1, 4, 1, 311, 2, 1, 12]);
// 1.3.6.1.4.1.311.2.1.21
// prettier-ignore
export var OID_SPC_INDIVIDUAL_SP_KEY_PURPOSE_OBJID = new ObjectIdentifier([1, 3, 6, 1, 4, 1, 311, 2, 1, 21]);
// 1.3.6.1.4.1.311.3.3.1
// prettier-ignore
export var OID_RFC3161_COUNTER_SIGNATURE = new ObjectIdentifier([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[];
}
+41
View File
@@ -0,0 +1,41 @@
import { makeDERLength } from './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(makeDERLength(r.length)).concat(r);
};
return ObjectIdentifier;
}());
export 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[];
}
+29
View File
@@ -0,0 +1,29 @@
import { arrayToDERSet, makeDERSequence, makeDERTaggedData, } from './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(arrayToDERSet(this.digestAlgorithms))
.concat(this.contentInfo.toDER());
if (this.certificates && this.certificates.length > 0) {
var allCertsDER = arrayToDERSet(this.certificates);
// IMPLICIT SET
allCertsDER[0] = 0xa0;
r = r.concat(allCertsDER);
}
if (this.crls) {
r = r.concat(makeDERTaggedData(1, arrayToDERSet(this.crls)));
}
r = r.concat(arrayToDERSet(this.signerInfos));
return makeDERSequence(r);
};
return SignedData;
}());
export 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[];
}
+37
View File
@@ -0,0 +1,37 @@
import { makeDERSequence, arrayToDERSet, makeDEROctetString, } from './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 = arrayToDERSet(this.authenticatedAttributes);
// [0] IMPLICIT
a[0] = 0xa0;
r = r.concat(a);
}
r = r
.concat(this.digestEncryptionAlgorithm.toDER())
.concat(makeDEROctetString(this.encryptedDigest));
if (this.unauthenticatedAttributes &&
this.unauthenticatedAttributes.length > 0) {
var u = arrayToDERSet(this.unauthenticatedAttributes);
// [1] IMPLICIT
u[0] = 0xa1;
r = r.concat(u);
}
return makeDERSequence(r);
};
return SignerInfo;
}());
export 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);
}
+54
View File
@@ -0,0 +1,54 @@
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 __());
};
})();
import ContentInfo from './ContentInfo.js';
import ObjectIdentifier from './ObjectIdentifier.js';
import { makeDERSequence } from './derUtil.js';
// prettier-ignore
export var SPC_INDIRECT_DATA_OBJID = new ObjectIdentifier([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 makeDERSequence(this.type.toDER().concat(this.value.toDER()));
};
return SpcAttributeTypeAndOptionalValue;
}());
export { SpcAttributeTypeAndOptionalValue };
var SpcIndirectDataContent = /** @class */ (function () {
function SpcIndirectDataContent(data, messageDigest) {
this.data = data;
this.messageDigest = messageDigest;
}
SpcIndirectDataContent.prototype.toDER = function () {
return makeDERSequence(this.toDERWithoutHeader());
};
// this is used for calculating 'messageDigest'
SpcIndirectDataContent.prototype.toDERWithoutHeader = function () {
return this.data.toDER().concat(this.messageDigest.toDER());
};
return SpcIndirectDataContent;
}());
export default SpcIndirectDataContent;
var SpcIndirectDataContentInfo = /** @class */ (function (_super) {
__extends(SpcIndirectDataContentInfo, _super);
function SpcIndirectDataContentInfo(content) {
return _super.call(this, SPC_INDIRECT_DATA_OBJID, content) || this;
}
return SpcIndirectDataContentInfo;
}(ContentInfo));
export { 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);
}
+62
View File
@@ -0,0 +1,62 @@
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 __());
};
})();
import { RawDERObject } from './DERObject.js';
import { makeDERTaggedData, makeDERIA5String, makeDERBMPString, } from './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 makeDERTaggedData(this.tag, v);
}
else {
// IMPLICIT
v[0] = 0x80 + this.tag;
return v;
}
};
return SpcLink;
}());
export default SpcLink;
var SpcLinkUrl = /** @class */ (function (_super) {
__extends(SpcLinkUrl, _super);
function SpcLinkUrl(url) {
return _super.call(this, 0, new RawDERObject(makeDERIA5String(url))) || this;
}
return SpcLinkUrl;
}(SpcLink));
export { SpcLinkUrl };
// moniker is not supported now (currently unused)
var SpcLinkFile = /** @class */ (function (_super) {
__extends(SpcLinkFile, _super);
function SpcLinkFile(file) {
var _this = this;
var v = makeDERBMPString(file);
// [0] IMPLICIT BMPSTRING
v[0] = 0x80;
_this = _super.call(this, 2, new RawDERObject(v)) || this;
return _this;
}
return SpcLinkFile;
}(SpcLink));
export { 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);
}
+41
View File
@@ -0,0 +1,41 @@
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 __());
};
})();
import ObjectIdentifier from './ObjectIdentifier.js';
import { SpcAttributeTypeAndOptionalValue } from './SpcIndirectDataContent.js';
import { makeDERSequence, makeDERTaggedData } from './derUtil.js';
// prettier-ignore
export var SPC_PE_IMAGE_DATA_OBJID = new ObjectIdentifier([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 makeDERSequence([0x03, 0x01, this.flags & 0xff].concat(
// undocumented -- SpcLink must be tagged
makeDERTaggedData(0, this.file.toDER())));
};
return SpcPeImageData;
}());
export default SpcPeImageData;
var SpcPeImageAttributeTypeAndOptionalValue = /** @class */ (function (_super) {
__extends(SpcPeImageAttributeTypeAndOptionalValue, _super);
function SpcPeImageAttributeTypeAndOptionalValue(value) {
return _super.call(this, SPC_PE_IMAGE_DATA_OBJID, value) || this;
}
return SpcPeImageAttributeTypeAndOptionalValue;
}(SpcAttributeTypeAndOptionalValue));
export { 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[];
+56
View File
@@ -0,0 +1,56 @@
export 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();
}
export 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);
}
export 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));
}
export 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);
}
export function makeDERTaggedData(tag, body) {
return [0xa0 + tag].concat(makeDERLength(body.length)).concat(body);
}
export function makeDERSequence(body) {
return [0x30].concat(makeDERLength(body.length)).concat(body);
}
export 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);
}