Skip to content

Commit

Permalink
Merge 7c68455 into 7706025
Browse files Browse the repository at this point in the history
  • Loading branch information
microshine committed Jun 24, 2022
2 parents 7706025 + 7c68455 commit bff9d2b
Show file tree
Hide file tree
Showing 32 changed files with 1,362 additions and 1,371 deletions.
8 changes: 4 additions & 4 deletions package.json
Expand Up @@ -6,13 +6,13 @@
],
"devDependencies": {
"@types/mocha": "^9.1.1",
"@types/node": "^17.0.33",
"lerna": "^4.0.0",
"@types/node": "^18.0.0",
"lerna": "^5.1.5",
"mocha": "^10.0.0",
"nyc": "^15.1.0",
"ts-node": "^10.4.0",
"ts-node": "^10.8.1",
"tsconfig-paths": "^4.0.0",
"typescript": "^4.6.4"
"typescript": "^4.7.4"
},
"scripts": {
"test": "mocha",
Expand Down
2 changes: 1 addition & 1 deletion packages/adobe-acrobat/package.json
Expand Up @@ -36,7 +36,7 @@
"dependencies": {
"@peculiar/asn1-schema": "^2.1.9",
"@peculiar/asn1-x509": "^2.1.9",
"asn1js": "^3.0.4",
"asn1js": "^3.0.5",
"tslib": "^2.4.0"
}
}
2 changes: 1 addition & 1 deletion packages/android/package.json
Expand Up @@ -35,7 +35,7 @@
},
"dependencies": {
"@peculiar/asn1-schema": "^2.1.9",
"asn1js": "^3.0.4",
"asn1js": "^3.0.5",
"tslib": "^2.4.0"
}
}
2 changes: 1 addition & 1 deletion packages/android/test/test.ts
Expand Up @@ -18,7 +18,7 @@ context("Android", () => {
assert.strictEqual(kd.keymasterSecurityLevel, SecurityLevel.software);
assert.strictEqual(kd.attestationChallenge.byteLength, 32);
assert.strictEqual(kd.uniqueId.byteLength, 0);
assert.strictEqual(kd.softwareEnforced.creationDateTime, 1506793476000);
assert.strictEqual(kd.softwareEnforced.creationDateTime, "1506793476000");
assert.strictEqual(kd.softwareEnforced.attestationApplicationId!.byteLength, 87);
assert.strictEqual(kd.teeEnforced.purpose!.length, 1);
assert.strictEqual(kd.teeEnforced.purpose![0], 2);
Expand Down
2 changes: 1 addition & 1 deletion packages/cert-transparency/package.json
Expand Up @@ -35,7 +35,7 @@
},
"dependencies": {
"@peculiar/asn1-schema": "^2.1.9",
"asn1js": "^3.0.4",
"asn1js": "^3.0.5",
"pvtsutils": "^1.3.2",
"tslib": "^2.4.0"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cms/package.json
Expand Up @@ -37,7 +37,7 @@
"@peculiar/asn1-schema": "^2.1.9",
"@peculiar/asn1-x509": "^2.1.9",
"@peculiar/asn1-x509-attr": "^2.1.9",
"asn1js": "^3.0.4",
"asn1js": "^3.0.5",
"tslib": "^2.4.0"
}
}
2 changes: 1 addition & 1 deletion packages/csr/package.json
Expand Up @@ -36,7 +36,7 @@
"dependencies": {
"@peculiar/asn1-schema": "^2.1.9",
"@peculiar/asn1-x509": "^2.1.9",
"asn1js": "^3.0.4",
"asn1js": "^3.0.5",
"tslib": "^2.4.0"
}
}
2 changes: 1 addition & 1 deletion packages/ecc/package.json
Expand Up @@ -36,7 +36,7 @@
"dependencies": {
"@peculiar/asn1-schema": "^2.1.9",
"@peculiar/asn1-x509": "^2.1.9",
"asn1js": "^3.0.4",
"asn1js": "^3.0.5",
"tslib": "^2.4.0"
}
}
2 changes: 1 addition & 1 deletion packages/ess/package.json
Expand Up @@ -41,7 +41,7 @@
"@peculiar/asn1-rsa": "^2.1.9",
"@peculiar/asn1-schema": "^2.1.9",
"@peculiar/asn1-x509": "^2.1.9",
"asn1js": "^3.0.4",
"asn1js": "^3.0.5",
"tslib": "^2.4.0"
},
"bugs": {
Expand Down
2 changes: 1 addition & 1 deletion packages/lei/package.json
Expand Up @@ -35,7 +35,7 @@
},
"dependencies": {
"@peculiar/asn1-schema": "^2.1.9",
"asn1js": "^3.0.4",
"asn1js": "^3.0.5",
"tslib": "^2.4.0"
}
}
2 changes: 1 addition & 1 deletion packages/ntqwac/package.json
Expand Up @@ -34,7 +34,7 @@
"dependencies": {
"@peculiar/asn1-schema": "^2.1.9",
"@peculiar/asn1-x509": "^2.1.9",
"asn1js": "^3.0.4",
"asn1js": "^3.0.5",
"tslib": "^2.4.0"
},
"bugs": {
Expand Down
2 changes: 1 addition & 1 deletion packages/ocsp/package.json
Expand Up @@ -38,7 +38,7 @@
"dependencies": {
"@peculiar/asn1-schema": "^2.1.9",
"@peculiar/asn1-x509": "^2.1.9",
"asn1js": "^3.0.4",
"asn1js": "^3.0.5",
"tslib": "^2.4.0"
}
}
2 changes: 1 addition & 1 deletion packages/pfx/package.json
Expand Up @@ -38,7 +38,7 @@
"@peculiar/asn1-pkcs8": "^2.1.9",
"@peculiar/asn1-rsa": "^2.1.9",
"@peculiar/asn1-schema": "^2.1.9",
"asn1js": "^3.0.4",
"asn1js": "^3.0.5",
"tslib": "^2.4.0"
}
}
2 changes: 1 addition & 1 deletion packages/pkcs8/package.json
Expand Up @@ -36,7 +36,7 @@
"dependencies": {
"@peculiar/asn1-schema": "^2.1.9",
"@peculiar/asn1-x509": "^2.1.9",
"asn1js": "^3.0.4",
"asn1js": "^3.0.5",
"tslib": "^2.4.0"
}
}
2 changes: 1 addition & 1 deletion packages/pkcs9/package.json
Expand Up @@ -40,7 +40,7 @@
"@peculiar/asn1-schema": "^2.1.9",
"@peculiar/asn1-x509": "^2.1.9",
"@peculiar/asn1-x509-attr": "^2.1.9",
"asn1js": "^3.0.4",
"asn1js": "^3.0.5",
"tslib": "^2.4.0"
},
"bugs": {
Expand Down
2 changes: 1 addition & 1 deletion packages/rfc8226/package.json
Expand Up @@ -35,7 +35,7 @@
},
"dependencies": {
"@peculiar/asn1-schema": "^2.1.9",
"asn1js": "^3.0.4",
"asn1js": "^3.0.5",
"tslib": "^2.4.0"
},
"bugs": {
Expand Down
2 changes: 1 addition & 1 deletion packages/rsa/package.json
Expand Up @@ -36,7 +36,7 @@
"dependencies": {
"@peculiar/asn1-schema": "^2.1.9",
"@peculiar/asn1-x509": "^2.1.9",
"asn1js": "^3.0.4",
"asn1js": "^3.0.5",
"tslib": "^2.4.0"
}
}
2 changes: 1 addition & 1 deletion packages/schema/package.json
Expand Up @@ -38,7 +38,7 @@
"rebuild": "npm run clear && npm run build"
},
"dependencies": {
"asn1js": "^3.0.4",
"asn1js": "^3.0.5",
"pvtsutils": "^1.3.2",
"tslib": "^2.4.0"
},
Expand Down
14 changes: 11 additions & 3 deletions packages/schema/src/converters.ts
Expand Up @@ -27,9 +27,9 @@ export const AsnAnyConverter: IAsnConverter<AnyConverterType> = {
/**
* ASN.1 INTEGER to Number/String converter
*/
export const AsnIntegerConverter: IAsnConverter<IntegerConverterType> = {
fromASN: (value: any) => value.valueBlock.valueHex.byteLength >= 4
? parseInt(value.valueBlock.toString())
export const AsnIntegerConverter: IAsnConverter<IntegerConverterType, asn1.Integer> = {
fromASN: (value: asn1.Integer) => value.valueBlock.valueHexView.byteLength >= 4
? value.valueBlock.toString() // use string format
: value.valueBlock.valueDec, // use number format
toASN: (value: IntegerConverterType) => new asn1.Integer({ value: value as any }),
};
Expand All @@ -50,6 +50,14 @@ export const AsnIntegerArrayBufferConverter: IAsnConverter<ArrayBuffer> = {
toASN: (value: ArrayBuffer) => new asn1.Integer({ valueHex: value } as any),
};

/**
* ASN.1 INTEGER to BigInt converter
*/
export const AsnIntegerBigIntConverter: IAsnConverter<bigint, asn1.Integer> = {
fromASN: (value: asn1.Integer) => value.toBigInt(),
toASN: (value: bigint) => asn1.Integer.fromBigInt(value),
};

/**
* ASN.1 BIT STRING converter
*/
Expand Down
24 changes: 20 additions & 4 deletions packages/schema/src/decorators.ts
Expand Up @@ -4,16 +4,18 @@ import { IAsnSchema, IAsnSchemaItem } from "./schema";
import { schemaStorage } from "./storage";
import { IAsnConverter, IEmptyConstructor } from "./types";

interface IAsn1TypeOptions {
export type AsnItemType<T = any> = AsnPropTypes | IEmptyConstructor<T>;

export interface IAsn1TypeOptions {
type: AsnTypeTypes;
itemType?: AsnPropTypes | IEmptyConstructor<any>;
itemType?: AsnItemType;
}
export type AsnRepeatTypeString = "sequence" | "set";

export type AsnRepeatType = AsnRepeatTypeString;

interface IAsn1PropOptions {
type: AsnPropTypes | IEmptyConstructor<any>;
export interface IAsn1PropOptions {
type: AsnItemType;
optional?: boolean;
defaultValue?: any;
context?: number;
Expand All @@ -33,6 +35,20 @@ export const AsnType = (options: IAsn1TypeOptions) => (target: object) => {
Object.assign(schema, options);
};

export const AsnChoiceType = () => AsnType({ type: AsnTypeTypes.Choice });

export interface IAsn1SetOptions {
itemType: AsnItemType;
}

export const AsnSetType = (options: IAsn1SetOptions) => AsnType({ type: AsnTypeTypes.Set, ...options });

export interface IAsn1SequenceOptions {
itemType?: AsnItemType;
}

export const AsnSequenceType = (options: IAsn1SequenceOptions) => AsnType({ type: AsnTypeTypes.Sequence, ...options });

export const AsnProp = (options: IAsn1PropOptions) => (target: object, propertyKey: string) => {
let schema: IAsnSchema;
if (!schemaStorage.has(target.constructor)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/schema/src/index.ts
@@ -1,6 +1,6 @@
export * from "./converters";
export * from "./types/index";
export { AsnProp, AsnType } from "./decorators";
export { AsnProp, AsnType, AsnChoiceType, AsnSequenceType, AsnSetType } from "./decorators";
export { AsnTypeTypes, AsnPropTypes } from "./enums";
export { AsnParser } from "./parser";
export { AsnSerializer } from "./serializer";
Expand Down

0 comments on commit bff9d2b

Please sign in to comment.