Skip to content

Commit

Permalink
Merge bb909ce into ee73155
Browse files Browse the repository at this point in the history
  • Loading branch information
microshine committed Jun 24, 2022
2 parents ee73155 + bb909ce commit 18ed60a
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/test.yml
Expand Up @@ -36,6 +36,12 @@ jobs:
- name: Run test with coverage
run: npm run coverage

# Fixes problem with incorrect SF paths. See https://github.com/coverallsapp/github-action/issues/125
- name: Update lcov.info
run: |
sed -E "s/SF:(.+file:(.+))/SF:\2/g" ./coverage/lcov.info > coverage/lcov.new.info
mv ./coverage/lcov.new.info ./coverage/lcov.info
- name: Coveralls
uses: coverallsapp/github-action@master
with:
Expand Down
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
4 changes: 2 additions & 2 deletions packages/schema/src/converters.ts
Expand Up @@ -28,8 +28,8 @@ 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
? value.valueBlock.toString() // Convert number to string
fromASN: (value: any) => value.valueBlock.valueHex.byteLength >= 4
? parseInt(value.valueBlock.toString())
: value.valueBlock.valueDec, // use number format
toASN: (value: IntegerConverterType) => new asn1.Integer({ value: value as any }),
};
Expand Down
48 changes: 46 additions & 2 deletions packages/schema/test/test.ts
@@ -1,7 +1,7 @@
// @ts-ignore
import * as asn1 from "asn1js";
import * as assert from "assert";
import { AsnProp, AsnPropTypes, AsnType, AsnTypeTypes, OctetString, AsnArray } from "../src";
import { AsnProp, AsnPropTypes, AsnType, AsnTypeTypes, OctetString, AsnArray, AsnConvert } from "../src";
import * as Converters from "../src/converters";
import { AsnParser } from "../src/parser";
import { AsnSerializer } from "../src/serializer";
Expand Down Expand Up @@ -219,7 +219,7 @@ context("Test", () => {
* SEQUENCE (1 elem)
* INTEGER (47 bit) 123456789012345
*/
test(Test, "300802067048860ddf79", "123456789012345");
test(Test, "300802067048860ddf79", 123456789012345);
});
});
context("BooleanConverter", () => {
Expand Down Expand Up @@ -805,4 +805,48 @@ context("Test", () => {
});
});

// https://github.com/PeculiarVentures/asn1-schema/issues/75
context("issue #75", () => {

it("parse 3 bytes INTEGER", () => {
@AsnType({ type: AsnTypeTypes.Choice })
class Test {
@AsnProp({ type: AsnPropTypes.Integer })
public value!: number;
}

const buf = Buffer.from("0203010203", "hex");
const test = AsnConvert.parse(buf, Test);

assert.strictEqual(test.value, 66051);
});

it("parse 4 bytes INTEGER", () => {
@AsnType({ type: AsnTypeTypes.Choice })
class Test {
@AsnProp({ type: AsnPropTypes.Integer })
public value!: number;
}

const buf = Buffer.from("020401020304", "hex");
const test = AsnConvert.parse(buf, Test);

assert.strictEqual(test.value, 16909060);
});

it("parse more than 4 bytes INTEGER", () => {
@AsnType({ type: AsnTypeTypes.Choice })
class Test {
@AsnProp({ type: AsnPropTypes.Integer })
public value!: number;
}

const buf = Buffer.from("020f0102030405060708090a0b0c0d0e0f01", "hex");
const test = AsnConvert.parse(buf, Test);

assert.strictEqual(test.value, 5.233100606242807e+33);
});

});

});

0 comments on commit 18ed60a

Please sign in to comment.