Skip to content

Commit

Permalink
feat: v0.1.8 | Add test support for CardSecurity
Browse files Browse the repository at this point in the history
  • Loading branch information
li0ard committed Sep 28, 2024
1 parent 74e8713 commit d778a2a
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion jsr.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@li0ard/tsemrtd",
"version": "0.1.7",
"version": "0.1.8",
"exports": "./src/index.ts",
"publish": {
"include": [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@li0ard/tsemrtd",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"version": "0.1.7",
"version": "0.1.8",
"type": "module",
"author": "li0ard",
"repository": {
Expand Down
24 changes: 24 additions & 0 deletions src/cardsecurity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { AsnConvert, OctetString } from "@peculiar/asn1-schema";
import { SecurityInfos } from "./asn1/eac";
import { CertificateSet, ContentInfo, SignedData } from "@peculiar/asn1-cms";

/**
* Class for working with EF.CardSecurity
* @experimental
*/
export class CardSecurity {
/**
* Get EAC/PACE security informations
* @param data Data of EF.CardSecurity file
*/
static load(data: Buffer) {
let contentInfo = AsnConvert.parse(data, ContentInfo)
let signedData = AsnConvert.parse(contentInfo.content, SignedData)
let securityInfos = AsnConvert.parse(signedData.encapContentInfo.eContent?.single as OctetString, SecurityInfos)
return {
certificates: signedData.certificates as CertificateSet,
securityInfos: securityInfos,
signatures: signedData.signerInfos
}
}
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export { DG14 } from "./dg14"
export { DG15 } from "./dg15"
export { SOD } from "./sod"
export { PKD } from "./pkd"
export { CardSecurity } from "./cardsecurity"
export * as Enums from "./consts/enums"
export * as Interfaces from "./consts/interfaces"
export * as Oids from "./consts/oids"
Expand Down
Binary file added tests/dgs/EF_CardSecurity.bin
Binary file not shown.
7 changes: 6 additions & 1 deletion tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test, expect } from "bun:test"
import { join } from "path"
import { COM, DG1, DG2, DG3, DG5, DG7, DG11, DG12, SOD, DG15, DG4, DG14, Schemas } from "../src"
import { COM, DG1, DG2, DG3, DG5, DG7, DG11, DG12, SOD, DG15, DG4, DG14, Schemas, CardSecurity } from "../src"

const getDGContent = async (name: string): Promise<Buffer> => {
return Buffer.from(await Bun.file(join(import.meta.dir, "dgs", name)).bytes())
Expand Down Expand Up @@ -106,4 +106,9 @@ test("SOD", async () => {
expect(data.ldsObject.version).toBe(0)
expect(data.ldsObject.algorithm.algorithm).toBe("1.3.14.3.2.26")
expect(data.ldsObject.hashes.length).toBe(4)
})

test.todo("CardSecurity", async () => {
let data = CardSecurity.load(await getDGContent("EF_CardSecurity.bin"))

})

0 comments on commit d778a2a

Please sign in to comment.